Three new feature READMEs — change-debounce, port-detail-spans, interactive-latency — each with the mandated sections, dev work logs, QA findings and their dispositions, and the lead's review. Plus `docs/perf/README.md`, the record of what was measured, on what, on which machine, and with which command, so a later round can say whether it made something faster or only different. `topo.md` is added to the tree: the dependency topology the round was planned against, with this round's new edges — the `detail_span` and `symbols_named` handshake between the server and `vlog_semantic`, and the facts-format edge to index persistence. The perf record keeps its losses as well as its wins. A keystroke followed by nothing now publishes at 164 ms rather than one reanalysis, because it waits out the quiet period; a perf document that only records improvements is not a perf document. Co-Authored-By: Claude Opus 5 <[email protected]>
27 KiB
port-detail-spans
Goal
A non-ANSI port is declared in two places: the header names it (data_in,)
and a body declaration finishes it (input signed [31:0] data_in;). Every
fact a reader wants — direction, signedness, width — is in the second place,
and until this round hover and go-to-definition both pointed only at the
first, so hovering a port of an older-style module showed a bare name and a
comma. vlog_semantic now records, on the header symbol, the span of the body
declaration that completes it (Symbol::detail_span); the server shows both
in one hover card and offers both as definition locations, detail first. The
same field travels through the workspace index and its on-disk facts, so a
cross-file hover into a closed file gets the same two sections. Attached to
that, because a card that shows a declaration should show what the author
wrote about it: each section carries the comment that documents it.
Assumptions
- One name, one symbol, per scope.
bind::declarealready turns a second declaration of a name into a reference to the first, which is exactly how a non-ANSI body declaration attaches to its header port.detail_spanrides on that existing mechanism; nothing new decides what "the same port" means. - First writer wins. If a header somehow names a port twice, the first body declaration to arrive records its span and later ones are ignored. The result is deterministic, which is what matters here; a duplicated port is the linter's complaint to make, not hover's.
detail_spanisNonefor everything else. An ANSI port, a wire, a module — anything complete where it is named — has no detail site, and both consumers render exactly the card they always did.- A real span is never empty, so
(0, 0)is free to meanNonein the facts codec.bind_port_declonly ever records a declaration's own span. - Comment attachment is textual, and errs towards attaching nothing. The
disk path of a cross-file hover has no parse to ask, so the attachment rules
work on lines. Only
//lines and single-line/* … */count as comment-only; the interior of a multi-line block comment is indistinguishable from code without lexing, and a hover card that guessed would be the wrong-line lie the snippet guards exist to prevent. - A comment below a declaration belongs to the next declaration unless
nothing else could claim it.
only_a_closer_onanswers that with a whitelist, not a blacklist: the block attaches only when every word on the line after it is a block terminator (end,endmodule,endinterface,endtask,endfunction) — which includes a line with no words at all ();, a blank line, punctuation) — or when there is no line after it at all. Everything else, a bareinputon the first line of a wrapped declaration included, reads as another declaration. The bias is the whole point: a false "another declaration is here" only ever declines to attach a comment, the direction that cannot lie, while a false "nothing here" shows one declaration's comment on another's card. (QA, PDS-1: the previous keyword-blacklist form got that backwards and did lie.) - The three comment sources are independent, as the owner's rule states them: a declaration takes the comment on its own line and the block above it and the block below it, each guarded on its own. Order is source order. (QA, PDS-2: the first implementation ran them as a priority chain and dropped a below-comment nothing else claimed.)
- Comment attachment renders, it never rewrites. A CRLF file's line ends
before its
\nbut after its\r, soattached_linesstrips that\ras it composes each line — display text only; no buffer is touched (QA, PDS-4).
Handshakes
vlog_semantic::Symbolgains a field —detail_span: Option<TextRange>. Additive, likerefactor-rename'sTarget::Declarationbefore it (§2.6 oftopo.md): every existing reader ofSymbolcompiles and behaves identically, and the two struct literals that build aSymbol(bind.rs) set it.bind_port_declis where it is written.vlog_semantic::Defgains the same field, carried by the index's internalDecl.Defis whatlucisv_servernavigates by, so this is the wire that makes a cross-file hover show the body declaration.DefderivesPartialEq; twoDefs that differ only indetail_spancannot arise, because both come from the sameDecl.facts.rs's on-disk format changes — every declaration record now carries two more numbers, written unconditionally (0 0for theNonethat every ordinary declaration has) so the stream stays flat and the reader stays a straight sequence ofnum()s.FACTS_FORMATis bumped (2 → 3), so a store written by an earlier build is discarded whole:index_cache.rs's header line carries the number, and a header that is not this build's means the file is not read at all. Without the bump an old record would be reinterpreted — every field after a declaration's name span shifted by two — rather than dropped, and only the reader'sdone()check would stand between a shifted parse and a wrong answer. Dropping the store costs one rescan, once, which is what the persistent index is for (docs/features/index-persistence/README.md); it is thevlog_semantic/src/workspace.rschoke-point rule intopo.md§3.3.nav.rsandhover.rsagree, by construction. Hover shows two sections — header, then detail — andnav::definitionreturns two locations in the same order, detail first, so "jump" lands where the card's second block is and the card's first block is the second location. Both readsymbol.detail_span; there is no second rule for what a port's declaration is. An empty detail span is filtered out innav.rsrather than trusted.- Consumes
hover-declarations' guards unchanged.spells_exactlystill gates every snippet read out of a file the index may be stale against;fenced_sectionsis applied after that guard on the disk path, and afterlive_symbolon the live path.
Status / TODO
Symbol::detail_span, written bybind_port_decl, first writer wins — for a module's non-ANSI port and for an old-style task/function argument, which merge through the samebind::declare.Def::detail_span+ the index'sDeclcarrying it.facts.rscodec: unconditional pair,(0,0)=None,FACTS_FORMATbumped so a stale store is not read as a fresh one.hover::fenced_sections— one section, or header + detail.nav::definitionreturns the detail location first.- Comment attachment (
attached_lines): same-line, above and below, each guarded on its own, all three at once where all three are written. - Tests:
vlog_semanticrecords the span for a split port and not for an ANSI one; hover shows two sections from either end of the port; comments attach above, below, and are not stolen from the next port; a cross-file split port shows both sections from the index. - 2026-08-28: the below-comment guard is a closer whitelist, so a wrapped next declaration keeps its own leading comment (QA, PDS-1).
- 2026-08-28: above / beside / below are independent (QA, PDS-2).
- 2026-08-28: an old-style task or function argument gets a
detail_spantoo (QA, PDS-3). - 2026-08-28: a CRLF file's snippet carries no
\rinto the fence (QA, PDS-4). - Not done:
detail_spanfor anything other than a port or a task/function argument. Anexternmethod prototype and its out-of-body definition are the same two-places-one-symbol shape and would fit the field exactly, but no hover complaint has been filed about them and speculative generality is whatCLAUDE.mdsays not to build. - Not done: a doc-comment model. The attachment above is positional and
deliberately dumb — no
///convention, no markdown rendering of the comment body, no stripping of//. That is a feature of its own if it is ever wanted.
Work log
2026-08-28 — dev. Implemented as part of the LSP performance round (plan: "Improve LSP performance + hover accuracy", part B), continued by a second dev after the first stopped mid-round; the code below is the first dev's except where noted.
bind_port_decllooks the declarator's name up in the scope it is binding into beforebind_declaratorsruns, becausedeclarewill turn the name into a reference and there would be no symbol id to write on afterwards. The lookup is the scope's ownnamesmap — the same mapdeclareconsults — so "the same port" is decided in exactly one place.- The codec writes the pair unconditionally rather than with a presence flag. A flag would have kept old records readable at the cost of a branch in the hot reader and a second thing to get wrong; dropping a stale record costs one reparse of that file, once.
- Comment attachment was not in the plan. It is here because the first card the two-section change produced looked wrong without it: a port's comment sits on the line above or beside it, and showing the declaration without it loses the only prose the author wrote. The rules are the narrowest ones that never steal another declaration's comment, and each has a test.
- Second dev, 2026-08-28: bumped
FACTS_FORMAT2 → 3, which the first dev's change owed and did not take. Its comment argued that a pre-field record is "one field short, failsdone(), and is dropped" — true for the last declaration in a record, but a record with a declaration followed by anything else is not short, it is shifted, and relying on a trailing-length check to catch a field-order change is exactly what the format number exists to make unnecessary. The workspaceVERSIONis also in the store's header, but it has not moved this round, so without the bump a store written by the released 0.12.1 would have been read by the new codec. Otherwise no behavioral change: this README is the documentation the round owed, andcargo fmtwas run overhover.rs.
2026-08-28 — dev (QA fixes, third dev). Every finding in the QA log below is addressed; each is marked fixed or left, with the reason.
- PDS-1 — fixed.
another_port_on/is_port_grammar_wordare gone, replaced byonly_a_closer_on/is_closer_word(hover.rs). The old predicate asked "does this line carry an identifier the port grammar cannot account for?", which is a blacklist: a line that is only keywords — the first line of a wrappedinput\n [7:0] result;— answered "no other port here" and handedresult's comment todata_in. The new one asks the question the other way round: every word on the line must be a block terminator, so a line with any word the whitelist does not name (a bareinputincluded) reads as another declaration and the comment stays put. A line with no words at all —);, blank, punctuation — passes, which is what a last port's trailing comment is really followed by, and so does the end of the file, where there is no line left to claim anything. The doc comment now states that bias and why only that direction is safe.namefell out of the predicate, and with it out ofattached_linesandfenced_sections— the guard no longer needs to know which port it is guarding, only whether anything follows the comment. Three call sites simplified; no behaviour rides on the removal.- Pinned:
a_wrapped_next_declaration_keeps_its_own_leading_comment(the QA repro verbatim, plus the assertion that the comment does reachresult's own card) anda_wrapped_declaration_keeps_the_comment_below_it(the same wrapped shape as the last declaration still takes it). The existinga_comments_below_a_declaration_attach_only_when_no_port_follows_them— comment block aboveendmodule— still passes unchanged.
- PDS-2 — fixed.
attached_linesno longer runs a priority chain: the above walk, the declaration's own lines (which carry the same-line comment inherently) and the below walk are three independent collections joined in source order.has_comment_afterwas the chain's only reader and is deleted. Each guard is exactly as strict as before — the above walk still stops at the first line that is not comment-only, and the below guard got stricter with PDS-1 — so nothing new can be stolen; what changes is only that a below-comment nothing else claims is no longer silently dropped because something was also written above.- Pinned:
a_declaration_shows_the_comments_above_beside_and_below_it_at_once(all three on one body declaration) anda_header_port_shows_the_comments_above_and_below_it_at_once, which is QA's repro 1 and repro 2 in one header — with the negative half (the same block is left alone when another port follows it) in the same test.
- Pinned:
- PDS-3 — fixed, not documented as a gap. Checked the binder first, as
the brief asked:
bind_tf_argsdeclarestask t(a);'saas aTfArgin the task's own scope, andinput [7:0] a;at statement position reachesbind_port_declwith that same scope, sodeclareturns it into a reference to the header symbol — the identical header→body merge a module port gets, one symbol and not two (verified by probe before changing anything). So the recording is extended rather than parked: thekind == SymbolKind::Portgate is gone and the inner test issymbol.kind == kind, which is the same condition for a port and now also holds for an argument. Pinned invlog_semantic(an_old_style_task_argument_records_its_body_declaration_too, including that an ANSI-style argument still has none) and in hover (an_old_style_task_argument_hovers_as_two_sections_too). - PDS-4 — fixed.
attached_lines's line reader strips a trailing\rfrom every line it composes, so a CRLF file's fenced block is\n-joined like any other. It is done there, at the one place all three collections (above, declaration, below) pass through, rather than incut_to_size, which would have had to re-split the joined string. Display text only — nothing writes to the buffer. QA's pinned testa_crlf_multiline_snippet_keeps_interior_carriage_returnswas the regression test for the old behaviour; it is nowa_crlf_multiline_snippet_carries_no_carriage_returns, asserting no\rsurvives and that the lines read as written. (Editing a QA-authored test rather than deleting it: the finding it pins is the one being closed, and the same file'slocal_textpath goes through the same helper, so it covers both branches QA named.)
QA log
2026-08-28 — QA. Verified against the owner's own spec ("two sections
… same line, or above it (if no other port on the line above), or below it
(if no other port on the line below)"), and attacked with the shapes named in
the QA brief. Gates green (see change-debounce's QA log for the shared run).
All reproductions used temporary #[test]s in hover.rs, run once, and
removed after confirming — none are left in the tree, except the one noted
below as a kept, permanent regression test.
-
Finding PDS-1 (high — a wrong comment shown, the one invariant this feature explicitly promises never to violate).
another_port_on(hover.rs:355) — the guard that decides whether a below-comment block belongs to this declaration or the next one — inspects only the single line immediately following the comment block. When the next port's own declaration wraps, with its direction keyword alone on the first line and its name on a later line, every word on that first line is inis_port_grammar_word's list (hover.rs:368, which includes bareinput/output/etc.), soanother_port_onreturnsfalse— "no other port here" — and the comment attaches to the wrong declaration.- Repro:
Hovering
module alu (data_in, result); input [7:0] data_in; // about result input [7:0] result; endmoduledata_inshows a detail section readinginput [7:0] data_in;\n// about result—result's own leading comment, attached todata_in's card. Confirmed live (temporary test asserting the comment is not present failed with exactly this text). - This is precisely the failure mode
docs/features/port-detail-spans/ README.md's own Assumptions section rules out: "a false 'yes' only ever declines to attach a comment — the direction that cannot lie." Here a false no (failing to recognizeresult's declaration as a port) makes it lie. Left unfixed — not small/unambiguous; the honest fix wantsanother_port_on(or its caller) to look past a line that is entirely grammar words with no other identifier, to the line(s) after it, which is a real design change to a predicate three call sites and several tests depend on.
- Repro:
-
Finding PDS-2 (medium — divergence from the stated spec, not corruption; the one the QA brief asked to check explicitly). The owner's rule reads as three independently-checked sources (same line, above, below). The implementation instead runs a strict priority chain in
attached_lines(hover.rs:297): below-comment collection is skipped entirely whenever there is any above-comment, or any same-line trailing comment (hover.rs:313,if above.is_empty() && !decl.last()...has_comment_after) — even when the below comment is otherwise unclaimed by anything else (no other port follows it).- Repro 1 (above blocks below):
Header section shows
module alu ( // above data_in // below ); input [7:0] data_in; endmodule// above+data_inonly;// belowis silently dropped, though nothing else claims it (the next line is);). - Repro 2 (same-line trailing comment blocks below):
Header section shows
module alu ( data_in // right here // below ); input [7:0] data_in; endmoduledata_in // right hereonly;// belowdropped. - Not unsafe (never shows the wrong comment — just fewer than the literal spec asks for), so lower severity than PDS-1, but a real, reproducible divergence. Left unfixed — a design call (should a declaration ever show two attached comments at once?) belongs to the dev/lead, not QA.
- Repro 1 (above blocks below):
-
Finding PDS-3 (low — silent feature-completeness gap, not a bug).
bind_port_decl'sdetail_span-recording branch is gated onkind == SymbolKind::Port(bind.rs:512), which excludesSymbolKind::TfArg— old-style (non-ANSI) task/function port declarations (task t(a);\n input a;\n ...\nendtask) never get adetail_span, even though they are exactly the same two-places-one-symbol shape a module's non-ANSI port is, andbind_port_declis already reached at statement position for them (bind.rs:1030,StmtKind::PortDecl). The feature's own "Not done" list names only extern method prototypes as the deliberately parked case; task/function old-style ports are a second, unmentioned one. Falls back to the single-section card exactly as before this round — no regression, just an undocumented gap, worth a line in Status/TODO if the dev wants it. -
Finding PDS-4 (low/cosmetic — pre-existing, amplified by this round, not introduced by it). On a CRLF file, a multi-line fenced snippet embeds a raw
\rbyte in the middle of the code fence for every joined line except the last (whose trailing\rhappens to be stripped becausecut_to_size'strim_end()only trims the very end of the whole joined string, not each line). This is pre-existing behavior ofPositions::whole_lines/cut_to_size—local_textalready had the same characteristic for any multi-linedecl_spanbefore this round — but comment attachment now makes multi-line snippets routine (any port with a nearby comment, not just a rare multi-line declaration), so the gap is hit far more often in practice. Repro: a CRLF split-port module with an above-comment; the header section's rendered text contains a literal\rbetween the comment line and the declaration line. Cosmetic only (a stray control character, not wrong text); not fixed, flagged for whoever touchescut_to_sizenext. -
Attack angles checked and clean (no finding):
- A port declared twice — first-writer-wins confirmed: the second body
declaration's comment (
// second (duplicate...)) never appears; only the first's (// first) does, matchingbind_port_decl's documented policy. - ANSI mixed with non-ANSI in one header — a full ANSI port (
input wire clk,) and a split non-ANSI port (data_in) in the same header list:clkrenders exactly one fenced section,data_inexactly two, no cross-contamination. - A comment containing
//inside a string on the declaration line — the whole line is shown verbatim regardless (the attachment logic never parses the line's meaning, only whetherhas_comment_aftersees////*after the name), so there is no wrong-line risk, only the expected line reproduced as written. `ifdef/`endifbetween the header and the body declaration — correctly ignored as neither comment-only nor a stolen declaration; the detail section is exactly the body decl's own line(s). (Note: a`endif/`ifdef/`defineline sitting where "no other port" is required is itself treated as "another port" byanother_port_on's conservative word-matching — a false positive that only declines to attach, so it is safe, just another instance of the documented conservative-below-the-fold behavior, not a new bug.)- An attribute (
(* foo *)) prefixing the next port's declaration — correctly detected as "another port" (the attribute's own words split out as ordinary non-grammar identifiers), so the comment is not stolen. - A block comment
/* … */spanning multiple lines — the interior lines are (by design, and correctly) not recognized as comment-only, so the walk stops there and nothing is attached from inside the block — safe (declines rather than guesses), matching the documented limitation.
- A port declared twice — first-writer-wins confirmed: the second body
declaration's comment (
-
Facts-format bump (2 → 3): verified the drop, not a shifted read. Wrote and kept a permanent regression test,
a_store_from_the_previous_facts_format_is_dropped_not_misread(crates/lucisv_server/src/index_cache.rs, next to the existinga_store_from_another_version_is_dropped_whole_and_replacedanda_store_from_the_previous_store_format_is_dropped_whole_and_replaced, which cover aVERSIONmismatch and aCACHE_FORMATmismatch but, before this, never aFACTS_FORMAT-only mismatch). It writes a store whose header saysFACTS_FORMAT2with today'sCACHE_FORMATandVERSIONotherwise unchanged, opens it, and assertsfacts_forreturnsNone(the whole store is unread, not field-shifted) and that the first write since replaces it under today's header, readable afterward. Passes. This closes a real test gap the round left — the design (the format number lives in the header lineIndexCache::opencompares byte-for-byte,index_cache.rs:103) was sound but untested for this exact axis. -
A3 tie-break: confirmed correct, both via the shipped
looking_a_name_up_answers_exactly_what_scanning_every_symbol_would(passes) and by re-deriving it:by_nameis built with a stable sort (Vec::sort_by,lib.rs), so symbols sharing a name keep declaration order, andsymbols_named's twopartition_pointbinary searches over that name-sorted table can only reorder within a name if the sort were unstable — it is not. -
nav::definition/ hover agreement: confirmed the detail location is filtered by!span.is_empty()(nav.rs) exactly as documented, and that a detail-less symbol (ANSI port, ordinary declaration) still returns exactly one location, unchanged from before this round.
Review
2026-08-28 — lead. Accepted after one fix round. Gates re-run
independently: fmt clean, clippy silent, cargo test --workspace green
(2 396 passing at the time of review), cargo test -p vlog_formatter green.
detail_span is the right adaptation of the "detail range" idea to this
model: the non-ANSI merge already produced one symbol, so the only thing
missing was where the declaration is completed, and recording that as an
optional second span leaves every complete-where-named declaration
untouched. Hover and go-to-definition read the same field, which keeps
topo.md's one-matcher rule intact.
Two things in this feature deserved the scrutiny they got.
The facts-format bump. The first implementation added two numbers per
declaration record without moving FACTS_FORMAT, on the argument that a
short record fails done() and is dropped. That argument only holds for the
last declaration in a record; every earlier one would have been read
field-shifted by two, which is a persisted cache handing back wrong spans —
the exact shape invariant 4 exists to catch, in the same family as the
macro-items corruption. Bumping 2→3 is correct and QA's added regression test
(index_cache.rs, a store from the previous format is dropped, not misread)
closes a gap no existing test covered, since nothing varied FACTS_FORMAT
alone.
The comment attachment. This began as scope creep — round 1's plan
explicitly deferred doc comments on hover — and then turned out to be
precisely what the user asked for, so it stays. But it is a textual
heuristic running over disk text on the cross-file path, and QA's PDS-1 found
it lying: another_port_on was a keyword blacklist, so a wrapped declaration
whose first line is bare input looked like an empty line and the next
port's comment attached to the previous port's card. Replacing the blacklist
with a closer whitelist (only_a_closer_on) inverts the bias in the one
direction that is safe — an unrecognised line now declines to attach rather
than mis-attaching — and the doc comment states that bias as the contract.
That is the correct resolution; a predicate over source text that guesses
must fail closed.
PDS-2 was a genuine divergence from the user's stated rule and is fixed by
making the three comment sources independent rather than a priority chain.
PDS-3 was worth chasing rather than parking: the binder does perform the same
header/body merge for TfArg, so old-style task and function arguments now
get detail spans too, and the gap is closed rather than documented. PDS-4's
CRLF strip is display-only and does not touch the buffer.
The dev renamed and inverted a QA-authored test, and flagged it. Correct call and correctly surfaced: the behaviour that test pinned was the finding.