perf(lsp): session parse cache + file watchers for cross-file features - #14
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR1 made
codeLensparse the workspace once per request. But every other cross-file feature — hover, go-to-definition, find-references, rename, document-highlight, workspace-symbols, and import diagnostics — still re-parsed every closed.ridlfile (and its whole import graph, twice) on each request. This adds a session-level parse cache so those closed-file parses are reused across requests, invalidated precisely when the workspace actually changes.How it works
gen(atomic.Uint64) on the server is bumped — atomically with the document-store mutation, under a singleworkspaceMu.Lock— on every content-affecting event:didOpen/didChange/didCloseand.ridldidChangeWatchedFiles. Not ondidSave(no content change) orsetResult.map[path]*ParseResultkeyed by the current generation. Any gen change drops it wholesale (a closed file's parse depends on its entire import graph's overlay+disk state, so per-file dependency tracking isn't worth the complexity). Readers snapshot(docs, gen, overlays, cache-hit)underworkspaceMu.RLockand release before parsing — the lock is never held across a parse or aWalkDir.Initializedregisters**/*.ridlwatchers viaclient/registerCapability(this also revives the previously deaddidChangeWatchedFileshandler). The cache is enabled only if registration succeeds; otherwise it's bypassed entirely and behavior is exactly as before (every parse re-reads disk). This is the correctness boundary: without watcher events we can't see closed-file disk edits, so we don't cache.referenceCandidatePaths()'s fullWalkDiris cached by the same generation (same snapshot discipline).parsePathinstead of a direct re-parse.Correctness guards:
parsePathnever caches a cancelled or incomplete parse (ctx.Err()checked on entry and after parse — the upstream parser can returnerr==nilwith a partial result after cancellation) and stores only if the generation didn't move during the parse (TOCTOU). Cached*ParseResult(Root and Schema) is treated read-only. CodeLens (PR1) is untouched.This is PR2 of two; PR1 (#13) is merged.
Test plan
New tests: parse-cache gen semantics (hit/miss/roll-forward/stale-put/nil-skip); generation bumps on open/change/close/
.ridl-watched-files and not on save; watcher registration + cache-enable gating (advertised+success / not-advertised / register-fails); closed-file cache hit + reparse-after-gen-bump + no-cache-on-cancel + disabled-bypass; candidate-path caching + invalidation; and a concurrency race test that (verified by coverage) actually exercises the session cache under gen churn.Review notes
Design converged with Codex up front (the watcher-gating fallback, the atomic mutation boundary, and the no-cache-on-cancel rule all came out of that round), then the diff went through a Claude per-task + opus core-task review and a Codex adversarial diff review. Codex's adversarial pass caught that the concurrency test was vacuous for the session cache (cursor on a non-symbol → the cache was never reached;
parseCache.get/putat 0% coverage) — fixed by targeting a real cross-file reference, now 100%/80% covered.Non-blocking follow-ups:
candidatePathCache.getcould useRLock(matchesparseCache's plainMutexfor now); per-file dependency-graph invalidation was intentionally skipped in favor of whole-generation drop.