659 lines
36 KiB
Markdown
659 lines
36 KiB
Markdown
# completion-core
|
||
|
||
M5 of the refactoring plan (`docs/features/refactor/README.md`): **general
|
||
completion** — keywords and project-wide identifiers merged into M4's
|
||
module-hinting response — plus the **0.3.0 version bump**.
|
||
|
||
## Goal
|
||
|
||
Make `textDocument/completion` answer the question a user actually asks while
|
||
typing, instead of only the one M4 could answer. One response, five tiers,
|
||
sorted best-first: the instantiation skeleton where one belongs, then the
|
||
declarations visible at the cursor, then what the project declares, then every
|
||
reserved word the lexer knows, then every identifier used anywhere in the
|
||
project. A name appears once, claimed by its best tier. Nothing is offered
|
||
inside a comment or a string, and — the other half of the same promise — a name
|
||
that appears *only* inside a comment or a string is never a candidate, because
|
||
the word list is harvested from the token stream, where comments are trivia and
|
||
a string is one token. The scope of "the project" is M1's ladder, unchanged, so
|
||
a file the filelist leaves out contributes nothing.
|
||
|
||
Completion fires on every keystroke, which is the whole design constraint: no
|
||
tier may walk the workspace. The two project-wide tables are built beside the
|
||
workspace index, from the same file list, and are replaced with it.
|
||
|
||
## Assumptions
|
||
|
||
- **The lexer's reserved-word list is the keyword list.** `vlog_parser::token`
|
||
now generates `KEYWORDS` (a `&[&str]`) and `is_keyword` from one
|
||
`keywords![...]` macro invocation, so a word cannot be one without being the
|
||
other. The list is unchanged — 181 words, comments and all — and the parser
|
||
suite is green, so lexing behaviour is untouched. Offering a word the parser
|
||
does not reserve, or failing to offer one it does, would both be lies; the
|
||
macro makes both unrepresentable.
|
||
- **A comment is never code and a string is never code.** The harvest takes
|
||
`Ident` and `SystemIdent` tokens only. Comments never reach the token stream
|
||
at all (the lexer detaches them as trivia), and a string literal is one
|
||
`String` token, so neither can contribute a candidate — this is a property of
|
||
the lexer, not a filter that could be forgotten. Two `Ident` shapes are
|
||
dropped on purpose: a macro usage (`` `WIDTH ``, whose text is the whole
|
||
invocation, argument list included — the macro *names* have their own table)
|
||
and an escaped identifier (`\my-port`, which needs a terminating space that a
|
||
plain word item cannot promise).
|
||
- **A buffer that does not lex gets no completions at all.** With no token
|
||
stream there is no way to tell a comment from code, and the commonest way to
|
||
break the lexer while typing is to open a string or a block comment and keep
|
||
going. Declining is the safe half of that trade, and the buffer lexes again as
|
||
soon as the quote or the `*/` is typed. Deliberate: the alternative is
|
||
offering a completion list *inside* the unterminated string.
|
||
- **The index's freshness is the tables' freshness.** The index rebuilds on
|
||
`initialize` and on `didSave`, so the project-wide tables do too. An unsaved
|
||
edit in *another* buffer is therefore not in the word table until it is
|
||
saved — exactly the rule the index has always had (`lucisv-server`'s
|
||
invalidation notes). The buffer being typed in is the exception, and needs no
|
||
rebuild: its own token stream is already computed on every change, so its
|
||
words are harvested per request and an unsaved name is a candidate
|
||
immediately.
|
||
- **A macro name is written with a backtick where it is used and without one
|
||
where it is defined or tested.** See *The backtick ruling* below.
|
||
- **`sortText` is a nudge, not a guarantee.** VS Code scores its own fuzzy match
|
||
first and uses `sortText` to break ties; a client that sorts purely on
|
||
`sortText` gets the tier order exactly. Both are correct behaviour, and the
|
||
tests assert what the server sends rather than what any client draws.
|
||
- **The response is capped at 512 items** (`LIMIT`), the module tier separately
|
||
at 64 (`MODULE_LIMIT`, M4's, unchanged). Justification under *The cap*.
|
||
|
||
## Handshakes
|
||
|
||
- **Widened in `vlog_parser`** — the only change outside `lucisv_server`.
|
||
`token.rs`'s keyword table became a `keywords![...]` macro invocation that
|
||
generates both `pub const KEYWORDS: &[&str]` and `pub fn is_keyword`;
|
||
`lib.rs` re-exports `KEYWORDS`. `is_keyword` is still a `matches!` over
|
||
literals, so the lexer's hot path is byte-for-byte the same code it was.
|
||
No word was added, removed or reordered.
|
||
- **Consumes `vlog_semantic`**: `Semantics::scopes`/`scope`/`symbol` for the
|
||
visible-declarations tier, `WorkspaceIndex::workspace_symbols`/`path`/
|
||
`files`/`defines` (all once per index build, never per request) for the
|
||
project-declares tier. Read-only; nothing new is asked of it.
|
||
`SymbolKind` → `CompletionItemKind` is a new mapping in `completion.rs`
|
||
mirroring the choices `symbols::lsp_kind` already makes for the outline in
|
||
the other enum.
|
||
- **Consumes `vlog_parser`**: `tokenize` for the word harvest, `KEYWORDS` for
|
||
the keyword tier, `defines::DefineKind` to keep `` `undef`` entries out of the
|
||
macro table.
|
||
- **Consumes `vlog_refactor`** exactly as M4 did — `module_names`,
|
||
`module_definition`, `instantiation_plan`, `render_with` — through the
|
||
unchanged `module_tier`. Nothing in `vlog_refactor` was touched.
|
||
- **Duplicated deliberately, not shared**: `vlog_refactor::ports::visible_in`
|
||
answers "is this *one* name visible here" and is `pub(crate)` to that crate;
|
||
`completion::visible_symbols` answers "what is visible here". They share the
|
||
innermost-scope idea and nothing else, and lifting one to fit both would have
|
||
meant widening another crate's API for a second caller that wants a different
|
||
answer. Recorded so the lead can overrule it cheaply.
|
||
- **Promises `lucisv_server`'s own callers**: `completions` never panics, always
|
||
returns items whose `textEdit` replaces exactly the typed word (plus the
|
||
backtick, in the macro case), and never returns a module item whose text
|
||
differs from what M4 returned — the M4 tests assert the skeleton byte for
|
||
byte and still pass.
|
||
- **`editors/vscode` needs no change.** No new setting, no new capability: the
|
||
completion provider was already advertised, and `snippetSupport` is read the
|
||
same way.
|
||
|
||
## The tiers
|
||
|
||
`sortText` is `<tier digit><name>`, so the client sorts tier-first and
|
||
alphabetically within a tier.
|
||
|
||
| Tier | What | `CompletionItemKind` | Where it comes from |
|
||
|---|---|---|---|
|
||
| `0` | Module instantiation skeletons | `MODULE` | M4, unchanged — module-item position only |
|
||
| `1` | Declarations the scope chain at the cursor binds | the declaration's own kind | this file's `Semantics` |
|
||
| `2` | Packages, package members, typedefs, classes, modules, `` `define`` names | the declaration's own kind, `CONSTANT` for a macro | `WorkspaceIndex`, tabled at build time |
|
||
| `3` | Every reserved word | `KEYWORD` | `vlog_parser::KEYWORDS` |
|
||
| `4` | Every identifier used anywhere in the project | `TEXT` | token harvest, tabled at build time |
|
||
|
||
Tier 0 is first because at module-item position a fifteen-line skeleton is what
|
||
the user is reaching for, and it is the only tier that is *position*-gated at
|
||
all: M4's gate (nothing but whitespace before the word on its line, plus
|
||
`pairs::analyze`'s scope chain) is unchanged and still declines inside a
|
||
procedural block, a function, a class, a connection list and an expression.
|
||
Every other tier ignores position entirely — a name is a name wherever it is
|
||
written — which is why M4's "nothing is offered here" tests became "no
|
||
*skeleton* is offered here".
|
||
|
||
Tier 4 deliberately includes names that are **not** visible at the cursor. That
|
||
is the point of it: it is the rope / VS Code word-completion tier, and a name
|
||
used three files away is a better guess than nothing. It is last, and it is
|
||
`TEXT`, so it never pretends to be a resolved symbol.
|
||
|
||
Dedup is by label, first tier wins. A name that is both a local declaration and
|
||
a word used elsewhere in the project is offered once, in tier 1, with its real
|
||
kind and its declaration line as detail.
|
||
|
||
## The backtick ruling
|
||
|
||
`` `define`` names are the one candidate whose spelling depends on where the
|
||
cursor is, so the rule is stated rather than implied:
|
||
|
||
- **The cursor follows a backtick** (`` `WI| ``) — the response is *only* macro
|
||
names, because nothing else may follow a backtick. Each item is labelled and
|
||
inserted as `` `NAME ``, and the replaced range starts at the backtick the
|
||
user already typed, so it is never doubled.
|
||
- **The cursor does not follow one** (`WI|`) — macro names are offered
|
||
alongside everything else, bare, and **no backtick is invented**. Inserting
|
||
punctuation the user did not type is how a completion list loses trust, and
|
||
bare is the correct text at exactly the places a macro name is written without
|
||
a backtick: `` `ifdef NAME ``, `` `ifndef NAME ``, `` `undef NAME ``,
|
||
`` `define NAME ``.
|
||
|
||
Both spellings are tested. `` `undef`` entries are not offered: lucisv does not
|
||
preprocess and cannot say where a name stopped being defined, so a table that
|
||
listed them would be pretending to know.
|
||
|
||
## The cap
|
||
|
||
512 items per response, `isIncomplete` when it truncates. The arithmetic: an
|
||
*empty* prefix is the worst case, and 64 modules + 181 keywords + whatever one
|
||
scope binds still leaves room for the word tier to appear at all, which a
|
||
64-item cap (M4's) would not — the list would have ended inside the keywords.
|
||
512 small items is a payload of a few tens of kilobytes, and the tiers fill in
|
||
order, so what a truncation drops is the least useful end.
|
||
|
||
The module tier keeps its own 64, because it is the one tier that costs
|
||
*parsing*: one parse of one defining file per item. Every other tier is a binary
|
||
search into a sorted table.
|
||
|
||
Truncation is cheap by construction: each tier asks `Items::full()` before
|
||
building an item and breaks out of its loop when the answer is yes, so a full
|
||
response never formats a `detail` string nobody will read. Skipping that check
|
||
cost 8.5 ms on the corpus's empty-prefix request; with it, 212 µs.
|
||
|
||
## Performance
|
||
|
||
Measured on the 860-file corpus (4.94 MB of source: picorv32, ibex,
|
||
common_cells, OpenTitan), release build, aarch64-apple-darwin. The permanent
|
||
regression guard is
|
||
`completion::tests::a_keystroke_over_the_whole_corpus_stays_in_budget`, which
|
||
skips when `corpus/` is not checked out and asserts a deliberately loose 150 ms
|
||
per request — it is there to catch an order of magnitude, not to pin a number.
|
||
|
||
**Build (once per index rebuild: `initialize`, `didSave`, a settings change):**
|
||
|
||
| Step | Time |
|
||
|---|---|
|
||
| `WorkspaceIndex::build` (pre-existing) | 165 ms |
|
||
| `Candidates::build` — the new tables | **94 ms** (word harvest alone: 88 ms) |
|
||
| whole `open_roots`: walk + read + index + tables | 344 ms |
|
||
|
||
The new tables therefore add ~57 % to what the index build already cost, and
|
||
~27 % to the whole rebuild. The word harvest is one extra `tokenize` pass over
|
||
the same sources the index reads; it is not shared with the index's own lex
|
||
because `WorkspaceIndex::build` does its lexing privately, and asking it to hand
|
||
back token streams would be a new cross-crate contract for one caller.
|
||
|
||
Deduplicating *during* the harvest rather than after it matters more than the
|
||
lexing does: the corpus holds ~900 k identifier tokens and 16 750 distinct
|
||
identifiers, and copying every token only to sort the copies away cost 197 ms
|
||
against the 88 ms it costs now.
|
||
|
||
**Tables and memory:**
|
||
|
||
| Table | Entries | Heap |
|
||
|---|---|---|
|
||
| index names (units + members) | 7 728 | |
|
||
| `` `define`` names | 361 | |
|
||
| project words | 16 750 | |
|
||
| all three | | **~1.4 MiB** |
|
||
|
||
**Per request (what a keystroke costs):**
|
||
|
||
| Case | Worst of ten, release | Worst of ten, debug |
|
||
|---|---|---|
|
||
| typed prefix, mid-expression | **298 µs** | 1.3 ms |
|
||
| empty prefix (explicit invoke — every tier matches, the cap does the work) | **212 µs** | 1.1 ms |
|
||
|
||
A prefix lookup itself is ~76 ns (1 000 lookups in 76 µs): the tables are
|
||
sorted case-insensitively, so a match is a `partition_point` and then a
|
||
`take_while` over one contiguous run. Nothing allocates a lowercase copy —
|
||
`lower_cmp` compares byte iterators.
|
||
|
||
The one request that is *not* microseconds is a module-item position, which
|
||
still parses up to 64 defining files. That is M4's cost, unchanged and
|
||
separately capped.
|
||
|
||
## Version 0.3.0
|
||
|
||
Every place `tools/RELEASING.md` says the version lives, plus the install
|
||
examples it does not:
|
||
|
||
- [x] `Cargo.toml` `[workspace.package] version` → `0.3.0` (all eight crates
|
||
inherit it via `version.workspace = true`)
|
||
- [x] `Cargo.lock` regenerated by `cargo check --workspace` — eight entries
|
||
- [x] `editors/vscode/package.json` `"version"`
|
||
- [x] `editors/vscode/package-lock.json` `"version"` in **both** places (top
|
||
level and `packages[""]`)
|
||
- [x] `README.md` — the `code --install-extension dist/lucisv-0.3.0.vsix` example
|
||
- [x] `editors/vscode/README.md` — both install examples
|
||
- [x] `tools/RELEASING.md` — the `dist/` listing, the install commands, the
|
||
`git tag v0.3.0` example and the appendix's publish commands
|
||
- [x] `CHANGELOG.md` — a `0.3.0 — 2026-08-24` section in the existing voice:
|
||
one paragraph per area (filelists, rename, ports, module hinting,
|
||
completion, editors), each linking to its feature README
|
||
- [x] Verified: `target/debug/lucisv --version` → `lucisv 0.3.0`. Nothing
|
||
hard-codes a version string in Rust; `lucisv --version` and the server's
|
||
`serverInfo.version` both read `env!("CARGO_PKG_VERSION")`.
|
||
- [x] Verified: `node editors/vscode/smoke.js target/debug/lucisv-server` →
|
||
`smoke: OK`
|
||
|
||
Deliberately **not** touched: the `0.2.0` section of `CHANGELOG.md`,
|
||
`docs/features/release-prep/README.md` and `TODO.md`'s release entry — those
|
||
record what happened at 0.2.0 and are not install instructions. The literal
|
||
`0.2.0` strings in `lucisv_core/src/cache.rs`'s and `lucisv/tests/cli.rs`'s
|
||
corrupt-cache fixtures are deliberately malformed lines whose version field is
|
||
incidental; they exercise the parser, not the version.
|
||
|
||
## Status / TODO
|
||
|
||
- [x] `KEYWORDS` factored out of the lexer's table without changing lexing
|
||
- [x] `candidates.rs`: the two project-wide tables, built with the index
|
||
- [x] Tier 1 — visible declarations, with kinds and declaration lines
|
||
- [x] Tier 2 — index names and `` `define`` names, with the backtick ruling
|
||
- [x] Tier 3 — keywords
|
||
- [x] Tier 4 — token-harvested project words, current buffer overlaid live
|
||
- [x] Comment/string gate, both directions
|
||
- [x] Dedup across tiers, `sortText` tier ordering, prefix filter, cap +
|
||
`isIncomplete`
|
||
- [x] Every M4 completion test green, module skeletons byte-identical
|
||
- [x] e2e stdio round trip for the new tiers
|
||
- [x] Corpus performance measured and guarded
|
||
- [x] Version 0.3.0 across the workspace, the extension and the docs
|
||
- [x] `cargo fmt --all -- --check`, `cargo clippy --all-targets`,
|
||
`cargo test --workspace` all clean; `smoke.js` OK
|
||
|
||
## Work log
|
||
|
||
- **2026-08-24 (dev)** — implemented.
|
||
|
||
**Keyword list.** `vlog_parser/src/token.rs`'s `is_keyword` was a 181-arm
|
||
`matches!`. Rather than write a second copy of the list, the whole thing is
|
||
now one `keywords![...]` invocation of a local `macro_rules!` that expands to
|
||
both `pub const KEYWORDS` and `pub fn is_keyword` — so `is_keyword` is still a
|
||
`matches!` over literals (no linear scan on the lexer's hot path) and the two
|
||
cannot drift. The explanatory comments inside the list survived the move. Two
|
||
tests added in `token.rs`; the parser suite (185 → 187 lib tests, all four
|
||
targets) is green.
|
||
|
||
**Tables (`crates/lucisv_server/src/candidates.rs`, new).** `Candidates` holds
|
||
three sorted vectors — index names, macro names, project words — built in
|
||
`Workspace::rebuild_index` from the same `collect_sources()` list the index
|
||
gets. That is what makes the scope ladder and the open-buffer-beats-disk rule
|
||
apply to completion for free, with no second walk. Lookup is
|
||
`partition_point` on a case-insensitive comparator, returning a slice.
|
||
|
||
**Tiers (`completion.rs`).** `completions` grew a gate
|
||
(`in_comment_or_string`, plus "no tokens, no answer") and five tier functions
|
||
feeding one `Items` builder that owns dedup, the cap and `isIncomplete`.
|
||
M4's `completions` body is now `module_tier`, unchanged except that it is
|
||
conditional instead of an early return, and its item gained a `sortText`.
|
||
`typed_word` grew two fields: `backtick` (was the run preceded by one) and
|
||
`at_line_start` (M4's second gate, now used only by tier 0).
|
||
|
||
**Decisions worth flagging to the lead:**
|
||
1. **M4's "nothing is offered" tests had to change meaning.** Nine of them
|
||
asserted `completions(...).is_none()` at positions where general
|
||
completion is exactly what a user wants (mid-expression, inside an
|
||
`always` block, inside a function). They are now "no *skeleton* is
|
||
offered here", checked on `sortText`'s tier digit; the skeleton text and
|
||
the module gate are untouched, and the e2e assertions changed the same
|
||
way. This is the one place the milestone genuinely broadens behaviour
|
||
M4 shipped, and it is what the M5 brief asked for — recorded so it is
|
||
reviewed rather than assumed.
|
||
2. **The cap went 64 → 512** for the response as a whole, with the module
|
||
tier keeping 64. Arithmetic under *The cap*.
|
||
3. **The backtick ruling** — only macros after a backtick, bare macro names
|
||
without one, no backtick ever invented. Under *The backtick ruling*.
|
||
4. **`SystemIdent` tokens (`$display`, `$clog2`) are harvested as words.**
|
||
They are identifiers used in the project and `$` is already an
|
||
identifier character as far as the typed-word scan is concerned, so
|
||
`$clo|` completes. Cheap, and it is what "identifiers used anywhere in
|
||
the project" says.
|
||
5. **A buffer that does not lex is declined outright** rather than answered
|
||
without a comment/string gate.
|
||
|
||
**Performance work.** Two measured fixes, both from the corpus harness rather
|
||
than from guessing: deduplicating the word harvest during collection (197 ms
|
||
→ 88 ms) and checking `Items::full()` before building an item (8.5 ms → 212 µs
|
||
on the empty-prefix request). Numbers under *Performance*.
|
||
|
||
**Version bump** per `tools/RELEASING.md`, checklist above, plus a
|
||
`CHANGELOG.md` 0.3.0 section covering M1–M5.
|
||
|
||
**Suite**: 1 232 → 1 262 workspace tests, all green; `cargo fmt --all --
|
||
--check` and `cargo clippy --all-targets` clean; `node
|
||
editors/vscode/smoke.js target/debug/lucisv-server` → `smoke: OK`.
|
||
|
||
## QA log
|
||
|
||
**2026-08-24 — QA agent.**
|
||
|
||
### Gates
|
||
|
||
- `cargo fmt --all -- --check` — clean.
|
||
- `cargo clippy --all-targets` — clean, zero warnings, workspace-wide.
|
||
- `cargo test --workspace` — green, **1262** tests (summed the per-crate
|
||
`test result` lines myself rather than trusting the printed total) —
|
||
matches the Work log's `1232 → 1262` claim exactly.
|
||
- `node editors/vscode/smoke.js target/debug/lucisv-server` — `smoke: OK`.
|
||
- `cargo build -p lucisv` then `target/debug/lucisv --version` → `lucisv 0.3.0`.
|
||
|
||
All gates: **pass, claims confirmed.**
|
||
|
||
### Priority 1 — the keyword-table refactor (`vlog_parser::token`)
|
||
|
||
Not eyeballed: extracted both word lists programmatically (regex over
|
||
`is_keyword`'s old `matches!` arms vs. the new `keywords![...]` invocation)
|
||
and diffed the two lists as Python sets and as ordered lists.
|
||
|
||
- Old list: 181 words, no duplicates. New list: 181 words, no duplicates.
|
||
- `old_set == new_set` → **True**. `old_words == new_words` (order too) →
|
||
**True**. Nothing added, dropped, reordered or typo'd.
|
||
- Read the macro expansion by hand: `matches!(s, $($word)|*)` expands to
|
||
exactly the same `matches!(s, "module" | "macromodule" | ...)` chain the
|
||
old hand-written function was — confirmed textually, not just by claim —
|
||
so the lexer's hot path really is byte-for-byte the same generated code.
|
||
- `crates/vlog_parser/src/lib.rs`'s diff is the expected one-line
|
||
`pub use token::KEYWORDS;`.
|
||
|
||
**Confirmed exactly as claimed.**
|
||
|
||
### Priority 2 — the nine repurposed M4 tests + the module-skeleton gate
|
||
|
||
Counted precisely rather than trusting "nine": `grep -c '.is_none()'` in the
|
||
old (`git show HEAD:.../completion.rs`) test module gives **8** call sites
|
||
across 6 functions (one of them a 4-case loop), plus **1** more in
|
||
`e2e.rs`'s `completion_and_signature_help_round_trip_over_the_wire` (the
|
||
`assert!(inside["result"].is_null())` at the always_comb position) — **9
|
||
total**, matching the claim exactly once both files are counted together.
|
||
|
||
Diffed the gate itself: `at_module_item`, `enclosing_scopes`,
|
||
`is_procedural`, `balanced`, and the `ITEM_SCOPES`/`NOT_ITEM_SCOPES`/
|
||
`PROCEDURAL`/`STATEMENT_END` constants are **byte-identical** between
|
||
`git show HEAD:crates/lucisv_server/src/completion.rs` and the working tree —
|
||
only a doc comment above `completions` changed (`"module completions"` →
|
||
`"completions"`). The gate that decides *where* a skeleton may appear was
|
||
not touched.
|
||
|
||
Confirmed each of the 9 sites was repurposed consistently: the 8 unit-test
|
||
sites now assert `skeletons(&items).is_empty()` (module-tier-only, read off
|
||
`sortText`'s digit) rather than `completions(...).is_none()`, and the
|
||
e2e site now asserts no item has a `sortText` starting with `'0'` while the
|
||
general tiers *do* answer (`items.iter().any(|i| sortText doesn't start
|
||
with '0')`) — i.e. it went from "nothing at all" to "everything except a
|
||
skeleton", which is exactly the milestone's stated broadening.
|
||
|
||
**Confirmed exactly as claimed.**
|
||
|
||
### Attacks — comment/string exclusion
|
||
|
||
All of the following pass exactly as the feature promises (verified by
|
||
reading `in_comment_or_string`/`in_comment` and running the dev's own
|
||
tests, which cover every case listed in the brief):
|
||
|
||
- Identifier only in a comment, or only in a string → not a candidate
|
||
(`a_name_that_only_a_comment_or_a_string_holds_is_never_a_candidate`,
|
||
and independently in `candidates.rs`'s
|
||
`words_come_from_tokens_so_comments_and_strings_contribute_nothing`).
|
||
- Cursor inside a `//` comment, a `/* */` comment, and a string literal →
|
||
no response (`nothing_is_offered_inside_a_comment_or_a_string`, all four
|
||
sub-cases).
|
||
- Cursor immediately after a block comment's `*/` on the same line → code
|
||
again, completions answer (`the_byte_after_a_block_comment_is_code_again`).
|
||
- An unterminated block comment mid-file → `doc.tokens.is_empty()`, decline
|
||
outright (`a_buffer_that_does_not_lex_is_declined_rather_than_guessed_at`).
|
||
- Identifier in a string in an **unsaved** buffer overlay: structurally
|
||
guaranteed rather than merely tested — `word_tier`'s live scan of
|
||
`doc.tokens` filters to `Ident | SystemIdent` (`completion.rs:250-254`),
|
||
the same `TokenKind` gate `candidates.rs::is_word` uses for the
|
||
persisted table, so a string's contents can never surface as an `Ident`
|
||
token regardless of whether the buffer is saved.
|
||
|
||
No findings here.
|
||
|
||
### Attacks — the backtick
|
||
|
||
- `` `de<cursor> `` completes defines with the range including the
|
||
backtick, no doubling — dev's own
|
||
`a_backtick_offers_macro_names_and_only_macro_names` pins the exact
|
||
replaced range; re-verified by hand.
|
||
- Backtick with nothing typed after it (`` `<cursor> ``, no macros defined)
|
||
→ 0 items (probed). With macros defined → all of them, sorted
|
||
(probed: `` `<cursor> `` against `ALPHA`/`BETA` → `["`ALPHA", "`BETA"]`).
|
||
- Backtick inside a comment → `None` (probed: the comment gate in
|
||
`completions` runs before the backtick branch is ever reached, so this
|
||
is structural, not incidental).
|
||
- **Directive keywords (`ifdef`, `endif`, `undef`, `include`, `timescale`,
|
||
…) get no completion help anywhere — LOW, not filed as blocking.**
|
||
Probed: `` `ifd<cursor> `` (typing toward `` `ifdef ``) → `None`.
|
||
Mechanism: `` `ifdef FOO `` lexes as one `TokenKind::Directive` token
|
||
(`vlog_parser/src/token.rs`), so `ifdef`/`endif`/etc. are never `Ident`
|
||
tokens (can't reach the word tier) and are deliberately absent from
|
||
`KEYWORDS` (the lexer's directive handling is a separate mechanism from
|
||
its keyword table, unchanged by this milestone). Typing a backtick then
|
||
a directive name routes into the backtick branch's macro-only answer,
|
||
which correctly finds no macro named `ifd*` and returns nothing. This
|
||
isn't a regression — there was no completion at all before M5 — and it
|
||
isn't inside this milestone's stated scope (keywords + project
|
||
identifiers), but it's a real, common gap (`` `ifdef `` is about as
|
||
frequent as any keyword) that the README's *Assumptions* and *The
|
||
backtick ruling* sections don't mention at all. Worth a line in the
|
||
README disclosing it, or a follow-up milestone; not blocking M5.
|
||
|
||
### Attacks — tiers, dedup, case
|
||
|
||
- A name that is both a local declaration and a project word: offered
|
||
**once**, tier 1, real kind — dev's own
|
||
`a_name_that_is_both_in_scope_and_a_project_word_is_offered_once`;
|
||
re-derived independently with a `Data`/`data` pair (see below).
|
||
- Module name at item position → skeleton (tier 0); at expression
|
||
position → offered as a plain tier-2 index item, `CompletionItemKind::
|
||
MODULE`, `PlainText`, no snippet (probed directly: `sub` at
|
||
`assign x = su|` comes back as tier `'2sub'`, not a skeleton). Correct —
|
||
matches "a name is a name wherever it is written" for every tier but 0.
|
||
- Case-insensitive **prefix** vs. case-sensitive **identity**: probed with
|
||
`logic data;` (local) and a project file declaring `logic Data;`
|
||
elsewhere. Typing `dat` (prefix, case-insensitive) surfaces **both**
|
||
`data` and `Data` as separate items — the prefix match doesn't collapse
|
||
them, and dedup (label-keyed) correctly treats them as different SV
|
||
identifiers. Exactly as required.
|
||
- The cap keeps the **best** tiers, not an arbitrary cut: probed a
|
||
workspace where tier 2 alone (600 `localparam`s in one package) exceeds
|
||
`LIMIT` on an empty prefix — response is exactly 512 items, all from
|
||
tier 2 (`has_word_tier: false`), `isIncomplete: true`. Consistent with
|
||
the tiers being filled in strict order and each one's `Items::full()`
|
||
guard stopping it immediately; not re-derived from scratch since the
|
||
dev's own `a_full_response_is_truncated_and_says_it_is_incomplete` and
|
||
the corpus test's "empty prefix fills the response to exactly LIMIT"
|
||
already pin the same mechanism.
|
||
- Empty prefix at item position: 187 items total, 2 module skeletons
|
||
(`sub`, and — see next finding — `top` itself).
|
||
|
||
**LOW, informational, not blocking — a module can offer itself as a
|
||
self-instantiation skeleton.** Probed: cursor at item position inside
|
||
`module top` with nothing typed → tier-0 skeletons offered are `["sub",
|
||
"top"]`. `module_tier` calls `vlog_refactor::module_names(ws.index(), "")`
|
||
unfiltered by the enclosing module, and that function is M4's, unchanged
|
||
(confirmed: `module_tier`'s body is untouched by this milestone). Not a
|
||
new bug — an M4-era gap in `vlog_refactor::module_names` — but M5 makes it
|
||
far easier to hit in practice: an explicit empty-prefix invoke
|
||
(VS Code's Ctrl+Space) at item position is a completion this milestone
|
||
specifically added support for (see *The cap*'s "empty prefix" arithmetic),
|
||
and it now surfaces "instantiate `top` inside `top`" as a real, clickable
|
||
suggestion. Filing against `vlog_refactor::module_names`/`instantiate.rs`,
|
||
not against this milestone's own code, since nothing in `completion.rs` or
|
||
`candidates.rs` introduced it.
|
||
|
||
### Attacks — scope ladder, invalidation, cap arithmetic
|
||
|
||
- 2-file + filelist fixture: dev's own
|
||
`a_file_outside_the_filelist_contributes_no_words` builds exactly this
|
||
(`files.f` listing only `listed.sv`) and confirms `word_unlisted` never
|
||
appears. Read the mechanism independently: `Candidates::build` is fed
|
||
the same `sources` list `rebuild_index` already restricted by the
|
||
filelist, so this is structural, not per-tier filtering.
|
||
- Which event updates candidates: confirmed by reading `server.rs` —
|
||
`reindex()` (which calls `Workspace::rebuild_index`, which rebuilds
|
||
`Candidates`) is called from `DidSaveTextDocument`, from `DidOpen` only
|
||
when there is no workspace root, and from `open_roots` at `initialize`.
|
||
`DidChangeTextDocument` does **not** call it. This matches the README's
|
||
"rebuilds on `initialize` and `didSave`" claim exactly — not "on every
|
||
edit". The buffer being typed in is still live because `word_tier`
|
||
separately re-scans `doc.tokens` (recomputed per `didChange`) on every
|
||
request, independent of the table. Probed the negative case the dev's
|
||
own test doesn't cover: edited *another* buffer without calling
|
||
`rebuild_index()` — the new word (`ov_in_buffer`) is correctly absent
|
||
(only the current buffer's own half-typed `ov` shows up, from the live
|
||
per-request scan). The dev's
|
||
`another_open_buffer_overlays_disk_once_the_index_is_rebuilt` shows the
|
||
positive half (present *after* `rebuild_index()`); together they pin
|
||
the exact rule stated in the README.
|
||
- Cap arithmetic isn't quadratic: ran the corpus budget test in release
|
||
(below). Separately probed a worst-case shape the corpus doesn't
|
||
naturally produce — sparse scope/index/keyword tiers (so `word_tier`'s
|
||
own `items.full()` guard does *not* short-circuit) against an
|
||
artificially huge word table (30 003 distinct identifiers, one file) —
|
||
512 items, `isIncomplete: true`, in **1.66 ms** (release build). Not
|
||
quadratic (n log n from the sort, bounded well under any budget this
|
||
test would need to guard), and not a finding: `word_tier` does collect
|
||
and sort the *whole* prefix-matched slice before applying the cap
|
||
rather than stopping at remaining capacity, which is a real but minor
|
||
inefficiency (the guard only short-circuits the *whole tier*, not a
|
||
partial one) — worth knowing about, not worth blocking on at these
|
||
numbers.
|
||
|
||
### Version 0.3.0
|
||
|
||
- `grep -rn "0.2.0"` over the whole tree (excluding `target/`): every hit
|
||
is one the dev's README lists as deliberately untouched — `CHANGELOG.md`'s
|
||
`0.2.0` history section, `TODO.md`'s release-prep line,
|
||
`docs/features/release-prep/README.md`'s own history, and the
|
||
malformed-cache-line fixtures in `lucisv_core/src/cache.rs` and
|
||
`lucisv/tests/cli.rs`. No stray `0.2.0` anywhere else.
|
||
- `cargo metadata` — all eight workspace crates report `0.3.0`.
|
||
`editors/vscode/package.json` and **both** places in
|
||
`package-lock.json` (top level and `packages[""]`) — `0.3.0`.
|
||
`Cargo.toml`'s `[workspace.package] version` — `0.3.0`.
|
||
`target/debug/lucisv --version` → `lucisv 0.3.0`.
|
||
- `CHANGELOG.md`'s `0.3.0` section: read against what actually shipped
|
||
(filelists, rename, ports, module hinting, completion, editors) —
|
||
accurate, no overclaiming; the completion paragraph's "860 real-world
|
||
files answer a request in about 300 µs" matches the measured number
|
||
below almost exactly.
|
||
|
||
**Confirmed exactly as claimed.**
|
||
|
||
### Performance
|
||
|
||
Re-ran `a_keystroke_over_the_whole_corpus_stays_in_budget` in `--release`
|
||
against the checked-out `corpus/` (860 files):
|
||
|
||
```
|
||
corpus: 860 files, 16750 words, 7728 index names;
|
||
index+tables built in 344.538ms;
|
||
worst request 296.917µs typed / 222.625µs empty
|
||
```
|
||
|
||
Matches the README's table almost exactly (298 µs / 212 µs claimed vs.
|
||
297 µs / 223 µs measured here — within normal run-to-run noise on a
|
||
loaded machine) and the file/word/index counts match exactly (860 / 16 750
|
||
/ 7 728). **Confirmed, not overclaimed.**
|
||
|
||
### e2e — real server binary over stdio
|
||
|
||
Ran the dev's own `crates/lucisv_server/tests/e2e.rs` tests as part of the
|
||
full-suite gate (both pass). Independently drove `target/debug/lucisv-server`
|
||
over stdio by hand (a small Python LSP client, not committed anywhere) for
|
||
the one case the dev's own e2e test doesn't explicitly assert on:
|
||
|
||
- **Keyword completion over the wire** — `initialize` → `didOpen` with
|
||
`assign x = alw` → `textDocument/completion` at the cursor. Real
|
||
response: 5 items, keyword items `always`/`always_comb`/`always_ff`/
|
||
`always_latch`, each with `"kind": 14` (LSP `Keyword`), `"sortText":
|
||
"3always"` etc., and a `textEdit.range` matching exactly the typed
|
||
`alw`. Confirms the keyword tier works correctly end-to-end.
|
||
- Project-word completion from another file, and inside-comment decline:
|
||
already covered by the dev's own
|
||
`keyword_and_project_completion_round_trip_over_the_wire`, which I
|
||
re-ran in isolation (`cargo test -p lucisv_server --test e2e
|
||
keyword_and_project_completion -- --nocapture`) — passes standalone.
|
||
|
||
**LOW, informational — the Status/TODO line "e2e stdio round trip for the
|
||
new tiers" (plural) is slightly optimistic.** `e2e.rs` asserts scope
|
||
(tier 1), index/macro (tier 2), word (tier 4), and the comment decline
|
||
over the wire, but never asserts a keyword-tier (tier 3) item by label or
|
||
`kind` — only that no item's `sortText` starts with `'0'`. The keyword
|
||
tier itself is thoroughly unit-tested
|
||
(`every_keyword_the_lexer_knows_is_offered`,
|
||
`the_keyword_tier_is_exactly_the_lexers_list`) and, per the probe above,
|
||
does work correctly over the wire — this is a documentation-accuracy /
|
||
test-coverage nit, not a functional gap. Not fixed (adding the assertion
|
||
is a one-line addition to the dev's existing e2e test, left for the dev
|
||
or a follow-up rather than touching test files outside a small,
|
||
unambiguous fix).
|
||
|
||
### Cleanup
|
||
|
||
All probing was done with temporary `qa_probe_*` `#[test]` functions added
|
||
to `crates/lucisv_server/src/completion.rs`'s existing `tests` module, run
|
||
with `--nocapture`, then fully reverted. Verified clean:
|
||
`grep -rn qa_probe crates/` — zero hits; `git diff --stat` for this file
|
||
matches the pre-QA baseline exactly (898 changed lines, same as
|
||
`git status` showed before QA started); final `cargo fmt --all -- --check`
|
||
+ `cargo clippy --all-targets` + `cargo test --workspace` (1262 passed)
|
||
re-run clean after cleanup.
|
||
|
||
### Verdict
|
||
|
||
**Ship.** Both priority items (the keyword-list refactor and the nine
|
||
repurposed tests) are verified programmatically, not by eyeballing, and
|
||
hold up exactly as claimed. Every other claim in the Work log — the three
|
||
sorted tables, the five tiers, the backtick ruling, the cap arithmetic,
|
||
the performance numbers, the version bump — checked out under direct
|
||
attack. Three LOW/informational findings, none blocking:
|
||
|
||
1. Preprocessor directive names (`` `ifdef ``, `` `endif ``, …) get no
|
||
completion assistance anywhere — a real, common gap, undisclosed in
|
||
the README, but out of this milestone's stated scope
|
||
(`vlog_parser::token`'s directive handling, untouched by M5).
|
||
2. A module can offer itself as a self-instantiation skeleton at an
|
||
empty-prefix, item-position completion — pre-existing to
|
||
`vlog_refactor::module_names` (M4), newly easy to trigger via M5's
|
||
empty-prefix support.
|
||
3. The e2e suite's "new tiers" coverage doesn't explicitly assert the
|
||
keyword tier by label/kind over the wire, though it works correctly
|
||
(independently verified by hand against the real binary).
|
||
|
||
No fixes applied to feature code — nothing found rose to "small,
|
||
unambiguous" (typo/missing assertion) territory; all three are judgment
|
||
calls for the dev/lead. No commits, no edits to `TODO.md` or the umbrella
|
||
`docs/features/refactor/README.md`.
|
||
|
||
## Review
|
||
|
||
**2026-08-24 — lead.** Reviewed after QA's ship verdict — the first
|
||
milestone through with no rework round; gates run independently (1262
|
||
tests, 0 failures, clippy silent). The keyword-table refactor was verified
|
||
set- and order-identical programmatically, the five-tier/sortText design is
|
||
the boring right shape, and 212–298 µs per keystroke over the 860-file
|
||
corpus with a budget test guarding it is exactly the performance story
|
||
wanted. The nine repurposed M4 tests are a genuine, intended broadening
|
||
(general completion where skeletons were rightly refused), with the
|
||
skeleton gate itself byte-identical. Dev's backtick ruling (never invent
|
||
punctuation) and decline-on-unlexable-buffer are accepted as argued.
|
||
QA's three LOW findings, ruled: (1) no completion help on preprocessor
|
||
directive words — accepted gap, now named in the umbrella backlog;
|
||
(2) self-instantiation skeletons — pre-existing M4 nit, backlog;
|
||
(3) e2e keyword-tier assertion — nice-to-have, not required. QA's
|
||
transparency note about a briefly clobbered-and-restored working file is
|
||
appreciated; the independent gate run confirms the tree. Accepted; M5 and
|
||
the 0.3.0 bump are checked off in the umbrella plan and TODO.md §8.
|