Files
lucioandClaude Fable 5 4e62a14af6 Fragment mode and define continuation: the three .svh shapes that did not parse, and the define that was blamed on its class body
TODO section 22, coverage_gaps H4 corrected. Class-body and module-item
include fragments already parsed - the file-scope item loop is the
class-item loop. The three shapes that did not - a bare statement list,
an enum-member list (riscv-dv's CUSTOM_1, file, included between enum
members), a covergroup-item list - become SourceFile::fragment, detected
by a whole-file rule that cannot misfire on a valid file: the first
structural item failed (directives, macros and null items do not count;
a tolerant Ok that recorded a diagnostic counts as failed - an existing
parity test caught if/else reading as a generate-if to one parser and a
statement to the other), the file does not open with a design-unit
keyword, and a shape consumes the file to EOF, tried narrowest-first.
Each shape re-lexes a fresh token stream - Rewind does not restore the
tokens' comment buckets and the first draft lost comments on
non-fragment files. A fragment formats at indent zero through the
existing printers; its declarations bind; its enum variants are not
exported (pkg::CUSTOM_1 must not resolve to a name that does not
exist). FACTS stays 12.

The other .svh was never a fragment problem: a define whose formal
argument list spans two lines with no backslash. The lexer continues
such a directive until the list closes - incrementally, after QA found
the first cut quadratic on an unclosed list (20000 lines: 2.5 s ->
0.56 ms), pinned by a byte-visit counter.

Opentitan 12 -> 10 failing files, exactly the two predicted; corpus
813 -> 814 of 820; every remaining comment-gap failure proven to fail
identically outside a fragment.

docs/features/fragment-mode/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-09-02 07:34:31 -07:00

572 lines
35 KiB
Markdown

# include-nav
## Goal
Make `` `include`` a real edge in the project graph instead of a comment the
server walks past. M1 taught lucisv to read a filelist and recorded its
`+incdir+` directories; nothing consumed them, so an include line was dead
text and a `` `define`` used in one file could only be answered with "here is
every definition of that name in the workspace, good luck". This milestone
builds the include graph once per index rebuild and spends it twice: an
include line becomes clickable (`textDocument/documentLink` for the underline,
`textDocument/definition` for F12 and `gd`), and hover on `` `NAME `` prefers
the definition the hovered file actually *reaches* through its includes — the
first thing lucisv has that can order two definitions of one macro name.
## Assumptions
- **The search order is the EDA one.** For `` `include "path" ``: an absolute
path is itself; otherwise the **including file's own directory** first, then
each **`+incdir+` of the configured filelist, in filelist order** (nested
`-f` incdirs included, flattened where the reader met them). The first
candidate that is an existing file wins. With no filelist there are no
incdirs at all, so only the own-directory rung applies — which is exactly
what `vcs`/`xrun` do when handed no `+incdir+`.
- **`` `include <path> `` is kept by the lexer and resolved against the
incdirs only**, skipping the own-directory rung. The angled form is not in
IEEE 1800 — it is a vendor extension borrowed from C — and the one thing
every tool that supports it agrees on is that it means "a header from the
search path, not from beside me". The lexer keeps the whole directive line
verbatim (`TokenKind::Directive`), so the form survives to here unchanged;
the only alternative was to drop such lines silently, which would leave a
UVM-style `` `include <uvm_macros.svh> `` mysteriously unclickable.
- **An include is found by a line scan, not by the parser.** The directive has
to be the first non-whitespace thing on its line, and the opening delimiter
the very next thing after the keyword — whitespace between them is optional,
which is what the lexer does too (`` `include"x.svh" `` is one directive
there and here). That is how every real one
is written, it costs one pass over the bytes instead of a second tokenize of
the workspace (see Cost), and it works in a buffer that does not lex — the
state an editor is in half the time someone is typing. What it gives up: a
`` `include`` written at the start of a line *inside a block comment* is
scanned as one (it would then resolve, and get a link, in a commented-out
region), and a `` `include`` that is not first on its line is missed. Both
are rare and both fail in the harmless direction.
- **An unresolvable include is silent.** No link, no location, no diagnostic.
lucisv does not preprocess, and a project routinely builds with incdirs lucisv
was never told about; underlining those lines in red would be wrong far
more often than right.
- **The graph is rebuilt whole with the index**, from the same source list, so
a file the scope ladder excluded is neither an includer nor a target. The
*open buffer's own* includes are resolved live against its current text
instead, so a line typed since the last save is already clickable.
- **A file the index does not cover contributes no `` `define``s**, even when
an include reaches it. Reachability narrows `find_define`'s answer; it
cannot add to it. A `.svh` outside the filelist is therefore invisible to
hover exactly as it was before this feature.
- **Reachability is a set, not an order.** The graph knows *which* files a
file pulls in, not in what order or under which `` `ifdef``, and it does not
model `` `undef`` or redefinition across files. So it is only allowed to
decide when the answer is unambiguous — exactly one reachable definition —
and otherwise it steps aside and the all-candidates hover stands.
- **A resolved path is re-spelled the way the index spells that file, when
the index is sure which file it is.** macOS and Windows default to
case-insensitive filesystems, so `` `include "defs.svh" `` opens a file
named `Defs.svh` quite happily — and the path as written is then a
*different* `PathBuf` from the one the index recorded, which makes every
comparison against the index miss a file that really is reachable. After
resolution, an exact match keeps its spelling, and otherwise **exactly one**
in-scope file matching case-insensitively lends the graph its own spelling.
Zero matches (a header outside the index's scope) or several (a
case-sensitive filesystem genuinely holding both spellings) keep the path as
written: guessing between two real files would be exactly the widening this
rule exists to prevent. It is a lookup in the file list the graph is built
from — no filesystem call, no platform test — and it applies to the
`definition`/`documentLink` targets too, so F12 lands on the file the index
knows.
- **Symlinks are not resolved.** Resolved paths are folded lexically
(`.`/`..` removed) so they compare equal to the index's own spelling, the
same lexical rule `lucisv_core::config::Discovery` and
`lucisv_core::filelist` follow.
## Handshakes
### Consumed
- `lucisv_core::filelist::Filelist::incdirs` — recorded since M1, used here for
the first time. Resolved absolute and in filelist order, which is the order
they are searched. **`state.rs` no longer drops them**: the scope ladder
carries them alongside the file list (`Scope`/`Sources` in `state.rs`) and
hands them to the graph on every rebuild. Only rung 1 (a filelist) can
produce any; rungs 2 and 3 name none.
- `vlog_semantic::WorkspaceIndex::find_define` — **unchanged**. It still
returns every workspace definition, in file order, implying no resolution
order. The include-graph precedence is an overlay applied in
`lucisv_server::hover`, so no `vlog_semantic` change was needed at all and the
workspace-index contract is exactly what it was.
- `vlog_parser` — nothing new. The line scan reads text; the lexer's
treatment of `` `include`` (one `TokenKind::Directive` token carrying the
whole line) is only relied on as documentation that the angled form is not
thrown away.
### Promised
- `lucisv_server::includes::IncludeGraph` — `build`, `resolve` and `reachable`
are the whole surface. `Workspace::includes()` hands the current one out.
A default-constructed `Workspace` has an empty graph, which resolves
nothing and reaches nothing; every caller must behave as it did before this
feature when that is what it gets.
- `lucisv_server::includes::scan` — the one include scanner. `documentLink`,
`definition` and the graph build all go through it, so the three can never
disagree about what an include line is.
- **A third lexical `normalize`.** `includes.rs` carries its own copy of the
`.`/`..` folding that `lucisv_core::filelist::Reader::normalize` and
`lucisv_core::config::Discovery::absolute` already have (both private, both
on stateful structs). Two copies were deliberate duplication (filelist work
log, 2026-08-24); three is the point at which extracting a
`lucisv_core::path::normalize` and pointing all three at it becomes worth
doing. **Request for the lead**, not done here: it touches two modules
outside this feature's scope.
## Cost
The graph build is what this feature adds to every index rebuild. Measured
2026-08-25 on the checked-in 860-file corpus, `--release`:
| | |
|---|---|
| files scanned | 860 |
| files that include something | 119 |
| include graph build | **~6 ms** |
| the `WorkspaceIndex::build` it runs beside | ~322 ms |
So roughly 2% of a rebuild that was already happening — a line scan per file
plus one `is_file` per include. Pinned by an `#[ignore]`d probe
(`cargo test --release -p lucisv_server --bin lucisv-server includes::tests::perf
-- --ignored --nocapture`), the same shape as `inlay.rs`'s: timing assertions
in a shared runner are flaky, so it prints and asserts nothing but the
corpus's presence.
## Status / TODO
- [x] `crates/lucisv_server/src/includes.rs`: `scan`, `Include`, `IncludeGraph`
(`build`/`resolve`/`reachable`), the two capability entry points.
- [x] `+incdir+` plumbed from the filelist through `state.rs` to the graph,
nested `-f` incdirs included and in order.
- [x] `textDocument/documentLink`, advertised with `resolveProvider: false`.
- [x] `textDocument/definition` on an include line, sharing the computation.
- [x] Hover's include-graph precedence, one definition or the old answer.
- [x] Tests: resolution order, angled form, unresolved, links + definition on
one fixture, a space in the path, one and two hops, a cycle, an
unreachable-only fallback, nested-filelist incdirs, no-filelist mode,
and one e2e stdio session covering all three requests.
- [x] QA round 1: case-canonicalization against the index's spelling (HIGH),
and the scanner loosened to the lexer's own rule for a missing space
before the delimiter (MEDIUM).
- [x] `cargo fmt`, `cargo clippy --all-targets`, `cargo test --workspace`,
`node editors/vscode/smoke.js`.
- [ ] **Not done, deliberately:** no `` `ifdef``/`` `undef`` awareness. A
reachable definition inside a false `` `ifdef`` branch is still offered;
modelling that means preprocessing, which TODO.md §7 rules out.
- [ ] **Not done, deliberately:** an include is not an index edge. Symbols
declared in an included file are found because the *file* is in the
index, not because it was included; a header outside the filelist stays
invisible.
**Amendment, 2026-09-02 (`docs/features/fragment-mode/README.md`, TODO
§22):** the files this bites hardest now at least *parse*. A `.svh` or
`.sv` that is a bare statement list, enum-member list or covergroup-item
list — riscv-dv's `riscv_custom_instr_enum.sv` is the canonical one —
is read as a **fragment**, so it formats, binds, lints and hovers on its
own terms instead of being one error node. What is still missing is
exactly what this item names: the **reverse** map, who `` `include``s
this fragment. Without it a fragment exports nothing to the workspace
index (`is_unit` is unchanged, `FACTS_FORMAT` stays 12), so
`CUSTOM_1` is an `EnumVariant` inside its own file and unreachable from
`riscv_instr_pkg`, which is where it actually lands. That is the right
answer until the reverse map exists — inventing
`riscv_custom_instr_enum::CUSTOM_1` would be a name that does not
exist — and it is the first thing the reverse map would unlock.
- [ ] **Not done, deliberately:** no completion of include paths, and no
diagnostic for an include that resolves to nothing. Both are their own
features, and the second one needs lucisv to be sure it knows every
incdir — which it is not.
## Work log
### 2026-08-25 — dev agent, M10
Written in the order the brief lists: resolver, then the two capabilities,
then the hover overlay. Decisions worth recording:
- **One scanner, a line scan, used by everything.** The alternative was to
read includes off `Document::tokens` for the open buffer (the lexer already
gets comments and strings right) and to line-scan for the graph, since
tokenizing the workspace a second time to build the graph would have cost
far more than the graph. Two scanners would have meant `documentLink` and
the graph disagreeing in exactly the corner cases nobody tests. The price is
named under Assumptions: a `` `include`` at the start of a line inside a
block comment is treated as one.
- **The angled form resolves against incdirs only.** The lexer keeps it —
checked, not assumed: a throwaway `vlog_parser` example (deleted, not
committed) tokenized `` `include <uvm_macros.svh> `` and got back one
`Directive` token whose text is the whole line, because the raw lexer
captures every line directive verbatim to end of line. So the choice was
resolve-it-somehow or drop it. The C convention is the only
precedent every tool that supports the form agrees on, and it makes the two
spellings mean different things — which is the only reason to write the
angled one.
- **Resolution is live for the open buffer, cached for everything else.** The
graph is rebuilt on save like the index; a link that appeared only after a
save would look broken. The buffer's own includes are therefore resolved
from its current text on each request (one line scan of one file), and only
the hops *past* the buffer come from the graph.
- **The hover overlay narrows, never widens, and only when it is sure.** It
runs at all only when `find_define` returned two or more candidates, and
replaces them only when exactly one is reachable. Every other shape — no
graph, nothing reachable, several reachable — leaves the pre-existing
all-candidates answer byte-for-byte alone, which is what keeps this from
being a regression for a project that does not use `` `include``.
- **No `vlog_semantic` change.** The brief allowed a minimal one; none turned
out to be needed. `find_define`'s contract ("no resolution order is
implied") is still true, and the ordering lives in the server where the
graph lives.
**Files touched outside this feature's own module**, all of them the wiring
the brief asked for: `state.rs` (the `Scope`/`Sources` structs that carry
incdirs, the `includes` field and its accessor, three tests), `main.rs` (the
module, the `documentLink` capability, two tests), `server.rs` (the
`documentLink` handler), `nav.rs` (the include case of `definition`, one
test), `hover.rs` (the narrowing overlay, six tests).
**Verification.** `cargo fmt --all -- --check` clean; `cargo clippy
--all-targets` silent; `cargo test --workspace` green — 1420 tests, 28 of them
new (16 `includes`, 6 `hover`, 3 `state`, 1 `nav`, 1 `main`, 1 e2e session).
`node editors/vscode/smoke.js target/debug/lucisv-server` OK. Perf measured as
above. No new dependency; no version bump.
### 2026-08-25 — dev agent, QA round 1 fixes
**Finding 1 (HIGH), fixed: a case-mismatched include silently dropped a
reachable definition.** `IncludeGraph` now carries the in-scope file list it
was built from — `known` (exact spellings) and `folded` (lower-cased spelling
→ the one file that has it, or `None` when several do) — and every path
`resolve` returns goes through `as_the_index_spells_it`
(`crates/lucisv_server/src/includes.rs`). Exact match: unchanged. Exactly one
case-insensitive match: the index's spelling is adopted, so the graph edge,
the reachability comparison in `hover.rs` and the URI go-to-definition hands
the editor all name the same file. Zero or several matches: the path as
written, which is what a case-sensitive filesystem and an out-of-scope header
both keep doing.
Why this shape rather than `fs::canonicalize`: canonicalization is a syscall
per include *and* resolves symlinks, which this project deliberately does not
do anywhere (`config-discovery`'s lexical rule). The tables are built from a
list the graph already holds, so the fix costs one `HashSet`/`HashMap` of the
workspace's paths and one lower-casing pass at build time — the perf probe
still reports ~6ms over the 860-file corpus, unchanged within noise.
Why the zero/several cases stay as written: adopting a spelling when two real
files fold together would be a guess between them, which is the *widening*
the narrowing rule exists to prevent. Better to keep the honest all-candidates
hover.
**Regression test** — QA's pinned test flipped from asserting the bug to
asserting the fix: `hover::qa_findings::a_case_mismatched_include_still_counts_as_reachable`
now requires "is defined 2 times" with both `Defs.svh:1` and `other.svh:1`
named. Added `includes::tests::a_resolved_path_is_re_spelled_the_way_the_index_spells_it`
at the level the rule is implemented: nothing in scope → as written; one
in-scope match → the index's spelling; two folding together → as written.
Both are `cfg(any(target_os = "macos", target_os = "windows"))`-gated, as
QA's was, because the premise is `is_file` succeeding for a spelling the file
does not have.
**Mutation-checked**, because a regression test that cannot fail is worthless:
made `as_the_index_spells_it` return its argument unchanged and re-ran — both
tests failed, exactly the shape QA reproduced. Restored.
**Finding 2 (MEDIUM), fixed: `` `include"x.svh" `` (no space) was missed.**
The whitespace requirement in `include_on_line` is gone; the opening
delimiter must simply be the next thing after the keyword, which keeps
`` `includes "x.svh" `` and `` `include_foo"x.svh" `` declining (the
delimiter does not immediately follow) without a separate guard. QA's pinned
test became
`includes::tests::a_missing_space_before_the_delimiter_is_still_an_include`,
covering both delimiters and both keyword-prefix cases. Assumptions updated.
**Finding 3**: nothing to do, as ruled — QA's probe pins intended behavior.
**Gates after the fixes.** `cargo fmt --all -- --check` clean, `cargo clippy
--all-targets` silent, `cargo test --workspace` green — 1426 tests on macOS
(1425 QA left, plus the one new test above; no test was removed, QA's two
pinned ones were rewritten in place). `node
editors/vscode/smoke.js target/debug/lucisv-server` OK. Perf probe re-run after
the fix: ~6ms over the 860-file corpus.
## QA log
### 2026-08-25 — QA agent, M10
**Gates.** `cargo fmt --all -- --check` clean. `cargo clippy --all-targets`
silent. `cargo test --workspace` green — re-ran repeatedly while adding the
tests below; **1425** tests at the end (1420 the dev shipped + 5 added here).
`node editors/vscode/smoke.js target/debug/lucisv-server` OK. Perf probe re-run:
`cargo test --release -p lucisv_server --bin lucisv-server includes::tests::perf
-- --ignored --nocapture` → **6.5ms** over the 860-file corpus (dev measured
~6ms) — confirmed, order of magnitude and absolute number both hold.
**Design review of the riskiest piece — hover's "narrows, never widens"
claim.** Traced both edge cases the brief asked about directly:
- *Define in the hovered file itself, plus a same-name define elsewhere.*
Safe by construction: `macro_hover` (`hover.rs:36`) checks
`doc.defines.latest(name)` **before** it ever calls
`narrowed_to_the_include_graph`. A file's own definition short-circuits the
whole overlay; the include graph never gets a vote. No finding.
- *A define reached only through a path the resolver can't resolve.*
`reachable_from` (`includes.rs`) seeds from `resolved(ws, doc)`, which drops
any `` `include`` `graph.resolve` returns `None` for. If every include on
the seed hop is unresolved, `reachable_from` returns an empty set, and
`narrowed_to_the_include_graph` (`hover.rs:82-84`) takes the `reachable.is_empty()`
early return straight back to all-candidates. Safe. No finding.
**Finding 1 — HIGH. Case-insensitive filesystem breaks the narrowing
invariant: a genuinely-reachable definition is silently dropped, and hover
shows a single wrong-confidence answer instead of the honest "defined N
times."**
`IncludeGraph::resolve` (`includes.rs:121-135`) resolves an `` `include``
by trying `dir.join(target).is_file()` and, on success, returning
`normalize(&found)` — the path **as written**, only `.`/`..`-folded, never
canonicalized against the filesystem's actual on-disk spelling. On the
default filesystem for macOS (this machine) and Windows — case-insensitive,
case-preserving — `is_file()` succeeds for a spelling that differs only in
case from the real file name. `WorkspaceIndex`, in the meantime, records the
file under whatever case `collect_files`/the filelist reader actually read
off disk. The two `PathBuf`s differ, so the `reachable.contains(p)` check in
`narrowed_to_the_include_graph` (`hover.rs:88`) silently fails to recognize a
file that **is** reachable.
Concretely: `top.sv` contains `` `include "defs.svh"`` and
`` `include "other.svh"``. The real file is `Defs.svh` (capital D); `other.svh`
is spelled correctly. Both are genuinely included and both define `` `W ``.
The two-reachable case is supposed to fall back to "is defined 2 times" (this
is exactly what `two_reachable_definitions_are_listed_rather_than_guessed_between`
in `hover.rs` pins for the case-matched case) — but here, `Defs.svh` drops out
of the `reachable.contains` comparison (not out of the graph — the edge is
there, just under the wrong-case key), leaving exactly one candidate. The
overlay then does precisely what it is built to do with one candidate: shows
it alone, with full confidence, never mentioning the other one exists.
Reproduced and pinned as `hover::qa_findings::qa_a_case_mismatched_include_silently_drops_a_reachable_define`
(`crates/lucisv_server/src/hover.rs`, gated `cfg(any(target_os = "macos",
target_os = "windows"))` since the premise needs a case-insensitive default
FS). The test asserts *today's* wrong output rather than the correct one, so
the suite stays green — a fix must touch this test.
Not attempted here: this is a design decision (canonicalize `resolve`'s
output against the real directory entry — costly per include; or compare
paths case-insensitively only where narrowing needs to decide reachability;
or normalize both the graph's and the index's paths through one canonical
form) that belongs to the dev, not a QA-sized fix. **Recommend: fix before
shipping**, since it is a silent-wrong-answer failure of the feature's core
documented safety property, on the platform this was developed and tested on.
**Finding 2 — LOW/MEDIUM. An undocumented scanner narrowing: `` `include``
with no whitespace before the opening delimiter is silently missed, and it
diverges from the very lexer the README cites as this scanner's behavioral
reference.**
`include_on_line` (`includes.rs:56`) requires `rest.starts_with(char::is_whitespace)`
right after stripping `` `include``, so `` `include"x.svh"`` (no space) scans
to nothing — no link, no definition, no graph edge, no diagnostic. But
`vlog_parser`'s lexer — which the Assumptions section leans on directly
("a throwaway `vlog_parser` example... tokenized `` `include <uvm_macros.svh>``
and got back one `Directive` token") — recognizes the directive name by
scanning identifier characters with no whitespace requirement at all
(`crates/vlog_parser/src/lexer.rs:219-238`, `is_line_directive` list at
line 702: `` `include"x.svh"`` lexes as one whole-line `Directive` token,
same as the spaced form). So this scanner is *stricter* than the tool it
claims consistency with, and unlike the two narrowings the README does
document (block-comment false positive, mid-line miss), this one isn't
written down anywhere. Real-world impact is small — nobody's style guide
omits the space — but it is a genuine, silent false negative and an
inconsistency between the documented behavioral reference and the actual
scan rule. Pinned as `includes::tests::qa_a_missing_space_before_the_quote_is_silently_missed`.
**Recommend:** either loosen the scanner to match the lexer (drop the
whitespace requirement, keep the `` `includes`` guard some other way — e.g.
require the next byte be `"` or `<|` rather than merely non-alphanumeric) or
add one sentence to the Assumptions section admitting the gap. Not a blocker.
**Finding 3 — informational, not a defect.** `documentLink`/`definition`
resolve purely off disk (`IncludeGraph::resolve` takes no `sources`/index
argument), so a header the configured filelist never names — reachable only
through its incdir — is still clickable, even though it is outside
`WorkspaceIndex`'s scope. This is consistent with `vcs`/`xrun` (the search
path is not the same thing as the compiled unit list) and is not a bug, but
it is an asymmetry with `find_define`'s explicit index-scoping ("an include
is not an index edge") that the Assumptions section does not spell out for
the other two capabilities, and it was previously untested. Pinned as
`includes::qa_scope_probe::a_link_resolves_to_a_file_the_filelist_never_names`.
No action required.
**Coverage added, no defect found:**
- `hover::qa_findings::an_angled_include_narrows_hover_same_as_a_quoted_one` —
the six hover narrowing tests the dev shipped only ever use the quoted
form; the angled (`<sys>`) form narrows correctly too, now pinned.
- `crates/lucisv_server/tests/e2e.rs::include_nav_round_trips_in_a_workspace_whose_directory_has_a_space` —
the one e2e session for this feature used a plain temp dir; every other
e2e test in the file hand-rolls unencoded `file://` URIs, so a directory
with a space had never gone over the wire for any feature, this one
included. Passes: `path_to_uri`'s percent-encoding (already unit-tested in
`includes.rs`) round-trips correctly end to end.
**Tried and found solid, no test added (already covered or the fix would be
redundant with an existing test):**
- Tab-indented `` `include``, CRLF line endings, a file whose last line is an
include with no trailing newline, `` `include?`` (keyword-prefix collision),
a string literal at line start beginning with the directive's own text —
all scan correctly or correctly decline, matching the documented rules.
- Two `` `include``s on one physical line: only the first (line-initial) one
is scanned, the second is silently dropped — this is the direct, intended
consequence of the documented "first non-whitespace on its line" rule, not
a separate gap.
- Resolution order (own dir beats every incdir), the angled form skipping the
own-directory rung, a relative `../` path that lexically escapes above the
workspace root (folds correctly to the real absolute path — `PathBuf::pop`
on an already-root path is a harmless no-op, matching POSIX `..`-at-root
semantics), and an absolute include — all match the dev's own tests and the
documented EDA search order; re-verified by direct code reading rather than
new tests, since the existing suite already exercises each one.
- 500 `` `include``s in one file: `documentLink` answered in 3.5ms — no
quadratic surprise (`resolved` scans once and resolves inline).
- Stale-graph honesty: an unsaved buffer edit that *adds* an include is
clickable immediately (`resolved()` scans the live buffer text for the
first hop), but any hop *past* that first one still comes from the graph as
of the last rebuild — exactly as the Assumptions section and work log say.
Not misleading; the README's own wording already draws this line correctly.
**Verdict: ship after fixing Finding 1.** The scanner, resolver, and the two
navigation capabilities are solid — 500-include perf is fine, the search
order matches the documented EDA convention, and the narrowing overlay is
provably safe by construction in the two cases the brief worried about most
(a file's own definition, and an unresolvable seed). But Finding 1 is a real
violation of the feature's central documented promise ("narrows, never
widens, and only when it is sure") on the platform this shipped from, using
an unremarkable real-world input (one file whose include-site spelling
doesn't match its own filename's case — common when headers come from a
vendor IP or a different OS's checkout). It should not corrupt anything lucisv
formats (out of scope for the hard invariants in `CLAUDE.md`, which are about
formatter output), but it is a silently-wrong LSP answer, not a
conservatively-declined one, and that is exactly the failure mode this
feature was built to avoid. Finding 2 is real but low-impact and can ship
with a documentation fix or wait. Finding 3 needs nothing.
### 2026-08-25 — QA agent, round 2 (re-verification of the dev's rework)
Dev's rework: `IncludeGraph` now carries `known` (exact in-scope spellings)
and `folded` (lowercased spelling → the one in-scope file that has it, or
`None` when several do), and every `resolve` result passes through
`as_the_index_spells_it` (`includes.rs:179-188`) — an exact match keeps its
spelling; exactly one case-insensitive match adopts the index's spelling
(so the graph edge, `documentLink`'s target, and `definition`'s `Location`
URI all carry it); zero or several matches keep the path as written. Pure
`HashMap`/`HashSet` lookup, no `fs::canonicalize`. `include_on_line`
(`includes.rs:51-66`) dropped the whitespace-before-delimiter requirement:
the delimiter must be the very next byte after `` `include``, matching the
lexer, while `` `includes`` / `` `include_foo`` still decline because the
keyword itself doesn't match. Finding 1's test flipped to
`hover::qa_findings::a_case_mismatched_include_still_counts_as_reachable`,
now asserting "is defined 2 times" with both files named. Finding 2's test
flipped to `includes::tests::a_missing_space_before_the_delimiter_is_still_an_include`.
**Gates, re-run clean.** `cargo fmt --all -- --check` clean. `cargo clippy
--all-targets` silent. `cargo test --workspace` green at **1429** — the
1426 the dev's rework landed at, plus 3 added in this round (below). Perf
probe re-run: **6.3ms** over the 860-file corpus (dev claimed ~7ms; this
machine has consistently measured 6-6.5ms across both rounds — same order of
magnitude, no regression). `node editors/vscode/smoke.js target/debug/lucisv-server`
OK.
**Mechanism-level re-verification of Finding 1's fix.** Read
`as_the_index_spells_it` and the `folded` construction in `build`
(`includes.rs:104-134, 179-188`) directly rather than trusting the summary:
- `known.contains(&path)` is checked first, so an exact-spelling match never
touches `folded` at all — the common case is untouched by the new logic.
- `folded` is populated with `.and_modify(|found| *found = None).or_insert_with(...)`.
A key seen once stores `Some(path)`; seen again, unconditionally flips to
`None` and *stays* `None` no matter how many more times the same key comes
through — verified this isn't a last-writer-wins bug by re-deriving it from
the `Entry` API semantics, then confirming with a fresh three-way collision
test (below) rather than trusting the two-file test the dev already had.
- `folded` is built entirely from `sources` (the in-scope file list handed to
`IncludeGraph::build`), never from a directory read or `fs::canonicalize`,
so a case collision against a file the graph was never told about (outside
the filelist's scope) has no entry to match and falls through to "keep the
path as written" — re-verified with a dedicated out-of-scope test rather
than assuming the "built from sources" comment is accurate.
**Round-2 attacks, all done against real code/binaries, not by re-reading the
round-1 writeup:**
1. **Three files colliding on one folded spelling, all in scope.** Extended
the dev's own two-file collision test to three
(`includes::qa_round2::three_files_colliding_on_one_folded_spelling_stay_ambiguous`,
`includes.rs`). Confirmed `None` sticks through a third collision and the
path comes back as written — no false adoption, no "third one breaks the
tie" surprise.
2. **Case-mismatched include whose target is out of scope.** A file that
really exists on disk under a different case, but was never passed to
`IncludeGraph::build` as a source (e.g. excluded by the filelist).
Confirmed unchanged behavior — the path comes back exactly as written, the
same answer this would have gotten before the fix
(`includes::qa_round2::a_case_mismatch_on_a_file_outside_the_graphs_scope_is_unchanged`).
3. **The real binary, once, on a case-mismatched fixture.** Unit tests calling
`resolve`/`hover` directly can't settle what URI an editor actually
receives, so this drives `lucisv-server` over real stdio JSON-RPC — the same
harness `e2e.rs` uses for every other capability. `top.sv` writes
`` `include "defs.svh"``; the real (and indexed) file is `Defs.svh`.
Confirmed both `documentLink`'s `target` and F12's `Location.uri` carry
the capital-D URI, not the as-written lowercase one
(`go_to_definition_lands_on_the_indexs_own_spelling_not_the_includes`,
`crates/lucisv_server/tests/e2e.rs`, case-gated). This is the one check none
of the unit-level tests — the dev's or mine — could have caught a
regression in: it is the only test that round-trips the URI through the
actual wire encoding (`path_to_uri`) with a real spawned process on the
other end.
4. **`` `include<x.svh>`` — angled, no space.** Already covered by the dev's
own flipped test (`a_missing_space_before_the_delimiter_is_still_an_include`
asserts `one("`include<nospace.svh>\n").target == "nospace.svh"`).
Independently re-confirmed by direct `scan()` call before writing this
entry; not re-added as a separate test since the dev's already pins it.
5. **A tab between the keyword and the quote.** `rest.trim_start()`
(`includes.rs:60`) trims every `char::is_whitespace` byte, tab included —
"whitespace optional" was never "whitespace forbidden", and nothing in the
rework narrowed it. Confirmed directly by calling `scan` on a line with a
literal tab between `` `include `` and the opening quote; not pinned as a
new test since it exercises the same `trim_start` call the dev's
spaced-form tests already cover and no distinct code path is at risk.
6. **Mutation check.** Temporarily reverted `as_the_index_spells_it` to
`{ path }` (identity) in a scratch copy, re-ran the full `lucisv_server`
unit suite: exactly two tests failed —
`includes::tests::a_resolved_path_is_re_spelled_the_way_the_index_spells_it`
and `hover::qa_findings::a_case_mismatched_include_still_counts_as_reachable`
— and nothing else. That is precisely the two tests whose whole point is
this function, with no collateral breakage and no false negative from a
test that would have passed either way. Restored the real implementation
before re-running the full gate suite.
**Verdict: ship.** Finding 1 (HIGH) is fixed at the mechanism level, not just
at the level of the one scenario the round-1 test happened to check — the
three-way collision, the out-of-scope collision, and the real-binary wire
round trip were all attacks the fix's *design* had to survive, not just its
one pinned test, and it did. Finding 2 (LOW/MEDIUM) is fixed and the
whitespace-optional behavior is exactly as documented, angled and quoted
forms alike, tabs included. Finding 3 (informational) is unaffected by this
rework and still needs nothing. No new findings this round.
## Review
**2026-08-25 — lead.** Reviewed after QA round 2's ship verdict; gates
run independently (1429 tests, 0 failures). The one-scanner-three-
consumers design keeps links, definition and the graph from ever
disagreeing, and spending M1's until-now-unused `+incdir+`s here closes
a loop the plan had open since the first milestone. QA's HIGH was the
round's real work: the case-insensitive-filesystem trap produced exactly
the confident-incomplete hover this feature was built to avoid, and the
fix — re-spelling resolved paths the way the index spells them, latching
to ambiguity on collisions, no fs::canonicalize — is the boring pure
lookup I'd have asked for. Round-2 verified it by construction, by
three-way-collision attack, by real-wire F12, and by mutation. The
hover-narrowing invariant (narrow, never widen; local defines always
win) held under every probe. Accepted; M10 checked off in the umbrella
plan and TODO §8.