# vscode-references-view ## Goal The user's report: "the find all references highlight doesn't show the full line in the references pane." The server's `textDocument/references` ranges are exact — each covers just the identifier (lead, verified at the LSP level). The truncation is VS Code's: its References view and peek build each preview from about eight characters before the match to the end of the line, so `always_ff @(posedge clk) r <= ~r;` reads `clk) r <= ~r;`. The server cannot change that, so the fix is in the extension: a lucisv **References** view that shows every reference's **whole line** with the identifier highlighted, grouped by file, and takes over Find All References (`Shift+Alt+F12`) in Verilog/SystemVerilog editors behind a setting. ### Design - **Where the view goes:** a `TreeView` (`lucisv.references`) in the existing `lucisv` activity-bar container, under Hierarchy. The built-in References view also lives in the sidebar, so the user finds the answer where they already look for it; a second container (or the bottom panel) would be one more place for one view. The view is hidden (`when: lucisv.references.hasResults`) until the first search fills it, the way the built-in one is, so the Hierarchy sidebar is unchanged for anyone who never uses it. A **Clear** title action empties and hides it again. - **Rows:** one per file — the workspace-relative path (`workspace.asRelativePath`), the reference count as the description, the file icon — expanded; the current file first, then by path. Under it one row per reference in line order: the whole line trimmed, the identifier highlighted (`TreeItemLabel.highlights`), `line N` as the description, and `path:line:col` as the tooltip. The declaration — the reference that starts where a definition-provider answer does — gets the `symbol-key` icon and `declaration · line N`. A click runs `vscode.open` with the exact reference range as `selection`. - **Title:** `References: (N in K files)`; an empty answer leaves `References: ` with the message `No references to .` - **Command:** `lucisv.references.show`, "Find All References (full lines)", in the editor context menu and the command palette for verilog/systemverilog only. It runs `vscode.executeReferenceProvider` and `vscode.executeDefinitionProvider` at the cursor (VS Code's own provider commands, so the answer is exactly what the built-in view gets — the extension adds no request of its own), reads the lines, fills the view and reveals it (`setContext`, then `lucisv.references.focus`). - **Setting and keybinding:** `lucisv.references.fullLineView` (boolean, default `true`). A contributed keybinding binds `shift+alt+f12` (no `mac` override: macOS uses the same chord) to the command with `when: editorTextFocus && editorHasReferenceProvider && config.lucisv.references.fullLineView && editorLangId =~ /^(system)?verilog$/`. When the setting is off, or the editor is any other language, the clause is false and the key resolves to whatever VS Code would have run — the built-in command is never unbound. `Shift+F12` (peek) is not touched. - **Reading lines:** an open document is read from its buffer (unsaved edits are what the server answered against); a closed file through `workspace.fs.readFile`, decoded as UTF-8, **not** `openTextDocument`. That is a deliberate deviation from the brief's "whichever the extension already uses" (Hierarchy uses `openTextDocument`, for one file it is about to show): `openTextDocument` on a closed Verilog file makes the language client send the server a `didOpen`, so a 500-reference answer across 100 files would open 100 documents on the server and fill Problems with their diagnostics just to draw preview lines. Every file is read once, in parallel; a file that cannot be read still lists its references, labelled `line N`. - **Modules:** `referencesModel.js` is pure (no `vscode`): grouping, ordering, trimming, highlight offsets, the declaration mark, the title. `referencesView.js` is the TreeView, the commands and the line reader. `extension.js` gains two lines. ## Assumptions - `vscode.executeReferenceProvider` asks providers with `includeDeclaration: true`, as VS Code's own Find All References does, so the declaration is in the list for the mark to find. Not enforced here; if it ever is not, no row is marked and nothing else changes. - An extension-contributed keybinding with a matching `when` clause wins over VS Code's default `shift+alt+f12` binding (including the built-in references-view extension's `references-view.findReferences`): user extensions' keybinding contributions are registered after the defaults and built-in extensions'. Not verifiable headless. - `editorLangId =~ /…/` regex `when` clauses are supported (they are since well before the extension's `engines.vscode` floor, 1.82). - The `.focus` command VS Code generates for every contributed view reveals a view that was hidden by its `when` clause once the context key is set — the built-in references view does the same (`setContext`, then focus). - Closed files are UTF-8 (or ASCII). A Latin-1 byte decodes to U+FFFD, one UTF-16 unit for one byte, so offsets on such a line still line up; only that character's glyph is wrong in the preview. - A tab is shown as one space, so a highlight offset never moves; the preview is not column-aligned and does not need to be. - A line longer than 240 characters after trimming is cut to a 240-character window that keeps 60 characters before the match, with `…` marking each cut — so a generated netlist line cannot become a 100 000-character label. ## Handshakes - **Consumes from VS Code:** `vscode.executeReferenceProvider`, `vscode.executeDefinitionProvider` (Location or LocationLink answers — a link is matched by `targetSelectionRange`, then `targetRange`), `vscode.open`, `setContext`, the generated `lucisv.references.focus`, `window.createTreeView`, `workspace.fs.readFile`, `workspace.textDocuments`, `workspace.asRelativePath`. - **Consumes from the server:** nothing new. The answers are the server's `textDocument/references` and `textDocument/definition`, through the language client's providers. No server change; the other lane's `crates/lucisv_server/**` is untouched. - **Promises:** a contributed view `lucisv.references` in the `lucisv` container, commands `lucisv.references.show` / `lucisv.references.clear`, context key `lucisv.references.hasResults`, setting `lucisv.references.fullLineView`. - **Request (release docs, not owned by this lane):** `tools/RELEASING.md`'s vsix-content check lists `restart.js` and `mcp.js` as the runtime files that must ship; it should also name `referencesModel.js` and `referencesView.js` (and, while it is there, the `hierarchy*.js` modules and `extract.js`, which it already omits). `tools/release.sh` asserts no JavaScript file list — only `bin/` contents — so it needs no change. In this lane the shipping is pinned by `referencesView_test.js::theRuntimeFilesShip` (reads `.vscodeignore`) and was confirmed with `vsce ls` (see the work log). ## Status / TODO - [x] `referencesModel.js`: groups, order, trim/tab/CRLF offsets, multi-line and clamped ranges, over-long lines, declaration mark, title. - [x] `referencesView.js`: TreeView, show/clear commands, stale-answer guard, buffer-or-disk line reader. - [x] `package.json`: view, commands, context menu, palette, title action, keybinding, setting. - [x] `.vscodeignore`: the two new tests excluded; runtime files ship. - [x] `extension.js` wiring (two lines). - [x] `editors/vscode/README.md` (feature row + setting) and `CHANGELOG.md` (Unreleased). - [x] Headless tests: `referencesModel_test.js`, `referencesView_test.js`. - [ ] Manual check in a real VS Code: keybinding precedence over the built-in, reveal of the `when`-hidden view, highlight rendering (QA / lead). ## Work log - 2026-10-14 (dev): Read the extension, the hierarchy view/model/tests and the hierarchy-sidebar README. Chose a native `TreeView` over another webview — `TreeItemLabel.highlights` is exactly "highlight a span of a label", and a tree gets keyboard navigation, collapse-all and theming for free; the hierarchy needed a webview only for its persistent search field. Put the view in the existing `lucisv` container, hidden until filled. Read closed files with `workspace.fs` rather than `openTextDocument` (reason in Design). Declaration mark: exact start match against the definition answer, with a containment fallback used only when nothing matches exactly (a provider whose definition range is the whole declaration). Duplicate locations are collapsed. A newer search wins over a slower older one (request counter). Tests: `node --test editors/vscode/*_test.js` under `tools/guard.sh -t 300` went from 6 files / 6 pass to 8 files / 8 pass. `npx --offline @vscode/vsce ls --no-dependencies` (cached vsce, no network) lists `referencesModel.js` and `referencesView.js` and none of the `*_test.js` files. ## QA log - 2026-10-14 — QA agent (Sonnet). **Verdict: PASS with findings (all low).** - Suite: `tools/guard.sh -t 300 -- node --test editors/vscode/*_test.js`: 8 files / 8 pass / 0 fail (`node --test` counts one test per file; each file is a single script of many assertions, so 8 is not an assertion count). `vsce ls --no-dependencies` (cached, offline, under the guard, rc 0) lists `referencesModel.js` and `referencesView.js`, no `*_test.js`. - Test strength: mutation-checked in a scratch copy. Deleting the `asked !== this.request` guard fails `aStaleAnswerDoesNotOverwriteANewerOne`; removing `.trim()` fails `theReportedLineIsShownWhole`. Not tautological. - Model attacks (scratch script, `referencesModel.js` required directly). Server negotiates UTF-16 (`crates/lucisv_server/src/main.rs:191`); the model indexes JS strings, which are UTF-16, so emoji and CJK before the match highlight exactly the identifier. Also clean: tabs, column 0, zero-length range (no highlight, line still shown), reversed ranges (same and cross line), negative character, empty file, reference past the last line (empty label, `line N` row), no trailing newline, NBSP indentation, 5 000 references in one file (9 ms), 2 000 files (3 ms), `untitled:` and `file:///c%3A/...` URIs, URI objects deduped, LocationLink declaration mark, windowing at start, middle and end of a 2 005-char line (highlight always inside the window; ellipsis offsets right). - Manifest: language ids registered are only `verilog` and `systemverilog` (`package.json` contributes.languages; `extension.js:34`), so the `^(system)?verilog$` regex misses nothing. Setting default/description match `README.md:306`. Palette, view `when`, menu group fine. - Findings: 1. LOW — `referencesModel.js:94`: the 240-char window can cut between the two halves of a surrogate pair (reproduce: `'😀'.repeat(300)+'sig'`, match at 600), leaving a lone surrogate (renders as a replacement glyph) at the edge next to the `…`. Cosmetic; highlight offsets stay correct. 2. LOW — `referencesView.js:130`: every file is read whole and in parallel with no cap; 2 000 referenced files means 2 000 concurrent reads and all their text held at once until the groups are built. A huge generated netlist is read in full for one line. Unlikely, bounded by the answer, no correctness impact. 3. LOW — `referencesView.js:141`: decoding is UTF-8 only. A BOM is stripped (matches VS Code's buffer, so columns agree). A UTF-16 file or an invalid UTF-8 sequence spanning several bytes decodes to fewer units than bytes, so on such a line the Assumptions' "one unit per byte" can be off and the highlight may shift. Latin-1 single bytes are fine. 4. LOW (docs) — `tools/RELEASING.md:204-210` still names only `restart.js` and `mcp.js` as must-ship runtime files; the dev filed this as a handshake. Not touched (outside lane scope). - Reviewed and clean: stale-search guard covers the failure path and `clear()` (both bump/compare `this.request`); every disposable is in `context.subscriptions`; `readLines`/`fileReader` cannot reject (read errors caught), and the `show` command's own rejections surface as VS Code's command-error toast; no workspace folder makes `asRelativePath` return the absolute path, which is fine; no `openTextDocument`, so no didOpen flood. - Unverified (needs a real VS Code): the contributed keybinding beating the built-in `shift+alt+f12`; `config.lucisv.references.fullLineView` resolving true by default (not just when set explicitly); `.focus` revealing a `when`-hidden view; highlight rendering; the context menu showing both the built-in and this entry. - Fixes made by QA: none. ## Review **2026-10-14 — lead.** Accepted. The view is additive: a hidden tree view, one command, one keybinding gated on the setting and the two language ids, and no change to the server or the built-in commands. Reading closed files with `workspace.fs` rather than `openTextDocument` (no didOpen flood) is the right call. QA's four lows are recorded and accepted as is (the surrogate split is cosmetic; UTF-16/invalid-UTF-8 files are rare in RTL). The `tools/RELEASING.md` handshake is granted: its must-ship list now names every runtime module. Still to confirm in a real VS Code: the keybinding winning over the built-in Find All References, the hidden view revealing on first use, and how the highlights render.