# references-nav M7 of the refactoring plan (`docs/features/refactor/README.md`), the first milestone taken from that plan's "LSP-parity and plumbing gaps" triage. ## Goal Three navigation capabilities that were all wiring over machinery the tree already had. **Cross-file find-all-references**: `textDocument/references` answered in-file only, while M2's rename had been collecting cross-file reference sets since it shipped — so lucisv could *change* references it could not *list*. **Document highlight for symbols**: the cursor on a signal now highlights its declaration and every use in the file, where before only a `begin`/`end` pair answered and everything else fell through to the editor's word matching. **Folding ranges**: `pairs.rs` already matches every `begin`/`end`-family pair for the rainbow, and `textDocument/foldingRange` is that same data on a standard capability. No new analysis was written for any of the three; the whole milestone is one shared collection function, one predicate, and three handlers. ## Assumptions - **The workspace index is the authority on what can be named from another file.** `nav::leaves_this_file` decides whether a references request walks the workspace by asking `WorkspaceIndex::units` / `::member_in(…, Surface::Hierarchical)` about the name under the cursor — not by re-deriving `is_unit`/`is_exported`, which are private to `vlog_semantic` and would be language knowledge in the protocol layer. **The surface matters** (amended 2026-09-12, §64.1): the question is which declarations a *use* in another file can reach, and a hierarchical path may name anything a module declares (IEEE 1800 §23.6) where a connection list may name only its ports and parameters (§23.3). Asking `::member` — the connection surface — was what made `assign w = u_x.sig;` in another file invisible to `references` while a rename was already editing it. The connection answer is the first, whole part of the hierarchical one, so nothing else moved; see `docs/features/references-hierarchical-surface/README.md`. Consequence: a declaration the index has not seen yet (a buffer edited but not saved, when the file is new) is answered in-file until the next rebuild. That is the same staleness window every other cross-file answer already has, documented in `docs/features/lucisv-server/README.md`. - **A stale index can omit a location; it can never point at a wrong one** (added 2026-09-12, §64.1 rework, QA findings 1–3). Until then this feature's staleness story stopped at the sentence above, which undersold it: a span recorded at index time and rendered against a **closed** file's current bytes — a `references_to` posting, or the `include_declaration` fallback — had no agreement check, so an external edit to that file (another tool, `git checkout`, a build step: none of the five events that drop a cached view) could put a true-looking `Location` on a line that no longer holds the name. `nav::closed_locations` now applies `hover::spells_exactly` to every closed-file span before emitting it and drops the ones that no longer spell the target's name — the same guarantee `hover-declarations` gives a snippet. Open buffers are not guarded and pay nothing: their spans come from the very text they are rendered against. - **A references answer is an indexed lookup.** Each `FileFacts` record stores compact facts for references to externally reachable declarations. The finished `WorkspaceIndex` resolves those facts once into declaration-to-use postings, and a request reads only that posting list. Open documents replace their saved postings with live `Semantics`, preserving unsaved additions and deletions. The old `Workspace::sources()` + refactor walk remains rename's correctness engine but is no longer on the references request path. - **A refusal degrades to the in-file answer, it is not an error.** The shared engine refuses an ambiguous name (declared in two indexed files) exactly as a rename does. `textDocument/references` is a read-only convenience, so the handler sends the file's own occurrences rather than a `RequestFailed`: a highlight the editor can draw beats a shrug, and the refusal the user actually needs to see is the one on the rename they then attempt. - **Reference spans are produced by the semantic analysis and versioned with the file facts.** A cache entry is content-addressed, so a saved span cannot be paired with different bytes; an open file contributes live spans instead. Location conversion fetches and line-indexes each touched file once, however many occurrences it contains. - **`documentHighlight` is a *document* answer even for a cross-file name** (2026-08-28). The cursor on an instantiated module, or on a `.port` in a connection list, highlights that name's uses **in this file** — the workspace overlay is consulted to learn *which declaration* the cursor names, never to widen the answer past the buffer. So the same position can answer 1 here and 7 to `references`, and both are right. - **Read/write is not distinguished** in `documentHighlight`. LSP permits a plain `Text` kind, and telling a read from a write in Verilog means classifying continuous vs. procedural assignment, port direction and `inout` — an analysis worth building for a lint rule, not for a highlight colour. - **Folding is line-based.** No `startCharacter`/`endCharacter`: editors default to whole-line folding, and a character-precise range for `begin`/`end` would buy nothing a reader can see. ## Handshakes **The original public API in `vlog_refactor`**, retained for rename and as the equivalence oracle in tests: ```rust pub fn find_references( files: &[(PathBuf, String)], file: &Path, offset: u32, include_declaration: bool, ) -> Result, String> ``` `files` is the same in-scope set `rename`/`prepare_rename` take (path and current text, open buffers already overlaying disk). The result is sorted by path then by position; an `Err` is the sentence a rename at that position would refuse with. **Where the original sharing lives.** The collection walk is `Scope::collect_occurrences` in `crates/vlog_refactor/src/rename.rs` — lifted out of `collect_edits`, which now calls it and turns the spans into edits. `find_references` (`crates/vlog_refactor/src/references.rs`) calls the same `Scope::build` → `locate` → `collect_occurrences` sequence and keeps the spans. The alternative considered was lifting the walk into `vlog_semantic`; it was rejected because the walk is not a semantic query — it needs the `Scope` cache, the workspace overlay *per file*, and the ambiguity policy, all of which are refactor-crate concerns, and `lucisv_server` already depends on `vlog_refactor`. The indexed implementation is compared directly with this walk in the server tests, so moving the hot path does not create a second semantic answer. **New public API in `vlog_semantic`:** `WorkspaceIndex::{file_id, references_to, references_are_ambiguous}`, plus `DefinitionKey` and `ReferenceSite`. `FileFacts`' encoded shape now includes local and unresolved external reference facts, and `FACTS_FORMAT` is **2**. A changed file rebuilds the merged postings from compact in-memory facts; it does not reread or parse the other files. `Semantics::{symbol_at, reference_at, reference_id_at}` and `Document::token_at` now use start-sorted position tables and binary search. **Consumed from `vlog_semantic`:** `Semantics::{reference_at, reference_id_at, references_of, symbol, symbol_at, scope}`, `Scope::owner`, `Symbol::{name, scope, name_span}`, `ExternalResolutions::get`, `ExternalTarget::best`, `WorkspaceIndex::{units, member, file_id, references_to, references_are_ambiguous}`. **Consumed from `vlog_parser`**: `token::Comment { span }` trivia and `LineIndex::line_col` for folding. **Consumed from this crate's own `pairs.rs`**: `analyze(&[Token]) -> ScopeAnalysis`, unchanged. `folding.rs` is its fourth consumer (`documentHighlight`, the missing-closer warnings, `lucisv/scopePairs`, folding) and reads only `pairs`, never `unmatched_open`/`unmatched_close`. **Promised to the editors**: nothing new to configure. `foldingRange` is a standard capability both VS Code's built-in client and Neovim's `vim.lsp` consume on their own once it is advertised; no extension change was needed and none was made. **Requested of other modules (2026-08-28) — DELIVERED 2026-08-28** by the index-scope round; see `docs/features/index-scope/README.md`, work log "a rescan stops re-parsing what is already analyzed". An open buffer's index facts and completion words now come from the analysis it already holds (`FileFacts::from_analysis`, `words_of_tokens`), on the whole-rebuild path and on `update_one`'s: **~228 ms → ~23 ms** on this feature's own probe. The request as it was written: **Requested of other modules (2026-08-28):** a scope-widening `didOpen` re-parses every open buffer. `Workspace::collect_sources` (`crates/lucisv_server/src/state.rs`) clones each open document's text into the list the index is rebuilt from, so a rescan triggered by opening some *other* file pays a full lex-and-parse of every buffer the user has open — measured at **210 ms of a 223 ms rescan** for one 1.4 MB `top.sv`, against 13 ms for the same 401-file scope with that buffer closed. Every open buffer already holds a finished parse and `Semantics`; `FileFacts::of` re-does both from the text. This is `index-scope` / `state.rs` territory, not this feature's, and the 2026-08-28 brief said measure it and stop — so it is written here rather than changed. The obvious shape (an `IndexBuilder::add_facts` path fed from the buffer's existing analysis instead of its text) is a real option and a separate decision. ## Status / TODO - [x] **`documentHighlight` answered nothing on a cross-file name (2026-08-28, performance wave Lane B):** `performance.md` §7 reported it returning 0 results at *every* opentitan position tried — the `aes` instantiation, the `.clk_i` port connection, at both scopes, before and after a widen — while `references` at the same positions returned 7 and 10. **Not a benchmark mistake: a real bug**, reproduced in a five-line fixture and fixed. Root cause and the argument are in the work log below; the regression tests are `nav::tests::a_cross_file_name_highlights_its_uses_in_this_file` and, over the wire at the same two positions, `e2e::cross_file_references_folding_and_highlights_round_trip_over_the_wire` ids 6 and 7. Still fast now that it answers: **0.05–0.15 ms** against the 0.03–0.12 ms it took to answer nothing. - [x] **References latency with a big buffer open (2026-08-28):** measure both directions of a cross-file references request while a 1.4 MB, 40 000-line `top.sv` is an open document, then fix what the numbers convict. Landed: a **spelled-name prefilter** and a **hoisted `file_id`** in `indexed_references`'s open-document overlay loop, and **walker-batched** span conversion in the two in-file fallbacks. Release probes: **3.20 ms → 110 µs** from the use site, **3.18 ms → 110 µs** from the declaration (29×); the in-file fallback for a signal used 10 001 times, **1.76 ms → 1.18 ms**, and `documentHighlight` on it **1.54 ms → 917 µs**. No answer changes — the equivalence test against `vlog_refactor::find_references` and the whole nav suite are untouched and green. - [x] **Not this feature's to fix, measured and filed (2026-08-28) — fixed elsewhere the same day:** the owner-reported *asymmetry* is not in `references` at all — both directions cost the same, before and after. What is expensive is the `didOpen` that jumping into another folder's file triggers: **220 ms**, of which **210 ms** is re-parsing the open big buffer during the scope-widening rescan. See the work log and Handshakes. Landed by `index-scope` on 2026-08-28 — the open buffer's facts and words now come from its own finished analysis — and this feature's `qa_didopen_latency_when_a_new_folder_widens_the_scope` probe reads **~228 ms → ~23 ms**, with its closed-buffer floor unmoved at ~12 ms. The probe now also prints the buffer's own share of a rescan, before and after, on every run. - [x] **Indexed navigation performance (2026-08-27):** persist each file's externally reachable reference facts beside its declarations, merge them into declaration-to-occurrence postings in `WorkspaceIndex`, and route hover/definition/references through indexed cursor and location lookups. Preserve ambiguity refusals and unsaved open-buffer overlays; prove the indexed answer equals the existing refactor walk before removing that walk from the request path. Release probe: **0.064 ms/request** over 820 synthetic files and five returned locations, versus **23.431 ms** for the old walk on the same workspace. - [x] `Scope::collect_occurrences` factored out of `collect_edits`, with `collect_edits` rewritten on top of it (no behaviour change; the rename suite is the regression test). - [x] `vlog_refactor::find_references`, new module `references.rs`, 7 tests. - [x] `nav::references` routes through `WorkspaceIndex` postings when the symbol can leave the file; the refactor walk remains its tested oracle. - [x] `nav::leaves_this_file` — the index-only gate that keeps a local signal off the workspace walk. - [x] `nav::document_highlights` — symbol occurrences in this file. - [x] `server.rs`: `documentHighlight` tries the scope pair first, the symbol second, and still declines both with `null`. - [x] `folding.rs` — one range per matched pair, plus multi-line block comments, 15 tests. - [x] `foldingRangeProvider` advertised in `main.rs`. - [x] e2e: one session covering cross-file references (both `includeDeclaration` values), `foldingRange` and `documentHighlight`. - [x] `docs/features/lucisv-server/README.md`: capability table, the "not done" list, and Handshakes updated. - [ ] **Not done, deliberately:** line-comment run folding (`//` blocks). The token stream carries each `//` comment separately, so folding a *run* of them means deciding what counts as one run (blank lines? indentation changes? a comment after code on its line?). That is a judgement call with no obviously right answer, and the brief said skip it if it is not trivial. Block comments, which have their own delimiters, are done. - [ ] **Not done, deliberately:** a references answer for an ambiguous name. It falls back to the file's own occurrences; returning both declarations' reference sets, the way `definition` returns both locations, is a real option and a separate decision. - [ ] TODO.md and the `refactor` umbrella checklist were **not** touched, per the milestone brief — the lead owns the two backlog checkboxes this closes ("Cross-file find-all-references", "Folding ranges", "Document highlight" in `docs/features/refactor/README.md`). ## Work log ### 2026-09-12 — dev (TODO §64.1: the gate asks the hierarchical surface) `leaves_this_file` and `indexed_def_in_file` — this feature's two index questions — asked `WorkspaceIndex::member`, the **connection** surface. Since `hierarchical-tail` (0.45.0) a module's net, variable and instance live on the **hierarchical** surface only, so both functions judged such a declaration unable to leave its file: `references` from the declaration fell to the single-file answer and never saw a cross-file `u_x.sig` tail or a `bind` connection expression, and a request that *did* go cross-file could not re-identify the declaring buffer's own in-file uses. Both now ask `member_in(owner, name, Surface::Hierarchical)`. Every connection-surface answer is byte-identical (the connection records come first and whole from that read); the `nav` harness rows are unchanged in count and within noise in time. The closed-declaring-file half of the completeness problem, the new `nav::declaring_file_uses`, the fixture sweep and the attack cases are all written up in `docs/features/references-hierarchical-surface/README.md`, which is this change's feature README. `documentHighlight`'s "a document answer even for a cross-file name" assumption was untouched and is now pinned from both ends (`definition_and_document_highlight_over_a_hierarchical_tail_are_unchanged`). **Rework the same day**, on QA's findings 1–3: the closed-file path reads each closed file exactly once per request, with `text_of` rather than the `file_view` cache, and every index-time span about a closed file is guarded by `hover::spells_exactly` before it is rendered. That is the new Assumptions bullet above; the derivation and the flipped QA tests are in `docs/features/references-hierarchical-surface/README.md`. ### 2026-08-28 — documentHighlight answered nothing on a cross-file name **The report.** `performance.md` §7: `documentHighlight` returned 0 results at every opentitan position tested, while `references` answered at the same positions. It was fast because it was doing nothing, which is the kind of result a benchmark that only times things rewards. **Reproduced first, in five lines.** A `top.sv` that instantiates a `sub` declared in another file, with two instantiations and a `.clk_i` connection on each. `references` at the module name answered 3; `document_highlights` at the same byte answered `None`. That is `a_cross_file_name_highlights_its_uses_in_this_file`, written to fail before anything was changed. **Root cause.** `document_highlights` asked `symbol_at`, which is `Semantics::reference_at(offset).resolved()` or `Semantics::symbol_at(offset)` — **both of them single-file questions**. A name this file *uses* but does not *declare* has no in-file symbol at all: `analyze` records the use as an external candidate and leaves it to the workspace layer, so `reference_at` resolves to nothing and `symbol_at` finds no declaration. An instantiated module's name and a `.port` in a connection list are exactly that shape, and they are most of what a cursor lands on in a testbench. `references` never had the bug because it reads `doc.external` — the workspace overlay — through `leaves_this_file`/`indexed_target`. The two handlers were answering the same question from different halves of the same document, and only one half had been wired up. The existing highlight tests all used a signal declared in the file under test, which is why the suite was green. **The fix**, `nav::external_occurrences`: when `symbol_at` finds nothing, ask the overlay for the reference at the cursor, and if the workspace answered it, collect every reference in *this* file that spells the same name and that the overlay answered the same way. Same-name-and-same-answer rather than same-name: two uses of `clk_i` that resolve into different modules are different symbols, and comparing the whole `defs()` slice rather than its first entry keeps two *ambiguous* uses together only when they are ambiguous between the same declarations. A use the index cannot answer is still left alone, so the editor keeps its own word highlighting — the contract the rest of the function already honours. It stays a **document** highlight: one file's occurrences, which is why the opentitan `aes` position now answers 1 where `references` answers 7. That is not a smaller answer to the same question; `tb.sv` instantiates `aes` once. Nothing outside `nav.rs` changed — the handler in `server.rs` already had the document in hand, and `Document::external` is already beside `Document:: semantics`, so no signature moved. ### 2026-08-28 — references latency with a big buffer open The owner reported find-references from a *use site* in a big open `top.sv` toward a module as "still very slow", and the same request from the module's *declaration* toward its uses as fast. Both run the same `indexed_references`, so the asymmetry was unexplained. Measured first. **The fixture.** Two `#[ignore]`d probes in `nav.rs`'s own test module, beside the `qa_indexed_references_latency_over_a_large_workspace` probe that has been there since 2026-08-27, and taken with `perf::mean` (now `pub(crate)`) so every number in this repo is timed the same way. `generated_top(10_000, 4)` is a 40 000-line, 1 374 KB module of ordinary RTL blocks — a wire, an assign, a register and its update — carrying **70 024 references**, four instantiations of a small `sub`, and one local `acc` used by every block so the file also has a *local* name with 10 001 occurrences. Both files are open documents; the index is built over the directory. ```text cargo test --release -p lucisv_server nav::tests::qa_ -- --ignored --nocapture --test-threads=1 ``` Machine: the one `docs/perf/README.md` records — Apple M1 Max, macOS 27.0, `--release`. Means of 20 runs (5 for the rescan rows). | what | before | after | |---|---|---| | `references` from the **use site** in `top.sv`, `includeDeclaration` | **3.20 ms** | **110 µs** | | `references` from the **declaration** in `sub.sv`, same | **3.18 ms** | **110 µs** | | `definition` from the use site | 1.21 µs | 1.13 µs | | `references` on a local wire used 3× (the in-file fallback) | 1.49 µs | 1.20 µs | | `references` on a local wire used 10 001× | **1.76 ms** | **1.18 ms** | | `documentHighlight` on that same wire | **1.54 ms** | **917 µs** | **Hypothesis 1 is convicted, and it is symmetric.** The open-document overlay loop was the whole 3.2 ms: for every one of the 70 024 references in the open buffer it ran either `indexed_def_for_symbol` — a `file_id` binary search whose comparisons are whole-path `cmp`s, plus a `units`/`member` `BTreeMap` lookup, plus a scope-and-owner chase — or a `doc.external` hash lookup, to discard all but five of them. It cost that whichever end the cursor was on, which is the first thing the measurement says: **the two directions are within 1 % of each other, before and after.** The owner's asymmetry is not in `references`. **Hypothesis 2 registers, but only for a common local name.** The in-file fallback and `documentHighlight` convert their spans one at a time with `positions.range`, which re-measures a line per span. On three occurrences that is 1.5 µs and invisible; on 10 001 it is 1.76 ms. Both now batch-convert with `positions.walker()` over the already-sorted span list, exactly as `locations` has done for the cross-file answer since this feature shipped — 1.5× and 1.7×. The rest of those two figures is collecting, sorting and allocating 10 001 spans, which is the answer's own size and not something to shave here. **Hypothesis 3 is where the felt latency actually is** — measured, and deliberately not redesigned this round (see Handshakes). With the same 1.4 MB buffer open and 401 files in scope: | `didOpen` | cost | |---|---| | a file the folder scope **already covers** | **8.4 µs** | | a file in a **new folder** (`didOpen` + the rescan `server.rs` then runs) | **220 ms** | | — the rescan alone | 223 ms | | — the same rescan with the big buffer **closed** | **13 ms** | So the scope-widening rescan is 223 ms, and **210 ms of it is the open big buffer**: `Workspace::collect_sources` clones every open document's text into the source list and the index re-parses it, at full lex-and-parse cost, on a rescan that was triggered by an entirely different file. That is the shape that matches the owner's report: F12 or a references result *from* `top.sv` opens the module's file, and when that file lives in a folder the folder scope had not reached, the `didOpen` widens the scope and pays a whole rescan. The reverse direction — standing on the declaration and listing its uses — opens nothing new and pays nothing. Filed as a Handshake request against `index-scope` / `state.rs`; no scope code was touched. **The prefilter, and why it changes no answer.** The new first line of the overlay loop is `if reference.name != target.name { continue }`. It is sound because *a `Def` in this index determines the name it is filed under*, and both sides of the old comparison are filed under a name the code already has in hand: - Every indexed `Def` is pushed into `units[name]` or `members[unit][name]` under its own declaration's `name`, and both `facts_of` and `collect_members` skip any declaration whose `name_span` is empty. A non-empty byte range in one file is one identifier, spelling one name — so two different keys cannot hold one `Def` value, and `target.def`'s key is `target.name` in both `indexed_target` arms (the `Local` arm looks the def up *by* `symbol.name` and stores that as `name`; the `External` arm stores the cursor reference's own `name`, which is the only key `follow_one` looks a def up under). - A reference that would have matched is filed under `reference.name`. In the Local arm, a `Resolution::Resolved` comes from `lookup_local(name)` (or an end label the binder checked spells the declaration's name), so `symbol.name == reference.name`, and `indexed_def_in_file` looks up `units[symbol.name]` / `members[owner][symbol.name]`. In the External arm, `resolve_external` calls `follow_one(index, reference.name, path)`, which only ever reads `units[reference.name]` or `member(unit, reference.name)`. So `def == target.def` implies `reference.name == target.name`, and skipping the name-mismatched references skips only work whose answer was `false`. **The `Ambiguous` refusal survives it**, by the same step: the candidates in `ExternalTarget::Ambiguous(defs)` all come out of the bucket keyed by `reference.name`, so `defs.contains(&target.def)` can only be true for a reference spelling `target.name` — which the prefilter always lets through. The `name_span.is_empty()` guard was deliberately *not* hoisted into the prefilter for the same reason: an ambiguous use aborts the whole collection whether or not it has a span, and moving that check earlier would have been a real behaviour change. **The hoist.** `indexed_def_for_symbol` is now two functions: the public one (unchanged signature, still `hover.rs`'s) resolves the document's `FileId` and calls `indexed_def_in_file`, which takes it as an argument. The overlay loop takes the `file_id` once per open buffer instead of once per reference. **What is left at 110 µs** is the loop itself: 70 024 string comparisons plus the iteration. Making that sublinear means a name-keyed reference side table in `Semantics` — the shape `symbols_named` already has for declarations — which is a `vlog_semantic` change this round's brief put out of scope. Not needed at 110 µs; worth naming as the next lever if a file ten times this size shows up. **Tests added** (permanent, all three green before and after the change, which is the point — the prefilter must change cost and not answers): - `a_same_named_port_in_another_open_buffer_is_a_different_symbol` — two modules declare a port `clk`, all three files open; each port's references are its own. The prefilter's risk case, from both sides. - `two_packages_declaring_one_name_keep_their_references_apart` — the same attack through the member table: `p::WIDTH` and `q::WIDTH` used on adjacent lines of one open file, asked from the declaration and from the use. - `every_in_file_occurrence_is_converted_against_its_own_line` — 41 occurrences over 40 lines each carrying a multi-byte and an astral character; every reported range is checked to point at the name, and `documentHighlight`'s ranges are asserted equal to `references`'. A walker handed spans out of order would answer stale columns here. **Gates.** `cargo fmt --all -- --check` clean; `cargo clippy --all-targets` zero warnings; `cargo test --workspace` **2 406 passed, 0 failed** (3 ignored probes in `nav.rs`, one of them pre-existing). Files edited: `crates/lucisv_server/src/nav.rs` and one `pub(crate)` on `perf::mean`. No new dependencies, no `unsafe`, no `unwrap`/`expect` outside `#[cfg(test)]`, no new `#[allow]`. `TODO.md` untouched — this round closes no backlog item; M7 is already checked. Did not `git commit`/`git push`. ### 2026-08-27 — indexed navigation performance - Began replacing the per-request `Workspace::sources()` + `vlog_refactor::find_references` rebuild with reference facts stored in the existing semantic index. The chosen shape is deliberately not a second project model: `FileFacts` remains the per-file persistence and incremental update unit, while `WorkspaceIndex` gains the merged inverted postings. `FACTS_FORMAT` will bump because the persistent record gains fields; the cache's version handshake therefore drops old records rather than reading a partial shape. - Scope remains the scope ladder's decision (filelist exactly when configured, otherwise the folder/workspace setting already in force). This round changes the cost of navigation inside that scope, not which files the user asked the server to index. - Completed the inverted index in the existing `FileFacts` / `WorkspaceIndex` lifecycle. `FACTS_FORMAT` moved from 1 to 2, so an old cache is discarded safely. Incremental save updates rebuild the postings from compact facts already in memory; adding/removing files still follows the index's path-sorted `FileId` contract. - `nav::references` now resolves the live cursor to one indexed declaration, reads its posting list, overlays every open buffer's current semantics, and batches byte-span-to-LSP conversion per touched file. Duplicate declarations and ambiguous uses still fall back to the in-file answer. Permanent tests cover module, package-member and port references, cache round trips, incremental equivalence, ambiguity, unsaved deletions/additions, moved live declarations, and direct equality with `vlog_refactor::find_references`. - Cursor hot paths no longer sweep the whole open file: semantic declaration and reference lookup, plus macro-token hover, use binary-searched position tables. Include definition inspects only the cursor's line. - The ignored release latency probe builds 820 files and returns five locations: **0.064 ms/request** averaged over 200 indexed requests; the old source collection + refactor walk took **23.431 ms** once on the same files (about **366×** slower). Command: `cargo test --release -p lucisv_server qa_indexed_references_latency_over_a_large_workspace -- --ignored --nocapture`. ### 2026-08-24 — dev agent (M7) - **Read first**: `CLAUDE.md`, `docs/features/refactor/README.md`'s triage, `docs/features/lucisv-server/README.md` in full, then `nav.rs`, `pairs.rs`, `state.rs`, `server.rs`, `main.rs`, `vlog_refactor/src/rename.rs` and `vlog_semantic`'s `workspace.rs`/`model.rs`. The design decisions below all came out of that reading rather than out of the brief. - **The sharing shape.** `collect_edits` was two things in one function: the walk that finds every occurrence, and the conversion of spans into checked edits. Splitting it at that seam gave `collect_occurrences` with no new logic and no change to the rename's behaviour — the ambiguity refusal, the `text.contains(&name)` prefilter and the on-demand analysis cache all stayed exactly where they were. `find_references` is 30 lines on top of it. `vlog_semantic` was left alone; the reasoning is in Handshakes. - **The gate was the interesting part, not the collection.** A naive wiring would call `find_references` for every references request, which re-reads the workspace to answer "where else is this `wire`" — 218 ms instead of 1 ms, on every request, for the commonest case. The predicate asks the *index* whether the name is reachable from outside (`units`, or `member` under the unit that owns the declaring scope), which needs no file I/O and no duplicated visibility rules. It falls out of that construction that a module's **ports** are cross-file referenceable — the index exports exactly what a connection list can name — so `.clk(...)` connections in other files now show up as references to the port, which is right and is tested. - **`documentHighlight` gained a second answer rather than a second handler.** `pairs::highlights` is tried first and `nav::document_highlights` second; both return `Option`, and both `None` means `null`, which is what keeps the editor's own word highlighting alive where lucisv knows nothing. The two never compete: a scope keyword is never an identifier. - **Folding stops one line short of the closer** (`endLine = close line - 1`). LSP hides `startLine + 1 ..= endLine`, so this leaves `end`/`endmodule` on screen — the convention that lets a reader see *what* was collapsed. Block comments do the opposite and fold through their last line, because a `*/` alone on screen tells nobody anything. A pair that opens and closes with nothing between the two lines produces no range at all. - **An unmatched opener produces no fold**, for free: `analyze` puts it on `unmatched_open`, not on `pairs`. This is the failure mode that makes people switch folding off — a missing `end` folding the rest of the file away — and it is pinned by its own test rather than left to the data structure. - **Trailing trivia was nearly missed.** The first draft of `folding.rs` walked `token.leading` only, which silently drops every comment written after code on its own line. Caught by writing the test before believing the code; both halves are now iterated and both have a test. - **Perf, measured on the corpus** (release binary, real stdio session, best of three, `initialize` + `didOpen` + one request + `shutdown`): `references` on `prim_lfsr` (declared once, instantiated in 4 other files, 820 source files indexed) — **218 ms** for the request, 535 ms for the whole session against a 317 ms session baseline. `references` on a local `logic` in the same file — **1 ms**, i.e. the gate is shut and no walk happens. Well inside the 1 s budget the brief set. - **No new dependencies.** No `unsafe`, no `unwrap`/`expect`/`panic!` outside `#[cfg(test)]`, no new `#[allow]`. - Did not touch `vlog_parser`, `vlog_formatter`, `vlog_linter`, `lucisv_core`, `crates/lucisv`, `editors/`, `TODO.md` or the umbrella plan. Did not run `git commit`/`git push`. No version bump (0.5.0 is M14's). **Results.** `cargo fmt --all -- --check`: clean. `cargo clippy --all-targets`: 0 warnings. `cargo test --workspace`: **1329 passed, 0 failed**, of which **34 are new**: 15 in `folding.rs`, 11 added to `nav.rs` (20 there in total), 7 in `references.rs`, and 1 e2e (18 in that file now). `node editors/vscode/smoke.js target/release/lucisv-server`: OK. Files added: `crates/vlog_refactor/src/references.rs`, `crates/lucisv_server/src/folding.rs`, this README. Files edited: `crates/vlog_refactor/src/{lib.rs,rename.rs}`, `crates/lucisv_server/src/{main.rs,server.rs,nav.rs}`, `crates/lucisv_server/tests/e2e.rs`, `docs/features/lucisv-server/README.md`. ## QA log ### 2026-08-28 — QA agent, references-latency round Adversarial charter: try to make the new spelled-name prefilter (`nav.rs:248`, `indexed_references`) **change an answer**. Slower-but-right was already true; only a changed answer is a defect this round. #### Soundness of the prefilter — traced by construction, not just trusted Read the dev's write-up's claim against the actual code that makes it true, rather than the prose alone: - `Def` (`crates/vlog_semantic/src/workspace.rs:33`) derives `PartialEq` over `(file, name_span, kind, detail_span)` — it carries no name at all. Its identity is "this declaration, right here," so `def == target.def` can only be decided by the site it points at, never by a spelling. - Every `Decl` is filed under exactly one key, its own declared name: `self.units.entry(decl.name.clone())...push(decl.def(file))` (`workspace.rs:529`) and `self.members.entry(unit.clone())...entry(decl.name.clone())...push(decl.def(file))` (`workspace.rs:535-540`). `decl.name` traces back to `Symbol.name` (`Decl::of`, `workspace.rs:654`), and `Symbol.name`/the scope's `names` map key are the same `name.to_string()` written in one `declare` call (`bind.rs:141` and `bind.rs:151`) — so a `Def` cannot be filed under a name it wasn't declared with, and cannot be filed under two names. - `Scope::lookup_local` (`model.rs:215`) is a plain `HashMap` `get` — no case-folding, no normalization. Every `Resolution::Resolved(id)` in `resolve.rs` comes from `lookup_local(&p.name)` (or `Target::Declaration(id)`, an end label the binder already matched to its opener's name). `Reference.name` is `p.name.clone()` at the exact construction site (`lib.rs:78-79`). So a **locally** resolved reference's `.name` is *definitionally* `symbol.name` — the prefilter reads the same field the binder used to decide the match, not a second, potentially divergent, source of truth. - The **external** arm is the same shape one level up: `resolve_external` (`workspace.rs:1097`) always calls `follow_paths(index, &reference.name, paths)`, and `follow_one` (`workspace.rs:1132`) always queries `index.units(name)` or `index.member(unit, name)` with that same `name` — `path` only picks *which* table, never the key. So both `Resolved(def)` and `Ambiguous(defs)` for a reference are always drawn from the bucket keyed by that reference's own `.name`, which makes the dev's ambiguity-survives argument mechanical rather than incidental: `defs.contains(&target.def)` can only be true when `defs` came from the `target.name` bucket, which only happens when `reference.name == target.name` — exactly what the prefilter already let through. No escaped-identifier or case-folding attack survives this: the lexer (`crates/vlog_parser/src/lexer.rs:304-318`) keeps an escaped identifier's leading backslash in the token text (`\sub` and `sub` are different strings at the token level already), and nothing between the lexer and `Scope::names` ever folds case or strips it — so whatever the binder already does or doesn't unify, the prefilter reads the identical field the binder matched on. There is no code path where `reference.name` and the spelling the binder used to resolve it can diverge, so there is no daylight for the prefilter to exploit. Traced, not fuzzed — I did not find a construction worth writing as a failing-if-regressed test beyond what's below, because the invariant is enforced by there being exactly one string in play, not by a check that could later be weakened unnoticed. **Verdict on the prefilter: sound, no answer-changing case found.** #### Attempts to break it anyway - **Port connection vs. declared name, member-table variant.** Extended the attack beyond the dev's own two tests (`a_same_named_port_in_another_open_buffer_is_a_different_symbol`, `two_packages_declaring_one_name_keep_their_references_apart`) with a name that is a **unit in one file and a member in another** — `module W` and `package p; localparam W = 4;` — plus a **live unsaved edit** to the file using both (a second instantiation added post-open, never saved). Added as `indexed_references_equal_the_refactor_walk_for_a_name_thats_both_a_unit_and_a_member` (`nav.rs:662`), asserted equal to `vlog_refactor::find_references` on `ws.sources()` (which itself overlays the unsaved edit) in both directions. Passed first try — no answer conflation between the `units` and `members` buckets, and the unsaved instantiation is correctly counted. - **Walker ordering/multi-byte/astral attack** on the two newly-batched conversion sites (`in_file_references` and `document_highlights`, now both walker-based per `nav.rs:347` and `nav.rs:374`). The dev's own `every_in_file_occurrence_is_converted_against_its_own_line` already covers this shape well (41 occurrences over 40 lines, each preceded by a multi-byte and an astral character, every reported range checked against the actual byte); I did not find a shape it misses. The walker itself (`crates/lucisv_server/src/convert.rs`, `PositionWalker`) is pre-existing, general-purpose infrastructure (`locations()` has used it since the 2026-08-27 round) with its own dedicated tests for out-of-order offsets, ping-ponging between far-apart lines, and an empty document (`the_walker_agrees_with_the_per_call_converter_on_every_shape`, `a_walker_handed_offsets_out_of_order_still_answers_the_per_call_position`, `a_walker_ping_ponged_between_two_far_apart_lines_still_answers_correctly`, `a_walker_over_an_empty_document_answers_the_one_position_there_is`, all in `convert.rs`) — so the only new risk this round is whether `in_file_references`/`document_highlights` feed it spans in order, and they do: both consume `occurrences()`, which sorts by `span.start` (`nav.rs:413`) before the walker ever sees them. No out-of-order feed exists on either path. - **Ambiguous-abort still aborts.** Re-ran `a_name_declared_in_two_files_degrades_references_to_the_in_file_answer` (already in the suite, unmodified by the dev this round) and traced the `Ambiguous(defs) if defs.contains(&target.def) => return None` arm (`nav.rs:258-260`) by hand against the bucket argument above: an ambiguous external use can only carry `target.def` in its candidate set when it spells `target.name`, which is exactly when the prefilter lets it reach this arm. Confirmed by construction, not just by the still-green test. - **Equivalence, existing test.** `indexed_references_equal_the_refactor_walk_they_replace` (`nav.rs:648`, pre-dating this round) still passes unmodified. #### Measurements reproduced (release, `--release`, this machine) ``` cargo test --release -p lucisv_server nav::tests::qa_ -- --ignored --nocapture --test-threads=1 ``` | what | work log | reproduced here | |---|---|---| | references, use site | 110 µs | 109.8 µs | | references, declaration | 110 µs | 108.9 µs | | definition, use site | 1.13 µs | 0.82 µs | | in-file, wire used 3× | 1.20 µs | 1.12 µs | | in-file, wire used 10 001× | 1.18 ms | 1.17 ms | | documentHighlight, same wire | 917 µs | 916 µs | | didOpen, scope already covers | 8.4 µs | 7.3 µs | | didOpen, new folder (+ rescan) | 220 ms | 214.6 ms | | rescan alone | 223 ms | 217.7 ms | | rescan, big buffer closed | 13 ms | 12.5 ms | All within the charter's 2-3× tolerance (most within 5%) — no contradiction of the work log's order-of-magnitude claims. The pre-existing `qa_indexed_references_latency_over_a_large_workspace` probe (2026-08-27, untouched by this round) also still ran clean: 0.068 ms/request vs. 31.35 ms for the old walk on this machine, consistent with that round's own numbers. #### Gates - `cargo fmt --all -- --check` — clean. - `cargo clippy --all-targets --all-features` — clean, zero warnings (forced re-check by `touch`ing the changed files first, not a cache hit). - `cargo test --workspace` — **2 406 passed, 0 failed** before my addition, matching the work log's count exactly; **2 407** after adding the one permanent equivalence test above. 24 ignored across the workspace (3 in `nav.rs`, one of those pre-existing, matching the work log). **All gates: pass, claims confirmed.** #### Verdict **SHIP.** No corruption, no answer change, no crash found under the adversarial charter. The prefilter's soundness holds by construction (one string, read by both the binder and the prefilter, never normalized or duplicated anywhere in between), not merely by the tests passing. One permanent regression test added (`indexed_references_equal_the_refactor_walk_for_a_name_thats_both_a_unit_and_a_member`, `nav.rs:662`) for the nastier unit/member name-collision case with a live unsaved edit, requested by the round's brief; no other findings warranted a fix or a new test. Review section left untouched. ### 2026-08-24 — QA agent #### Gates - `cargo fmt --all -- --check` — clean. - `cargo clippy --all-targets` — clean, zero warnings (forced re-check after `touch`ing every changed/new file, not a cache hit). - `cargo test --workspace` — **1329 passed, 0 failed**, matching the Work log's count exactly, before I added one regression test (see below); 1330 after. - `node editors/vscode/smoke.js target/release/lucisv-server` — OK. - `cargo test -p vlog_refactor` standalone — **48/48** rename behavior tests green (`tests/rename.rs`), confirming the `collect_edits`/ `collect_occurrences` split changed nothing rename depends on. **All gates: pass, claims confirmed.** #### The factoring (`collect_occurrences` out of `collect_edits`) Read the diff of `crates/vlog_refactor/src/rename.rs` line by line rather than trusting the green suite alone. `collect_occurrences` is exactly the old `collect_edits` walk with `edits_from_spans` peeled off the end; `collect_edits` now calls it and applies `edits_from_spans` to every `(file, spans)` pair, filtering empty results exactly as before (`if !edits.is_empty()`). No reordering, no new dedup, no change to the ambiguity refusal or the substring prefilter. `find_references` shares the same `(usize, Vec)` shape and does its own sort/dedup/declaration handling on top — it does not lean on any rename-specific step. Verdict: **behavior-identical**, confirmed both by the diff and by 48/48 green. #### Attempts to break it (`vlog_refactor::find_references`, API level) Wrote a scratch test file (`crates/vlog_refactor/tests/qa_probe_refs.rs`, removed after the round, not committed) exercising the public API directly: - **`bind`**: `bind top leaf b_leaf ();` correctly appears as a reference to `leaf` alongside the declaration. - **Instance arrays** (`sub u[3:0] ();`): found, alongside the declaration. - **Ambiguous declaration** (two files declare `dup`): `find_references` returns the same refusal sentence a rename at that position would (`` `dup` is declared in more than one indexed file... ``) — verbatim reuse of the rename refusal message, as the Handshakes section promises. - **`import p::*` glob in a third file**: the package member is found at the glob-import site in a file that is neither the declaring file nor the file the cursor started in. - **End labels**: `begin : blk ... end : blk`, asking for references to `blk`, returns **2** occurrences (the `begin` label and the `end` label) — end labels **do** appear in a references answer. Assessed, not a bug: M2 already made end labels *references* of their declaration (`docs/features/refactor-rename/README.md`), and since references and rename share one walk, hiding them from `references` while a rename edits them would be exactly the "two answers about one symbol" lie the Handshakes section says this feature refuses to tell. Correct as built. - **Rename ↔ references consistency**: for a cross-file port case (module `sub` with port `clk`, instantiated by name in two other files), the set of `(file, start-offset)` pairs from `rename`'s edits and from `find_references(..., include_declaration: true)` are **identical** after sorting. Spot-checked in code, not just eyeballed. #### Attempts to break it (`lucisv_server::nav`, handler level) Six scratch tests added temporarily to `nav.rs`'s own test module, run, then removed (`git diff --stat` on `nav.rs` returned to the dev's exact 344/-20 shape before I added the one permanent test below): - **Ambiguous name degrades to in-file, not error, not empty.** Two files declare `dup`; `leaves_this_file` correctly says "yes, ask the workspace" (the index holds `dup` as a unit), `find_references` refuses it as ambiguous, and `references()` falls back to exactly one location — the in-file declaration. This is the claim in Assumptions ("a refusal degrades to the in-file answer, it is not an error") and it holds. **This had no dedicated regression test among the 34 new ones** (the only ambiguity test in `nav.rs`, `an_ambiguous_workspace_name_returns_every_location`, is for `definition`, not `references`) — see "Fix applied" below. - **Cursor on a comment, or a keyword.** `document_highlights` returns `None` (not an empty list); `references` returns an empty `Vec` (not an error) — both correct, both matching the null-not-error contract the README states. - **Sibling scope, same signal name** (`n` declared inside `begin : b1` and independently inside a sibling `begin : b2`): `document_highlights` on `b1`'s `n` returns exactly `b1`'s declaration and use, never touching `b2`'s unrelated `n`. Correct isolation. - **Unsaved buffer overlay, two shapes.** (1) A file already known to the index (`sub.sv`, module `sub` already indexed at `open_roots` time) gets an unsaved `didChange`-style edit to `top.sv` adding a *new* instantiation of `sub`. `references` on `sub` **does** see the new instantiation — `Workspace::sources()` picks up the live buffer text even though the index has not rebuilt. (2) A brand-new file (`sub.sv`, never written to disk, never scanned by `open_roots`) is opened as a pure buffer, while an on-disk `top.sv` genuinely instantiates it. `references` on `sub` sees **only** the in-file declaration — the gate (`WorkspaceIndex`, save- triggered) has never heard of `sub` as a unit, so `leaves_this_file` stays shut, and `top.sv`'s real instantiation is invisible until a save rebuilds the index. Both outcomes match the documented staleness window exactly (Assumptions: "a declaration the index has not seen yet ... is answered in-file until the next rebuild"). - **Port referenceable from both sides, on the real binary** (see below). **Fix applied (small, unambiguous per CLAUDE.md's QA license):** added `a_name_declared_in_two_files_degrades_references_to_the_in_file_answer` to `crates/lucisv_server/src/nav.rs` (permanent, not a probe) — the one claim above that had behavior verified correct but zero regression coverage. Workspace test count is now 1330 (was 1329), gates re-run green after the addition. #### documentHighlight, on the real binary Independent stdio session (own script, not `tests/e2e.rs`) against a 2-file fixture (`leaf.sv`/`top.sv`, port `clk_i`, an `always_ff` block): - Cursor on `clk_i` inside the sensitivity list → highlights the port declaration (line 1) and this in-file use (line 5), `kind: Text` (`1`). - Cursor on the `begin` keyword → `pairs::highlights` answers first: `begin` and its matching `end`, not the symbol path. Fallthrough order confirmed live, not just read from the diff. - Cursor on the `always_ff` keyword → `null`. #### Folding, independent attacks Six scratch tests added temporarily to `folding.rs`'s own test module (run, then removed — file back to its original 249 lines): - **A 2-line `begin`/`end`** (`initial begin\nend`): produces **no** range — `through = close_line - 1 == open_line`, so `push` drops it. Only the enclosing module folds. Matches the documented "opens and closes with nothing between the two lines produces no range at all." - **CRLF file**, module + `initial begin`/`end` + a 2-line block comment, all with `\r\n` line endings: every fold lands on the right line, no off-by-one from the `\r` bytes. - **An unmatched opener sitting between two *matched* pairs** (`begin` (unmatched) between a matched `begin/end` before it and another matched `begin/end` after it, all inside one module): the unmatched `begin` produces no fold, the two real pairs fold correctly, and — significant — the *later* `begin` matches its own `end` rather than the earlier, orphaned one picking it up. Confirms the pair-matcher is a proper LIFO stack per keyword family, not a naive first-open/first-close scan, so an interior unmatched opener cannot cause a *later*, unrelated pair to be misattributed. No fold reached past the file's own last line either. - The "unmatched-begin file from the rainbow QA" round itself does not exist as a checked-in fixture (searched the tree; no `rainbow` feature README, no saved fixture file) — reconstructed the shape described in the M7 QA brief (an opener with no closer, amid otherwise-valid code) rather than reusing a file that isn't in this tree. - One-line block comment already covered by the dev's own `a_one_line_comment_of_either_spelling_folds_nothing` — read and confirmed correct rather than re-proven. #### Independent e2e: cross-file references + folding round trip Own hand-rolled Python stdio client (`write-then-read-all`, same rationale `tests/e2e.rs` documents at its own top, not the dev's script or fixture) — `leaf.sv` (a clocked module) instantiated twice by `top.sv`: - `references` on `leaf`'s declaration, `includeDeclaration: true` → 3 hits (declaration + both instantiations); `false` → 2 hits, declaration correctly dropped and nothing else lost. - `references` on the **connection-side** `.clk_i(...)` name in `top.sv` (not the declaration, not the expression) → resolves to the *port*'s full reference set: the port declaration, its in-file use inside the `always_ff` sensitivity list, and both connection sites across the two instantiations. Confirms ports are reachable **from a connection**, not only from the declaration side (the corpus perf run below confirms the declaration-side direction). - `foldingRange` on `leaf.sv` → exactly two ranges, the module (0–8) and the `always_ff` block (5–7), both boundaries correct. #### Performance Reconfirmed the dev's corpus measurement independently (own Python driver, release binary, real stdio session, `initialize` → `didOpen` → one `references` request → `shutdown`): `references` on `prim_lfsr`'s module name — **528.5 ms** whole-session wall time. A 3-run baseline session with no request (`initialize`/`initialized`/`shutdown`/`exit` only) measured **~317 ms**, so the request itself costs **~211 ms** — matches the Work log's 218 ms / 535 ms / 317 ms triad closely enough to call it the same number, measured twice. **New measurement: a common name, the text-prefilter's worst case.** Ports named `clk_i` appear (as a substring) in **360 of 860** corpus files — every one of those pays the "does the text contain the name" check and, on a hit, a full re-analysis. `references` on `prim_lfsr`'s own `clk_i` port — **3–4 runs, 612–627 ms** whole-session, i.e. **~295–310 ms** for the request alone. That is only ~1.4× the already-cross-file `prim_lfsr` case above, not a blowup, even though the prefilter had roughly 8× more files to look past (45 files spelling `prim_lfsr` vs. an estimated few hundred spelling `clk_i`, not counted exactly). Comfortably inside any reasonable request budget. **This scenario was not in the dev's own perf writeup** — worth having on record since "a port named like every other port in the codebase" is a completely ordinary real-world query, not an edge case. **Corpus file count, a documentation-only discrepancy.** The Work log says "820 source files indexed"; the Assumptions section separately says "the 860-file corpus". A plain `find` over `corpus/` for `.v`/`.sv`/`.svh`/`.vh` returns exactly **860**, matching every earlier round's number for this same directory (`docs/features/lucisv-server/README.md`'s QA log, 2026-08-19: "860 files"). `corpus/` itself is listed in the repo's own `.gitignore`, but the LSP root was pointed *at* `corpus/`, so that rule is moot; however `corpus/` contains **19 nested `.gitignore` files** from the vendored upstream repos themselves (`corpus/ibex/.gitignore`, `corpus/opentitan/.gitignore`, etc.), and the workspace walk has honored `.gitignore` unconditionally since `lucisv-core-lift` landed the same day as this round. So 820 vs. 860 is plausibly real — some vendored generated/build files are legitimately excluded now that they weren't when the 860 number was first measured — but I could not independently confirm 820 exactly: LSP exposes no "how many files did you index" answer, and `workspace/symbol` is capped at 256. **Not filed as a defect** — the explanation is plausible and the actual measured behavior (references answers, timings) was correct throughout — but flagging the inconsistency between the README's own two numbers (820 in Work log vs. 860 in Assumptions, for what reads as the same measurement) so whoever owns the prose can pick one and true it up. #### A process discrepancy worth the lead's attention (not a code defect) The Work log states plainly: "Did not touch ... `TODO.md` or the umbrella plan." But `git diff HEAD -- TODO.md` currently shows an uncommitted, 20-line addition — the M7–M14 checklist items — that is **not** part of `HEAD` (`6036a62`, which only touched `docs/features/refactor/README.md` per `git show --stat`). I did not revert it (TODO.md is explicitly out of QA's scope per the round brief, and I cannot tell from the working tree alone whether this is unfinished, not-yet- committed lead work from the same triage session, or something the dev agent added despite its own claim). Flagging so the lead can reconcile the Work log's claim against what is actually sitting in the working tree before commit. #### Summary | Claim | Verdict | |---|---| | Gates (fmt/clippy/test/smoke) | **Pass**, 1329 confirmed (1330 after my one added test) | | `collect_occurrences` factoring is behavior-identical | **Pass** — diff-reviewed and 48/48 rename tests green | | `find_references`: bind, instance arrays, glob import, ambiguous refusal, end labels, rename/references consistency | **Pass**, all as documented | | `nav::leaves_this_file` gate, ambiguous degrade, sibling isolation, comment/keyword null, unsaved-overlay behavior (both shapes), staleness window | **Pass**, all as documented | | Ports cross-file referenceable from both the declaration and a connection | **Pass**, confirmed on the real binary | | `documentHighlight` fallthrough order (pairs first, symbol second, null third) | **Pass**, confirmed on the real binary | | Folding: 2-line block, CRLF, unmatched-opener-amid-matched-pairs (LIFO correctness) | **Pass** | | Independent e2e round trip (references × 2 + folding) | **Pass** | | Perf: prim_lfsr corpus measurement | **Pass**, reconfirmed independently (~211 ms request, matches dev's 218 ms) | | Perf: common-name worst case (new measurement) | **Pass** — ~300 ms request, no blowup | | Corpus file count in the README (820 vs. 860) | **Informational** — plausible, not independently confirmable, prose-only inconsistency | | TODO.md untouched (Work log claim) | **Contradicted by the working tree** — flagged for the lead, not fixed | No corruption, no crash, no silent wrong answer found anywhere. One permanent test added (small, unambiguous, per CLAUDE.md). No probe files left in the tree; `nav.rs` and `folding.rs` diffs verified to match the dev's original shape plus exactly my one addition. **Verdict: ship**, with the two informational items (corpus count prose, TODO.md discrepancy) left for the lead to reconcile — neither is a correctness or safety issue in the shipped feature. ### 2026-08-28 — QA agent (performance wave Lane B: the documentHighlight fix) Verdict: **the fix is correct and holds under attack. One genuine behavioral divergence from `references` found and recorded (not a bug, but the lead should see it before calling the two "cross-checked").** **Reproduced the original bug, live.** Built this worktree's release binary, pointed a copy of the scratchpad's `lspclient.py`/`bench.py` harness at it (`SERVER` edited to `target/release/lucisv-server`, `ROOT` unchanged at `/Users/guoliangchen/repo/opentitan`), and ran `bench.py nav workspace -` against the real checkout: `documentHighlight(aes)` and `documentHighlight(.clk_i)` now each return **1 result** (the `tb.sv`-local occurrence — correctly fewer than `references`'s 7/10, since `references` is workspace-wide and highlight is this-file-only by contract), where `performance.md` §7 recorded 0. Confirms the fix end-to-end, not just in the unit suite. **Attacked the grouping logic (charter item 4) with three new permanent tests in `nav.rs`:** 1. `an_ambiguous_instantiation_highlights_where_references_gives_up` — two files both declare `module dup`, instantiated twice in a third file. `document_highlights` correctly groups both instantiations (same ambiguous def set). **Finding, not a bug**: `references` at the same position returns *empty*, not the same answer — traced to `indexed_target` (`nav.rs`), which only builds an `IndexedTarget` from `Definition::External([def])`, exactly one candidate; an ambiguous external use (2+ candidates) makes it return `None`, so `references()` falls through to `in_file_references`, which requires a *local* symbol (`symbol_at`) that an external use does not have — net empty, and this is pre-existing, unrelated to this round. `document_highlights`'s new `external_occurrences` has no such restriction: it groups by the overlay's whole answer, ambiguous sets included. This is a genuine divergence from "highlights == references-in-this-file at the same position", though arguably the *better* behavior (answering something reasonable beats forcing the editor's own word-highlighter to fall back to nothing) — recorded per the charter's instruction to cross-check rather than assumed away. 2. `two_uses_ambiguous_between_different_def_sets_do_not_group` — the sin the charter names directly. Building this took two attempts: my first version used two module-scope `import p1::*; import p2::*;` wildcards expecting position-scoped ambiguity, and it failed — both usages grouped together (lines `[3, 5]` where I expected `[3]` and `[5]` separately). Root cause, traced through `bind.rs::bind_module` / `follow_paths`/`follow_one`: imports are collected per-scope and tried *in declaration order*, and `follow_paths` returns on the **first** path with any answer — so multiple wildcard imports of packages that each independently declare the same member never produce a multi-package `Ambiguous`; each reference resolves against whichever imported package is tried first. Real ambiguity comes from **duplicate declarations of the same entity** (two files declaring the same module/package), not from multiple distinct wildcard imports. Rebuilt the test around two *different* modules (`dup_a`, `dup_b`), each duplicated across two files, both exposing a port named identically (`same_port`) and connected in the same top module — same `reference.name`, disjoint ambiguous def sets (`dup_a`'s two files vs. `dup_b`'s two files). Passes: the two connections do not group. This is the test that actually proves `external_occurrences`'s `defs()` comparison (not just the name match) is load-bearing. 3. `an_unanswered_external_use_declines_rather_than_guessing` — an import of a package the workspace does not declare, and a member reference the overlay cannot place. `document_highlights` returns `None` (declines), confirming the empty-`defs()` early-out and preserving the editor's own word-highlighting fallback. **Cross-file name collision (charter item 4, "local at one position, external at another")**: traced by hand rather than by a new test — `external_occurrences` only ever matches a candidate occurrence through `doc.external.get(at)`, which is populated only for references the workspace overlay actually resolved (`resolve_external`, `vlog_semantic::workspace`); a same-spelled local declaration/use has no entry there, so `None == Some(target.defs())` excludes it automatically. No counter-example found. **Reference-id indexing**: confirmed `ReferenceId(i)` in `vlog_semantic::lib.rs` corresponds exactly to index `i` in `Semantics::references()`'s backing `Vec` (`self.references.get(id.0 as usize)`), so `external_occurrences`'s `enumerate()` + `ReferenceId(*at as u32)` round trip is not an off-by-one risk. **Gates**: `cargo fmt --check`, `cargo clippy --all-targets`, `cargo test --workspace` (1261 passed), `node editors/vscode/smoke.js target/release/lucisv-server` — all clean, run against the worktree including my three additions. No fixes applied to feature code — the fix is correct as shipped. Three permanent regression tests added to `nav.rs`. No commits. ## Review **2026-08-28 — lead, performance-wave Lane B (documentHighlight).** The zero-results report was a real bug with a clean root cause: both cursor questions were single-file, so a name this file uses but does not declare had no answer, and every existing test used a declared name. The fix reads the overlay and groups by the whole defs() slice — the conservative equality — and was written failing-first with the two exact opentitan positions pinned over the wire. QA's INFORMATIONAL asymmetry (highlight answers on a globally-ambiguous target where references declines) is pre-existing, arguably correct — a highlight is file-local and read-only — and is now recorded here rather than discovered again. Accepted. **2026-08-28 — lead, references-latency round.** Reviewed after QA's clean SHIP; gates re-run independently (fmt clean, clippy silent, 2407 workspace tests green). Measure-first discipline held: the probes were written and their before-numbers recorded ahead of any fix, and they convicted the overlay loop (H1) while acquitting `references` of the owner-reported asymmetry — which the didOpen numbers (H3) explain instead, correctly filed as a Handshake request rather than fixed cross-scope. The prefilter comment in `indexed_references` points at the soundness argument, QA traced that argument to the code (single-key filing, no name normalization anywhere between lexer and lookup), and the unit-vs-member equivalence test QA added is the sharpest same-spelling case the design admits. The empty-span check deliberately left unhoisted — so a spanless ambiguous use still aborts — is the kind of detail that separates a fast loop from a subtly different one; noted with approval. Accepted; the scope-widening rescan follow-up (210 ms of re-parsing open buffers) is the next round. **2026-08-27 — lead, indexed-navigation performance round (external dev: codex).** Reviewed the full diff line-by-line and ran all three gates independently (fmt clean, clippy silent, 1155 server tests + workspace suite green). The design keeps the one-project-model rule: reference facts live in `FileFacts` (the existing persistence and incremental unit), postings are merged in `WorkspaceIndex`, and `FACTS_FORMAT` 1→2 plus the cache header's format handshake discards every v1 store whole — verified in `index_cache.rs:324`. `macro_definitions` filters `DefineKind::Define`, byte-identical semantics with the `DefineTable::all` it replaces. Ambiguity is preserved everywhere it mattered: ambiguous postings are marked, an ambiguous live overlay use aborts to the in-file answer mid-collection, and the rename refusal contract survives. The equivalence test pins the indexed answer to the old `vlog_refactor::find_references` walk, which stays as rename's engine and the oracle. Lead re-ran the ignored release probe: 0.062 ms/request over 820 files vs 21.7 ms for the old walk (~350×), consistent with the work log's numbers. No QA-agent pass this round; the lead review substituted, and the incremental-fingerprint, unsaved-buffer and ambiguity tests cover the paths a QA attack would have targeted. Accepted. **2026-08-24 — lead.** Reviewed after QA's ship verdict (clean first pass); gates run independently (1330 tests, 0 failures, clippy silent). The factoring is the right move — `collect_occurrences` peeled out of rename with the edit-conversion left behind, QA line-verified it behavior-identical — and `leaves_this_file` asking the index instead of re-deriving exportedness is exactly the no-second-resolution rule the umbrella plan demands. Folding as the fourth consumer of `pairs::analyze` cost one file. QA's added regression test for the ambiguous-degrade path is accepted with thanks; its corpus-count discrepancy note (820 vs 860) is the gitignore-aware walk, as suspected, and its TODO.md flag was the lead's own uncommitted M7–M14 queue. Rename↔references span consistency was verified — the property that makes this milestone honest. Accepted; M7 checked off in the umbrella plan and TODO.md §8.