The owner's first-level cache, realized on the carrier the index already had: DeclLines (name line + detail line) on every Decl/Def, computed at index time from the LineIndex the analysis already holds — tens of KB for 20k modules, FACTS_FORMAT 3->4, old stores discarded whole. A closed file's hover heading now costs zero I/O (it survives the file being deleted), and the snippet's one remaining read is served from a bounded FileView LRU (4 entries / 8 MiB, newest kept, dropped on set_document/close/update_one/rebuild): repeat hovers into a 12 MB file go 5.8 ms -> ~1 us, cross-file hover means 40/157 us -> 4.7/12.9 us. Ports ride the same member entries, so their lines came free. Stale-disk edits leave heading and snippet stale together, the spells_exactly guard still omits rather than lies, and QA pinned the pair. Measured and filed, not fixed here: the first request of a session waits 287-780 ms behind the startup scan (handshake for the next round). Co-Authored-By: Claude Fable 5 <[email protected]>
453 lines
27 KiB
Markdown
453 lines
27 KiB
Markdown
# hover-declarations
|
|
|
|
## Goal
|
|
|
|
Hovering a name declared in **this** file has always shown the declaration
|
|
itself — `local_text` prints the kind, the name and the source lines
|
|
`decl_span` covers. Hovering a name declared in *another* file showed only
|
|
`**port** — declared in `sub.sv:3``: enough to navigate to, not enough to read.
|
|
The owner's ask (2026-08-27) is that the cross-file card carry the declaration
|
|
too — for a port its direction, type and width, `input logic [7:0] addr` — so
|
|
that reading a connection list does not require jumping out of the file. This
|
|
round adds a fenced `systemverilog` snippet of the declaration's source line(s)
|
|
under each candidate's existing heading, fetched at hover time and omitted
|
|
entirely whenever it could be the wrong line.
|
|
|
|
## Assumptions
|
|
|
|
- **The index stays text-free.** `Def` is `{file, name_span, kind}` and the
|
|
persisted facts and `FACTS_FORMAT` are untouched
|
|
(`docs/features/workspace-index/README.md`,
|
|
`docs/features/index-persistence/README.md`). A hover is a rare, one-name,
|
|
human-speed request; reading one file to answer it is the same trade
|
|
`locate::line_number` has always made for the `file:line` half of the card.
|
|
- **`reference.name` is the declared name.** Every `Definition::External`
|
|
answer comes from a reference (`ExternalResolutions::definition_of` looks the
|
|
target up by `ReferenceId`), and `resolve_external` finds the `Def` by
|
|
passing exactly that `name` to `WorkspaceIndex::units` / `member`. So the
|
|
name is the bare declared spelling — `WIDTH` for a `p::WIDTH` use, `clk` for
|
|
a `.clk(...)` connection — never a qualified path. That is what makes it
|
|
usable as the guard's expected text.
|
|
- **Disk text is what the index was built from.** `Workspace::text_of` prefers
|
|
an open buffer, which is right for a location and wrong for a snippet, so the
|
|
open case is handled separately and never reaches `text_of`.
|
|
- **A `decl_span` may be enormous.** A module's `decl_span` is its whole body
|
|
(`bind_module` passes the item span), and one netlist line has no bound at
|
|
all — hence the two caps below.
|
|
|
|
## Handshakes
|
|
|
|
**Consumed**
|
|
|
|
- `crate::nav::indexed_def_for_symbol` — raised from private to `pub(crate)`,
|
|
behaviour byte-for-byte unchanged. `nav.rs` walks it live-symbol → indexed
|
|
`Def`; this feature walks the same relation the other way (scan the open
|
|
buffer's symbols for the one that maps to this `Def`), which is precisely
|
|
what `nav.rs`'s own `include_declaration` block already does for the
|
|
declaration location. One matcher, so a hover snippet and a
|
|
go-to-definition can never disagree about which declaration is which.
|
|
- `Workspace::document_for_path`, `Workspace::text_of`, `WorkspaceIndex::path`.
|
|
- `crate::convert::Positions::whole_lines`, `vlog_parser::LineIndex`.
|
|
- `vlog_semantic::{Def, Symbol}` — read only; nothing added to either.
|
|
|
|
**Promised**
|
|
|
|
- `nav.rs` keeps its behaviour: the visibility change is the only edit to it,
|
|
and its whole test module stays green unmodified.
|
|
- The `` ```systemverilog `` fence tag is used for the new block, as the
|
|
fence-tag contract in `docs/features/lucisv-server/README.md` requires — it
|
|
is the only thing that colours a hover card.
|
|
- Nothing is added to `Def`, to the facts file, or to `FACTS_FORMAT`; a cache
|
|
written before this round is still current after it.
|
|
**Superseded 2026-08-28 by `docs/features/port-detail-spans/README.md`**,
|
|
which adds `Def::detail_span`, writes it in every declaration record and
|
|
bumps `FACTS_FORMAT` 2 → 3, so a store written before *that* round is
|
|
discarded. This round's own promise held while it was this round's to
|
|
make; the index is text-free either way (a span is not text).
|
|
**Superseded again 2026-08-28 by `docs/features/hover-line-index/README.md`**,
|
|
which adds `Def::lines` (each declaration's line number) and bumps
|
|
`FACTS_FORMAT` 3 → 4. Same reading: a line number is not text either, and
|
|
it is what makes this feature's heading free.
|
|
- The heading line `**label** — declared in `file:line`` is unchanged, so a
|
|
client (or a test) reading only that half sees exactly what it saw before.
|
|
|
|
## How the snippet is fetched
|
|
|
|
`declaration_snippet(ws, def, name)` in `hover.rs`, once per candidate:
|
|
|
|
1. **The target file is open** (`ws.document_for_path`). The index's span is
|
|
against that file's *last saved* text, so an unsaved edit above the
|
|
declaration has already moved it and reading the buffer at `def.name_span`
|
|
would print whatever those offsets now cover. Match the `Def` to a live
|
|
symbol **logically** instead — same name, and `indexed_def_for_symbol` maps
|
|
it back to this same `Def` — and widen that symbol's live `decl_span` to
|
|
whole lines.
|
|
2. **Not open**: `ws.text_of(path)` (disk, since no buffer backs it), a fresh
|
|
`LineIndex`, and `def.name_span` widened to whole lines.
|
|
3. **Guard, both paths.** Slice the chosen text at the chosen name span and
|
|
require it to equal the hovered name. `str::get` returns `None` for a span
|
|
that runs past the text or lands mid-character, so a stale or shifted span
|
|
fails the check rather than panicking. Any failure — unreadable file, no
|
|
live symbol, text that does not spell the name — drops the snippet and
|
|
leaves today's card exactly as it was. **A hover must never lie; less
|
|
information beats wrong information.**
|
|
|
|
Note the asymmetry, and that it is deliberate: the open path widens
|
|
`decl_span` (mirroring `local_text`, which is the only span a live symbol
|
|
offers that covers a whole multi-line declaration), the disk path widens
|
|
`def.name_span` (the only span the index holds). For the declarations the ask
|
|
is about — ports, parameters, typedefs, a module header — both are one line
|
|
and the two paths print the same thing.
|
|
|
|
## Cutting it down
|
|
|
|
`cut_to_size` trims trailing blank space (as `local_text` does; leading
|
|
indentation stays, so the line reads as written) and then applies two caps,
|
|
each with its own note under the fence:
|
|
|
|
| Cap | Value | Why |
|
|
|---|---|---|
|
|
| lines | `SNIPPET_LINES` = 5 | a module's `decl_span` is its whole body |
|
|
| characters | `SNIPPET_CHARS` = 400 | one netlist line can be megabytes |
|
|
|
|
A cut appends ` …` inside the fence and `*shown to N lines*` /
|
|
`*shown to N characters*` after it — the same shape as the macro card's
|
|
`*truncated at N characters*`, so the two footnotes read as one convention.
|
|
The character cap counts `char`s and cuts on a boundary.
|
|
|
|
## Status / TODO
|
|
|
|
- [x] `declaration_snippet` with the open-buffer and disk paths.
|
|
- [x] Guard on both paths; snippet omitted on any mismatch.
|
|
- [x] Line and character caps with a note.
|
|
- [x] One snippet per candidate for an ambiguous name.
|
|
- [x] `indexed_def_for_symbol` shared with `nav.rs`, behaviour unchanged.
|
|
- [x] Tests (9 new, in `hover.rs`'s own test module).
|
|
- [x] Hover row + hover section in `docs/features/lucisv-server/README.md`.
|
|
- [x] `cargo fmt` / `cargo clippy --all-targets` / `cargo test --workspace`.
|
|
- Not done, deliberately: no facts/cache change, nothing in `vlog_semantic`,
|
|
no TODO.md edit (no existing checklist item covers this; §8's hover items
|
|
are all already checked, and inventing one is out of scope).
|
|
- [x] **2026-08-28**: one disk read per file per hover (`disk_view` memo);
|
|
QA finding 4 closed.
|
|
- [x] **2026-08-28**: `live_symbol` (and `nav::indexed_references`) look a
|
|
name up instead of scanning every symbol, with the first-match
|
|
tie-break pinned by test.
|
|
- [x] **2026-08-28**: a CRLF file's snippet no longer carries an interior
|
|
`\r` into the fence; QA finding 2 closed.
|
|
- [x] **2026-08-28** (`docs/features/hover-line-index/README.md`): the disk
|
|
path's heading costs no read at all (`Def::lines`) and its snippet's
|
|
read is shared across hovers, so the second hover into a closed file is
|
|
free. `disk_view` is gone, subsumed by `Workspace::file_view`.
|
|
|
|
## Work log
|
|
|
|
### 2026-08-27 — dev
|
|
|
|
- Read the brief, `hover.rs`, `nav.rs`, `state.rs` and `convert.rs`. Confirmed
|
|
the two facts the design rests on: `set_document` does **not** rebuild the
|
|
index (so an open buffer really can hold a span the index does not know
|
|
about — the case step 1 exists for), and `follow_one` looks a `Def` up by
|
|
`reference.name`, which is what licenses using that name as the guard's
|
|
expected text rather than trying to recover a name from `Def`.
|
|
- Added `declaration_snippet`, `live_symbol`, `span_text`, `fenced` and
|
|
`cut_to_size` to `hover.rs`, plus the two caps as consts. `symbol_hover`'s
|
|
`External` arm now appends the snippet to each candidate's part; the heading
|
|
it appends to is untouched.
|
|
- Raised `nav::indexed_def_for_symbol` to `pub(crate)` with a doc line naming
|
|
the second caller. No other change to `nav.rs`.
|
|
- Decision: the open path uses `decl_span` and the disk path `name_span`,
|
|
per the brief. Considered using `name_span` on both for symmetry — it would
|
|
make a big module's card one header line rather than five — but that would
|
|
drop the live-buffer case's only handle on a multi-line declaration, and the
|
|
line cap already bounds the damage. Recorded in *How the snippet is fetched*
|
|
so the asymmetry is a decision and not an accident.
|
|
- Decision: no fallback from the open path to disk text. If a file is open and
|
|
no live symbol matches, the buffer has been edited past the index and the
|
|
indexed span is exactly the thing that cannot be trusted; falling back would
|
|
re-introduce the wrong-line risk the guard exists to remove.
|
|
- Nine tests added (listed below). Ran the gates: fmt
|
|
clean, clippy `--all-targets` clean, `cargo test --workspace` green at 2372
|
|
passed / 0 failed / 12 ignored.
|
|
|
|
**Tests added** (all in `crates/lucisv_server/src/hover.rs`, `mod tests`):
|
|
|
|
| Test | Pins |
|
|
|---|---|
|
|
| `a_cross_file_port_connection_shows_the_ports_own_declaration_line` | the ask: direction + type + width, and only that port's line |
|
|
| `a_cross_file_module_instance_shows_its_header_line` | the module header, disk path |
|
|
| `a_package_member_shows_its_declaration_line` | a `localparam` and a `typedef` through `import p::*` |
|
|
| `an_unsaved_edit_that_moved_the_declaration_is_read_at_its_live_span` | live line, not the stale-span line (asserts the *new* width and the absence of the old) |
|
|
| `a_stale_indexed_span_drops_the_snippet_rather_than_showing_the_wrong_line` | guard, disk half: file rewritten under a live index → no fence at all, heading intact |
|
|
| `an_open_buffer_that_no_longer_declares_the_name_drops_the_snippet` | guard, live half: the port renamed away in the buffer |
|
|
| `a_very_long_declaration_line_is_cut_with_a_note` | the character cap and its note |
|
|
| `a_declaration_spanning_many_lines_is_cut_at_the_line_limit` | the line cap, via an open module whose `decl_span` is its body |
|
|
| `two_files_declaring_one_name_each_get_their_own_snippet` | ambiguous name: both headings, both snippets |
|
|
|
|
### 2026-08-28 — dev (performance: one disk read, one name lookup)
|
|
|
|
Parts A2 and A3 of the "Improve LSP performance + hover accuracy" round.
|
|
Behavior of every card is unchanged; both items are the same answer, reached
|
|
with less work. Numbers in `docs/perf/README.md`.
|
|
|
|
- **A2 — one read per file per hover.** A hover into a *closed* file used to
|
|
read that file and build a `LineIndex` over it twice: once in
|
|
`locate::line_number` for the `file:line` heading, once in
|
|
`declaration_snippet` for the fenced lines. This is QA's finding 4 below,
|
|
and it is now closed. `symbol_hover` holds a per-request memo — one
|
|
`(path, text, LineIndex)` in `disk_view` — that the heading and the snippet
|
|
both read, and `declaration_snippet` no longer touches the disk at all: it
|
|
is now the *open-buffer* path only, with the closed-file path inlined in
|
|
`symbol_hover` beside the heading it shares a read with. The
|
|
`spells_exactly` guard applies on both paths exactly as before. A card
|
|
naming one file twice (two declarations in one file) now pays for one read,
|
|
not two, which is why the memo is keyed by path rather than being a single
|
|
`Option` per candidate.
|
|
- Measured: 34 ms → 16.3 ms on QA's own 31.7 MB measurement, and 141 µs of
|
|
a 148 µs hover at 10 000 lines is that one read. See `docs/perf`.
|
|
- QA's measurement test was renamed
|
|
`hovering_into_a_large_closed_file_reads_it_twice` →
|
|
`..._reads_it_once`, since the doubling it was named for is gone. The QA
|
|
log below still names the old spelling; that section is QA's to amend.
|
|
- **A3 — `live_symbol` stops scanning every symbol.** Walking the whole
|
|
buffer's symbol table and calling `nav::indexed_def_for_symbol` (two index
|
|
lookups) on every symbol whose name happened to match — and reaching every
|
|
symbol whose name did not — became a name-keyed lookup:
|
|
`vlog_semantic::Semantics::symbols_named(name)`, two binary searches over a
|
|
side table of symbol ids sorted by name, built once during `analyze`. Only
|
|
same-named declarations are probed. A side table rather than a
|
|
`HashMap<String, Vec<SymbolId>>` so that `Semantics` — which is cloned per
|
|
document — does not carry a second copy of every name it already holds;
|
|
four bytes per symbol against a `String` per symbol.
|
|
- **The tie-break is preserved.** The map's lists are built by walking the
|
|
symbols in order, so `symbols_named` yields declaration order — the same
|
|
order, and the same first match, the old `symbols().iter().find(..)`
|
|
made. Pinned by `looking_a_name_up_answers_exactly_what_scanning_every_symbol_would`
|
|
in `crates/vlog_semantic/tests/semantics.rs`, which compares the two
|
|
answers directly and asserts the earlier declaration comes first. QA's
|
|
`duplicate_live_declarations_of_one_name_pick_the_first_one_silently`
|
|
(finding 3 below) still passes, unchanged.
|
|
- `nav.rs`'s `indexed_references` had the same scan-by-name for the
|
|
declaration's live span; it is the same swap and was made in the same
|
|
change, for the same reason.
|
|
- `vlog_refactor::ports.rs:1154` has a third one (`symbols().iter()
|
|
.position(|s| s.name == port && …)`). It is not a trivial swap — the
|
|
predicate carries a kind and a span test and the code wants the
|
|
*position* as a `SymbolId` — and it is in another crate, so it is left
|
|
alone and recorded here rather than done.
|
|
- Cost: four bytes per symbol. Measured saving on the lookup alone:
|
|
8.41 µs → 133 ns over a 5 001-symbol file (`docs/perf/README.md`).
|
|
|
|
### 2026-08-28 — dev (the heading stops reading the file at all)
|
|
|
|
Round `hover-line-index` — full argument, measurements and tests in
|
|
`docs/features/hover-line-index/README.md`. What changed *here*:
|
|
|
|
- **The `External` arm's disk branch no longer reads anything for the
|
|
heading.** `Def` now carries `lines: DeclLines`, recorded when the file was
|
|
indexed, so `**port** — declared in `sub.sv:2`` is a field lookup. The live
|
|
branch is untouched and still asks the open buffer's own line index, because
|
|
that buffer may hold unsaved edits the index has not seen — the same reason
|
|
`declaration_snippet` matches a `Def` to a live symbol logically.
|
|
- **`disk_view` was deleted.** Its job — one read per file per hover — is now
|
|
`Workspace::file_view`'s, which does it once per file per *generation of that
|
|
file*, so the next hover into the same file reads nothing. The four points
|
|
that drop a held view are listed in that round's Handshakes.
|
|
- **`spells_exactly` and both caps are untouched**, and a stale held view can
|
|
only ever make a snippet vanish. Every existing test in this file passed
|
|
unmodified.
|
|
- **One corner moved deliberately**: a closed file that cannot be *read* now
|
|
still gets its line in the heading (`sub.sv:2` rather than a bare `sub.sv`),
|
|
because the line no longer depends on the read. Pinned by
|
|
`a_closed_files_heading_line_comes_from_the_index_and_not_from_a_read`.
|
|
- Measured: a hover into a 12 MB closed file, 6.2 ms → **0.95 µs** on the
|
|
second hover; the 31.7 MB probe above, 17.0 ms → **4.4 µs** on the second.
|
|
The first touch is unchanged, because the snippet genuinely wants the text.
|
|
|
|
### 2026-08-28 — dev (CRLF, closing QA finding 2)
|
|
|
|
- Finding 2 below — a CRLF file's multi-line snippet keeping an interior
|
|
`\r` inside the fence — is **fixed**, as part of `port-detail-spans`' PDS-4.
|
|
Every line a card shows now goes through `attached_lines`, which strips a
|
|
trailing `\r` as it composes each line; that covers both this feature's
|
|
snippet path and `local_text`'s in-file path, which QA named as having the
|
|
same property, because both reach it through `fenced_sections`. Display
|
|
text only: no buffer is written.
|
|
- QA's pinned regression test was named for the old behaviour
|
|
(`a_crlf_multiline_snippet_keeps_interior_carriage_returns`) and asserted
|
|
it; it is now `a_crlf_multiline_snippet_carries_no_carriage_returns` and
|
|
asserts the opposite, plus that the lines read as written. The QA log below
|
|
still names the old spelling; that section is QA's to amend.
|
|
- No other change to this feature. `spells_exactly`, the caps and the
|
|
disk/live split are untouched.
|
|
|
|
## QA log
|
|
|
|
### 2026-08-27 — QA
|
|
|
|
Read the brief, the dev's Work log, and `crates/lucisv_server/src/hover.rs` /
|
|
`nav.rs` in full. Ran the gates first (all green before any probing): `cargo
|
|
fmt --check` clean, `cargo clippy --all-targets --workspace -- -D warnings`
|
|
clean, `cargo test --workspace` green — 1173 passed / 0 failed / 12 ignored
|
|
(pre-existing) before this round's own probes were added.
|
|
|
|
Then attacked `declaration_snippet`, `live_symbol`, `span_text` and
|
|
`cut_to_size` along the seven angles in the charter. Eight probe tests added
|
|
to a new `mod qa_hover_declarations` in `hover.rs` (one `#[ignore]`d perf
|
|
measurement); one real defect found and fixed with a ninth test pinning it.
|
|
|
|
**Finding 1 — MEDIUM, fixed.** *The guard was a fixed-length substring check,
|
|
not a whole-identifier check, so an edit that only **extends** a name defeats
|
|
it.* `declaration_snippet`'s guard (`hover.rs:243` and `:252`, before the fix)
|
|
compared `span_text(text, span)` — a slice of exactly `name.len()` bytes at
|
|
the *old, recorded* offset — against `name`. `def.name_span`'s length is
|
|
whatever the name was when the index was last built; it does not grow if the
|
|
file is edited without a reindex. So: index built on `input logic [7:0]
|
|
addr;`, then the file is rewritten on disk to `input logic [7:0] addr2;`
|
|
*without* triggering a reindex (an ordinary edit-then-hover-before-save-event
|
|
race, exactly the staleness window this feature's guard exists for). The old
|
|
span still covers exactly the four bytes `"addr"` — a *prefix* of the new
|
|
`"addr2"` — so `span_text` returns `Some("addr")`, equals the hovered name,
|
|
and the guard passed. The card for `.addr(...)` then showed
|
|
`` input logic [7:0] addr2 `` under a heading that says `addr`'s declaration,
|
|
one line pretending to be a name it is not — exactly the masked-corruption
|
|
shape CLAUDE.md's invariant 4 is about, applied to this round's new safety
|
|
net rather than `verify.rs`.
|
|
- Repro (was a failing/panicking assertion, now a passing regression test):
|
|
`a_disk_edit_that_only_appends_to_the_name_defeats_the_guard`,
|
|
`hover.rs:1060`.
|
|
- Fix: added `spells_exactly` (`hover.rs:293`) and `continues_a_name`
|
|
(`hover.rs:306`), and switched both guard call sites
|
|
(`declaration_snippet`'s live and disk branches) to it. It keeps the
|
|
existing text-equality check and additionally requires that the
|
|
character immediately outside the span on either side (if any) is not an
|
|
identifier-continuation character (`[A-Za-z0-9_$]`) — turning a
|
|
prefix/suffix match back into a miss. Applied to *both* branches for one
|
|
guard, one guarantee, even though the live branch's `symbol.name_span`
|
|
(a token span from a fresh parse) could not actually suffer this —
|
|
`symbol.name == name` was already checked before the span comparison, so
|
|
the length always matched there. No behavior change for any span that is
|
|
a genuine whole identifier, which is every case the dev's 9 tests and the
|
|
existing corpus tests exercise — full `cargo test --workspace` stayed
|
|
green (1173 passed / 0 failed / 13 ignored, the 13th being this round's
|
|
own perf probe) after the fix.
|
|
- This does **not** close every staleness gap by design — a same-length
|
|
edit that changes an identifier into a different same-length identifier,
|
|
or that changes what a name's *kind* means without renaming it, is still
|
|
the accepted risk window the Assumptions section already names ("a hover
|
|
is a rare, one-name, human-speed request"). What the fix removes is
|
|
specifically the case where the *shown text visibly disagrees with the
|
|
name in the heading* — the one the guard's stated promise ("never show a
|
|
wrong line") is about.
|
|
|
|
**Finding 2 — LOW, filed, not fixed.** *A CRLF file's multi-line snippet
|
|
keeps the embedded `\r` on every interior line, only the last one is
|
|
trimmed.* `cut_to_size` (`hover.rs`, unchanged by QA) calls `trim_end()` once
|
|
on the whole cut string, which strips a *trailing* `\r` (and `\n`) but not an
|
|
interior one before a kept newline. `local_text` (the in-file branch,
|
|
pre-existing, not part of this round) has the identical property via the same
|
|
`whole_lines`/`trim_end` shape, so this is not new behavior introduced by
|
|
this feature, just newly reachable from a second call site. Cosmetic, not a
|
|
correctness break: the bytes shown are exactly the file's own bytes, and a
|
|
fenced code block renders them close to verbatim either way. Pinned as a
|
|
permanent regression test rather than fixed, since a real fix (stripping
|
|
`\r` before every kept `\n`, in both `local_text` and here) is a
|
|
cross-cutting change to shared rendering, out of this round's stated scope
|
|
(`hover.rs`'s `External` arm and its shared helper with `nav.rs`).
|
|
- Repro: `a_crlf_multiline_snippet_keeps_interior_carriage_returns`,
|
|
`hover.rs:1156`.
|
|
|
|
**Finding 3 — LOW/accepted, pinned as a regression test, not a defect of this
|
|
round.** *Two live declarations of the same name+kind in one open buffer (a
|
|
transient mid-edit state, e.g. a duplicate line not yet deleted) make
|
|
`live_symbol`'s `.find()` pick whichever comes first in `Semantics::symbols()`
|
|
order, silently.* `indexed_def_for_symbol` (`nav.rs:164`, visibility-only
|
|
change this round) maps *any* live symbol with a matching name/kind/owner
|
|
back to the single persisted `Def` for that name when the index itself has
|
|
only one — it does not know or care that the *live* buffer momentarily has
|
|
two. This is inherited, unchanged behavior from `nav.rs`'s existing
|
|
go-to-definition matcher (the Handshakes section calls this out on purpose:
|
|
"one matcher, so a hover snippet and a go-to-definition can never disagree").
|
|
Not a lie in the sense the guard is about — the guard still requires the
|
|
*chosen* symbol's own span to spell the name exactly, which it always does
|
|
here by construction — but it is a silent, unsignaled choice between two
|
|
candidates. Filed rather than fixed: fixing it means changing
|
|
`indexed_def_for_symbol`'s matching rule, which is nav.rs's and explicitly
|
|
out of this round's scope ("nav tests must stay green," brief line 27).
|
|
- Repro: `duplicate_live_declarations_of_one_name_pick_the_first_one_silently`,
|
|
`hover.rs:1126`.
|
|
|
|
**Finding 4 — perf note, not a defect, no action taken.** *A hover resolving
|
|
into a large closed file reads the file and builds a `LineIndex` over it
|
|
twice*: once inside `locate::line_number` (for the `file:line` heading — this
|
|
predates this round) and again inside `declaration_snippet` (for the
|
|
snippet — new this round), independently, from the same disk path. Measured
|
|
in release mode: a 31.7 MB synthetic file (600k filler lines behind a small
|
|
port declaration, `maxFileSize` raised so it indexes at all) took 34 ms for
|
|
one hover — acceptable for a rare, single-shot request, but a real, avoidable
|
|
doubling of I/O and linear scan work per disk-path candidate. A fix would
|
|
mean threading one read/`LineIndex` through both `line_number` and
|
|
`declaration_snippet`, which touches `locate.rs` (also used by `macro_hover`)
|
|
and is a small refactor rather than a one-line change — noted per the
|
|
charter's "note it, don't redesign" rather than attempted.
|
|
- Measurement, `#[ignore]`d (writes ~30 MB, not a correctness assertion):
|
|
`hovering_into_a_large_closed_file_reads_it_twice`, `hover.rs:1325`. Run
|
|
with `cargo test --release -p lucisv_server large_closed -- --ignored
|
|
--nocapture`.
|
|
- **Amended 2026-08-28 — QA.** Closed by A2 (`docs/perf/README.md`):
|
|
`symbol_hover`'s `disk_view` memo now shares one read + one `LineIndex`
|
|
between the heading and the snippet. Re-ran the same measurement (now
|
|
named `..._reads_it_once`): **17.0 ms**, against the documented
|
|
"34 ms → 16.3 ms" — matches within the run-to-run noise `docs/perf/
|
|
README.md` itself calls out. No longer an open finding.
|
|
|
|
**Verified, no finding** (angles from the charter that turned up nothing):
|
|
UTF-8 multi-byte content before a declaration, on the same file, does not
|
|
panic `span_text`/`whole_lines` (`multibyte_utf8_before_the_declaration_does_not_panic`,
|
|
`hover.rs`) — both are `.get()`-based and this stayed a belt-and-braces pin.
|
|
A declaration at byte offset 0 and a declaration on the file's last line with
|
|
no trailing newline both render correctly, no underflow
|
|
(`a_declaration_at_the_very_start_of_the_file_is_shown`,
|
|
`a_declaration_on_the_last_line_with_no_trailing_newline_is_shown`). The line
|
|
cap (`SNIPPET_LINES` = 5) and character cap (`SNIPPET_CHARS` = 400) are both
|
|
exact-boundary-safe — 5 lines / 400 chars is not cut, 6 lines / 401 chars is,
|
|
and a 400-char boundary landing mid multi-byte character is not split because
|
|
`cut_to_size` counts with `char_indices`, never raw bytes
|
|
(`exactly_the_line_cap_is_not_cut_one_more_is`,
|
|
`exactly_the_char_cap_is_not_cut_one_more_is_and_boundary_is_safe`). A
|
|
case-mismatched open buffer (same file, different-case path on a
|
|
case-insensitive filesystem) is not recognized as "the target file open" by
|
|
`document_for_path`'s exact `PathBuf` equality, so it falls back to the disk
|
|
path rather than mixing the two identities — the safe direction, confirmed
|
|
with unsaved edits in the mismatched buffer never leaking into the card
|
|
(`a_case_mismatched_open_buffer_is_not_recognized_as_the_target_falls_back_to_disk`,
|
|
macOS/Windows-gated). Multiple ambiguous candidates each render from their
|
|
own file with no cross-contamination — the dev's own
|
|
`two_files_declaring_one_name_each_get_their_own_snippet` already covers
|
|
this and reads fine without a divider between candidates (each fenced block
|
|
is its own visual unit).
|
|
|
|
**Gates, final.** `cargo fmt --check` clean. `cargo clippy --all-targets
|
|
--workspace -- -D warnings` clean. `cargo test --workspace`: 1173 passed / 0
|
|
failed / 13 ignored (12 pre-existing + this round's one perf probe).
|
|
|
|
## Review
|
|
|
|
**2026-08-27 — lead.** Reviewed the full diff after QA's SHIP verdict;
|
|
gates re-run independently (fmt clean, clippy silent, 1173 server tests
|
|
green). The shape is right: no widening of persisted facts, snippets
|
|
fetched at hover time from whichever text the span is valid against
|
|
(live logical match through `nav.rs`'s one matcher, disk otherwise),
|
|
and a guard that prefers no snippet to a wrong one. QA's MEDIUM find —
|
|
the fixed-length substring guard passing on a name that had merely been
|
|
*extended* in place — is precisely the masked-corruption shape
|
|
invariant 4 exists for, applied correctly to a new forgiveness path
|
|
outside `verify.rs`; the `spells_exactly` boundary check closes it on
|
|
both the live and disk paths and the attack test pins it. The
|
|
deliberate asymmetry (live path shows `decl_span`, disk path the name's
|
|
line) is documented and bounded by the caps; the duplicate-live-symbol
|
|
tie-break is inherited from the shared matcher and correctly pinned
|
|
rather than re-designed. The CRLF interior-`\r` cosmetic and the
|
|
double-read of large closed files are accepted as filed. Accepted;
|
|
committed by the lead.
|