VS Code's built-in references pane cuts each preview to ~8 characters before the match. lucisv.references.show runs the same reference and definition providers and fills a tree view in the lucisv sidebar: one row per file (current file first), one row per reference with the trimmed full line and the identifier highlighted, the declaration marked; a click selects the exact range. The setting lucisv.references.fullLineView (default true) binds Shift+Alt+F12 to it in verilog/systemverilog editors only; Shift+F12 peek is untouched. Closed files are read with workspace.fs, so no didOpen reaches the server. QA (Sonnet): PASS with 4 lows (recorded). Node tests 8/8. tools/RELEASING.md must-ship list names every runtime module (lane handshake). docs/features/vscode-references-view. Co-Authored-By: Claude Opus 5.5 <[email protected]>
14 KiB
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 existinglucisvactivity-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 Nas the description, andpath:line:colas the tooltip. The declaration — the reference that starts where a definition-provider answer does — gets thesymbol-keyicon anddeclaration · line N. A click runsvscode.openwith the exact reference range asselection. - Title:
References: <name> (N in K files); an empty answer leavesReferences: <name>with the messageNo references to <name>. - Command:
lucisv.references.show, "Find All References (full lines)", in the editor context menu and the command palette for verilog/systemverilog only. It runsvscode.executeReferenceProviderandvscode.executeDefinitionProviderat 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, thenlucisv.references.focus). - Setting and keybinding:
lucisv.references.fullLineView(boolean, defaulttrue). A contributed keybinding bindsshift+alt+f12(nomacoverride: macOS uses the same chord) to the command withwhen: 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, notopenTextDocument. That is a deliberate deviation from the brief's "whichever the extension already uses" (Hierarchy usesopenTextDocument, for one file it is about to show):openTextDocumenton a closed Verilog file makes the language client send the server adidOpen, 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, labelledline N. - Modules:
referencesModel.jsis pure (novscode): grouping, ordering, trimming, highlight offsets, the declaration mark, the title.referencesView.jsis the TreeView, the commands and the line reader.extension.jsgains two lines.
Assumptions
vscode.executeReferenceProviderasks providers withincludeDeclaration: 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
whenclause wins over VS Code's defaultshift+alt+f12binding (including the built-in references-view extension'sreferences-view.findReferences): user extensions' keybinding contributions are registered after the defaults and built-in extensions'. Not verifiable headless. editorLangId =~ /…/regexwhenclauses are supported (they are since well before the extension'sengines.vscodefloor, 1.82).- The
<viewId>.focuscommand VS Code generates for every contributed view reveals a view that was hidden by itswhenclause 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 bytargetSelectionRange, thentargetRange),vscode.open,setContext, the generatedlucisv.references.focus,window.createTreeView,workspace.fs.readFile,workspace.textDocuments,workspace.asRelativePath. - Consumes from the server: nothing new. The answers are the server's
textDocument/referencesandtextDocument/definition, through the language client's providers. No server change; the other lane'scrates/lucisv_server/**is untouched. - Promises: a contributed view
lucisv.referencesin thelucisvcontainer, commandslucisv.references.show/lucisv.references.clear, context keylucisv.references.hasResults, settinglucisv.references.fullLineView. - Request (release docs, not owned by this lane):
tools/RELEASING.md's vsix-content check listsrestart.jsandmcp.jsas the runtime files that must ship; it should also namereferencesModel.jsandreferencesView.js(and, while it is there, thehierarchy*.jsmodules andextract.js, which it already omits).tools/release.shasserts no JavaScript file list — onlybin/contents — so it needs no change. In this lane the shipping is pinned byreferencesView_test.js::theRuntimeFilesShip(reads.vscodeignore) and was confirmed withvsce ls(see the work log).
Status / TODO
referencesModel.js: groups, order, trim/tab/CRLF offsets, multi-line and clamped ranges, over-long lines, declaration mark, title.referencesView.js: TreeView, show/clear commands, stale-answer guard, buffer-or-disk line reader.package.json: view, commands, context menu, palette, title action, keybinding, setting..vscodeignore: the two new tests excluded; runtime files ship.extension.jswiring (two lines).editors/vscode/README.md(feature row + setting) andCHANGELOG.md(Unreleased).- 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
TreeViewover another webview —TreeItemLabel.highlightsis 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 existinglucisvcontainer, hidden until filled. Read closed files withworkspace.fsrather thanopenTextDocument(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.jsundertools/guard.sh -t 300went from 6 files / 6 pass to 8 files / 8 pass.npx --offline @vscode/vsce ls --no-dependencies(cached vsce, no network) listsreferencesModel.jsandreferencesView.jsand none of the*_test.jsfiles.
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 --testcounts 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) listsreferencesModel.jsandreferencesView.js, no*_test.js. - Test strength: mutation-checked in a scratch copy. Deleting the
asked !== this.requestguard failsaStaleAnswerDoesNotOverwriteANewerOne; removing.trim()failstheReportedLineIsShownWhole. Not tautological. - Model attacks (scratch script,
referencesModel.jsrequired 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 Nrow), no trailing newline, NBSP indentation, 5 000 references in one file (9 ms), 2 000 files (3 ms),untitled:andfile:///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
verilogandsystemverilog(package.jsoncontributes.languages;extension.js:34), so the^(system)?verilog$regex misses nothing. Setting default/description matchREADME.md:306. Palette, viewwhen, menu group fine. - Findings:
- 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. - 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. - 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. - LOW (docs) —
tools/RELEASING.md:204-210still names onlyrestart.jsandmcp.jsas must-ship runtime files; the dev filed this as a handshake. Not touched (outside lane scope).
- LOW —
- Reviewed and clean: stale-search guard covers the failure path and
clear()(both bump/comparethis.request); every disposable is incontext.subscriptions;readLines/fileReadercannot reject (read errors caught), and theshowcommand's own rejections surface as VS Code's command-error toast; no workspace folder makesasRelativePathreturn the absolute path, which is fine; noopenTextDocument, so no didOpen flood. - Unverified (needs a real VS Code): the contributed keybinding beating the
built-in
shift+alt+f12;config.lucisv.references.fullLineViewresolving true by default (not just when set explicitly);.focusrevealing awhen-hidden view; highlight rendering; the context menu showing both the built-in and this entry. - Fixes made by QA: none.
- Suite:
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.