Files
lucioandClaude Fable 5 cadb4319e4
ci / checks (push) Successful in 45s
ci / corpus (push) Successful in 19s
Inline instantiation: the popup names the module, the ghost writes the rest
Two levels, sized for opentitan. Tier 0 of the completion popup stops
planning skeletons (up to 64 file reads + header parses per keystroke)
and offers module names alone; once the identifier at the cursor exactly
matches an indexed module, textDocument/inlineCompletion ghosts the full
instantiation — every parameter, every port, each a tabstop, in-scope
signals auto-connected — planned once through the existing header-slice
path and the FileView cache. Candidates::has_module is the per-keystroke
probe: a case-sensitive binary search whose str-order premise is pinned.
lucisv.inlineInstantiation (default on) gates it, independent of
inlineTemplates.

Measured on opentitan: non-matching keystroke 0.10-0.17 ms warm, ghost
0.6-1.1 ms for aes (14 params/16 ports), 2.5 ms cold for the
112-parameter top_earlgrey; popup module tier reads no files at all.

Lead corrections at merge: four doc references to a lucisv/instantiate
command that never existed, replaced by the honest gap (topo 2.9-19: no
skeleton path for clients without inlineCompletion); extension and nvim
README docs delivered.

docs/features/inline-instantiation/README.md; TODO.md section 12.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-30 14:17:16 -07:00

747 lines
41 KiB
Markdown

# completion-templates
M6 of the refactoring plan (`docs/features/refactor/README.md`): **statement
and item templates** in the server's completion response, plus the **0.4.0
version bump**.
## Goal
Make the completion list finish the *construct*, not the word. Typing `if`
inside an `always` block should offer `if begin/end` and, on accept, write
```systemverilog
if (cond) begin
end
```
at the line's own indentation, with `cond` selected and TAB moving into the
body — and the same for `if/else`, `else if`, `case`, the loops, the `always`
family, `initial` and the everyday declarations. This is M5's completion
machinery with one tier added: the templates are a sixth source of items,
ranked between what the code declares and the bare keywords, and gated by two
questions the server can already answer from the token stream — *may a
statement be written here?* and *may a module item?* Nothing is offered that
the buffer's own dialect would reject, and every template's untouched expansion
is fed to lucisv's own parser by the test suite, because a template that hands
the user a red squiggle from our own server is worse than no template.
Because this lives in the server, Vim gets it too — which is the reason it is
here rather than in `editors/vscode/snippets/*.json`, where nine of these
templates used to live. Those are gone; see *Reconciliation* below.
## Assumptions
- **A label that is not a keyword is a feature, not a workaround.** Dedup in
`Items` is by label, so a template labelled `if` would have swallowed the
keyword `if`. Every label is prose (`if begin/end`, `always_ff with reset`,
`logic [N:0] name;`) and `filterText` carries the word the user actually
types, so both items appear and the client still matches the template on
`if`. `no_label_is_a_bare_keyword_and_no_label_repeats` pins it.
- **Position is judged over the token stream, not a parse.** The statement gate
reuses M4's `pairs::analyze` scope chain — the same heuristic
`at_module_item` has always run on — so a half-typed buffer costs nothing
extra and an unbalanced one still answers. Both gates are wrong in the same
directions the M4 README already records; the failure mode is a template not
offered, never a template offered inside a port list.
- **A template's defaults are chosen so the untouched expansion parses.**
`if (${1:cond})`, not `if ($1)`: a hole with no default expands to nothing,
and `if () begin` is not Verilog. This is the editor-snippets assumption
restated for generated text, and it is verified rather than assumed —
`every_untouched_expansion_parses` plants every template where its gate says
it may be written and asserts `parse_source_tolerant` reports nothing.
- **`$` in a body is snippet syntax, not Verilog.** The other
editor-snippets lesson: VS Code substitutes an unknown `$NAME` with the empty
string and says nothing, so an unescaped `$finish` in a body would vanish
invisibly. No system task appears in any body today, and
`every_hole_is_a_tabstop_the_snippet_grammar_reads` fails the build if one is
added without an escape.
- **`lucisv.indent` (default 2) is the indent step**, and the line's own leading
whitespace is the base — the same `Layout` M4's skeletons use, resolved the
same way and with the same deviation from `lucisv.toml` recorded there. Because
the base is baked in, the item must tell the client not to indent it again:
see *The indentation contract* below.
- **A template is offered on prefix, not on fuzzy match.** The server filters
with `starts_with_ignore_case` on the template's prefix exactly as the other
tiers filter on a name, so `alw` finds every `always*` template and `wh`
finds `while`. What the *client* does with the list on top of that is the
client's business (M5's "`sortText` is a nudge" assumption, unchanged).
## Handshakes
- **New module `crates/lucisv_server/src/templates.rs`** — the registry, the
dialect rule and the renderer. It is data plus one function; nothing in it
knows about LSP. `completion.rs` owns the tier, the gates and the items.
- **Consumes `vlog_refactor::Layout`** — M4's `{ base, step }`, reused rather
than re-declared, so a skeleton and a template are indented by the same type.
Nothing in `vlog_refactor` was touched.
- **Consumes `lucisv_server::pairs`** through `completion::enclosing_scopes`,
exactly as M4 does. No change to `pairs.rs`.
- **Changed inside `completion.rs`, for other tiers to know about:**
- **The tier digits moved.** Templates are tier `3`; keywords are now `4`
and project words `5`. The only assertion outside this module that reads a
digit is `e2e.rs`'s word-tier check, updated with a comment saying why.
- `at_module_item` now takes the scope chain instead of computing it, so the
two gates share one `pairs::analyze` call; its logic is unchanged.
- `Word` grew `statement_head` (see *The gates*).
- **`editors/vscode`**: nine static snippets removed (below). No manifest
change, no `extension.js` change, no new setting, no new capability —
`snippetSupport` is read exactly where M4 read it.
- **No new dependency.**
## The templates
`label` is what the list shows, `prefix` is what the user types, and the body
is written as indented lines that the renderer lays out at the site's own
indentation. `$0` is where the cursor lands, which is the empty body line in
every block template.
**Both dialects:**
| Label | Prefix | Gate | Body |
|---|---|---|---|
| `if begin/end` | `if` | statement | `if (${1:cond}) begin` / `$0` / `end` |
| `if/else` | `if` | statement | `if (${1:cond}) begin` / `$2` / `end else begin` / `$0` / `end` |
| `else if` | `else` | statement (else-tail) | `else if (${1:cond}) begin` / `$0` / `end` |
| `else begin/end` | `else` | statement (else-tail) | `else begin` / `$0` / `end` |
| `case/endcase` | `case` | statement | `case (${1:sel})` / `${2:value}: $0;` / `default: ;` / `endcase` |
| `casez/endcase` | `casez` | statement | as `case`, with `casez` |
| `while begin/end` | `while` | statement | `while (${1:cond}) begin` / `$0` / `end` |
| `initial begin/end` | `initial` | item | `initial begin` / `$0` / `end` |
**SystemVerilog only (`.sv`, `.svh`):**
| Label | Prefix | Gate | Body |
|---|---|---|---|
| `for loop` | `for` | statement | `for (int ${1:i} = 0; $1 < ${2:N}; $1++) begin` / `$0` / `end` |
| `always_ff @(posedge clk)` | `always_ff` | item | `always_ff @(posedge ${1:clk}) begin` / `$0` / `end` |
| `always_ff with reset` | `always_ff` | item | `always_ff @(posedge ${1:clk} or negedge ${2:rst_n}) begin` / `if (!$2) begin` / `${3:q} <= '0;` / `end else begin` / `$0` / `end` / `end` |
| `always_comb begin/end` | `always_comb` | item | `always_comb begin` / `$0` / `end` |
| `logic name;` | `logic` | declaration | `logic ${1:name};` |
| `logic [N:0] name;` | `logic` | declaration | `logic [${1:7}:0] ${2:name};` |
| `localparam int NAME = 0;` | `localparam` | declaration | `localparam int ${1:NAME} = ${2:0};` |
| `parameter int NAME = 0;` | `parameter` | declaration | `parameter int ${1:NAME} = ${2:0};` |
**Verilog only (`.v`, `.vh`, and any buffer with no file name):**
| Label | Prefix | Gate | Body |
|---|---|---|---|
| `for loop` | `for` | statement | `for (${1:i} = 0; $1 < ${2:N}; $1 = $1 + 1) begin` / `$0` / `end` |
| `always @(posedge clk)` | `always` | item | `always @(posedge ${1:clk}) begin` / `$0` / `end` |
| `always @(posedge clk or negedge rst_n)` | `always` | item | the reset flavour, `${4:1'b0}` instead of `'0` |
| `always @(*)` | `always` | item | `always @(*) begin` / `$0` / `end` |
| `reg name;` | `reg` | declaration | `reg ${1:name};` |
| `reg [N:0] name;` | `reg` | declaration | `reg [${1:7}:0] ${2:name};` |
| `wire name;` | `wire` | declaration | `wire ${1:name};` |
| `wire [N:0] name;` | `wire` | declaration | `wire [${1:7}:0] ${2:name};` |
| `localparam integer NAME = 0;` | `localparam` | declaration | `localparam integer ${1:NAME} = ${2:0};` |
| `parameter integer NAME = 0;` | `parameter` | declaration | `parameter integer ${1:NAME} = ${2:0};` |
Sixteen templates in a `.sv` file, eighteen in a `.v` one.
Two deliberate details in that table. **The parameter templates name a type**
(`int` / `integer`) because lucisv's own `explicit-parameter-storage-type` rule
flags `localparam NAME = 0;` — a template that trips our own linter on insert
is not a template worth shipping, and it was the untouched-expansion check that
surfaced it. **`casez` but not `casex`**: `casez` costs one registry entry and
is what a decoder is actually written with, while `casex` is the one most style
guides tell you not to use, and an unused item is noise in the list.
## The gates
Three gates, all decided before any item is built, so a request at a position
where no template belongs costs one `pairs::analyze` and nothing else — and a
request in the middle of an expression does not even cost that, because neither
gate can be true unless the word starts a statement.
**Item position** is M4's `at_module_item`, unchanged: the innermost open scope
is a `module`/`interface`/`program`/`generate`/`begin`, no `function`/`class`/
`case`/`fork` is in the chain, the outermost `begin` is not procedural, and the
parentheses are balanced. An `always_ff` inside an `always_comb` is exactly what
that gate already refuses.
**Statement position** is its mirror image, new in `at_statement`: the innermost
open scope is a `function`/`task` — whose body is statements all the way down —
or a `begin`/`fork` whose outermost `begin` *is* procedural. Everything else is
refused, `case` arms included: a bare `if` is not a legal case item, and a gate
that guessed at one would offer a template that does not compile.
**Declaration position** is either of the two: a `logic`/`reg`/`wire`/
`localparam` declaration is a module item and a block item both, and
IEEE 1800's `block_item_declaration` includes the parameter forms as well.
On top of the scope chain, a template is only offered where a statement can
*start* on the line: nothing but whitespace before the typed word, or nothing
but `end`, `else` or `end else` — the two words a statement legitimately
follows on one line. That is what makes `end else if` complete, and what keeps
a template out of `x = if`. It is `Word::statement_head`, a list of three
strings, and it is deliberately the whole of the rule: anything else on the
line means the word is part of an expression.
One honesty note about the owner's phrasing ("typing `if(` then accepting a
suggestion"): the list appears while the word `if` is being typed, and the
template is accepted from *there*. Once the `(` is typed, the word being
completed is empty and no longer starts a line, so the templates are gone — the
user is inside an expression by then, and the item they wanted was on screen
one keystroke earlier. Offering `if (…) begin` as a replacement for text that
already contains `if(` would mean editing backwards over punctuation the user
typed, which is the same line M5's backtick ruling drew.
Comments and strings need no new gate at all. M5's `in_comment_or_string`
returns `None` for the whole request before any tier runs, so a `// if` offers
nothing, and the same is true of a buffer that does not lex.
## Ranking
`sortText` is `<tier digit><label>`, so the six tiers are:
| Tier | What |
|---|---|
| `0` | module names (the instantiation follows as ghost text) |
| `1` | declarations the scope chain binds |
| `2` | what the project declares |
| `3` | **templates** |
| `4` | keywords |
| `5` | project words |
**Above the keywords** because a user who typed `if` almost always wants
`if (…) begin … end` rather than the two letters they already have; the bare
keyword is one arrow-key away and is still there. **Below both semantic tiers**
because a name the code actually declares — a signal called `if_enable`, a
package called `case_pkg` — is a fact about this project, and a template is a
guess about intent; facts win. That the templates sit *below* tier 2 rather
than between 1 and 2 is the one judgment call: tier 2 is names the workspace
index resolved, which is the same kind of evidence as tier 1, so the two stay
adjacent.
Both orderings are asserted (`a_template_never_swallows_the_keyword_it_is_
reached_by`, `a_template_ranks_below_a_name_the_code_declares`), and — as M5
recorded — the tests assert what the server sends, not what a client draws.
## Dialect
`templates::dialect` reads the buffer's file extension, the same question
`wire-reg-mixup` asks: `.sv`/`.svh` (case-insensitively) is SystemVerilog,
**everything else is Verilog** — a `.v`, a `.vh`, an unknown extension, and a
buffer with no path at all (`untitled:`, stdin).
The default is Verilog rather than SystemVerilog on purpose, and it is the
opposite of what "newer is better" would suggest. Every Verilog template is
also legal SystemVerilog: guessing Verilog for an SV buffer costs the user
`reg` where they wanted `logic`, one keystroke to fix. Guessing SystemVerilog
for a Verilog buffer hands them `always_ff` and `logic`, which their compiler
rejects. The asymmetric cost decides it. Consequence worth naming: an *untitled*
buffer in VS Code gets the Verilog set even when the user picked the
SystemVerilog language mode, because the server is told a URI, not a language
id, and inventing a second source of truth for one rare case is not worth it.
The moment the buffer is saved as `.sv` it gets the SystemVerilog set.
## Plain-text clients
A client that never advertised `completionItem.snippetSupport` gets **the same
template with every hole filled in**, as `InsertTextFormat::PLAIN_TEXT` — the
M4 ruling for skeletons, applied here. `if` inserts
```systemverilog
if (cond) begin
end
```
and the cursor lands wherever the client puts it, which is the end of the
insertion. Skipping the tier entirely was the alternative and is worse: the
text is useful, it parses (it is the exact string the expansion test feeds the
parser), and the defaults were chosen for this case as much as for the
preselection. A line that held nothing but `$0` loses its indentation in this
spelling, since there is no cursor to park on it.
The two spellings go through one renderer — `Template::render(layout,
snippets)` — so they cannot drift, and
`the_two_spellings_of_a_body_are_the_same_text` asserts that stripping the
tabstops out of the snippet gives the plain text back.
## The indentation contract
**Added 2026-08-25, fixing a bug that had been in the popup since 0.4.0 and
was found while fixing its twin in `inline-templates`.**
Every multi-line body here already carries the site's indentation: `Layout`'s
`base` is the trigger line's leading whitespace and every line after the first
starts with it. VS Code then indents it *again*. `suggestController.ts`'s
`_insertSuggestion` calls
```ts
snippetController.insert(insertText, {
…,
adjustWhitespace: !(item.completion.insertTextRules! & CompletionItemInsertTextRule.KeepWhitespace),
…
});
```
and `SnippetSession.adjustWhitespace` prepends the insertion line's own
leading whitespace to every line after the first, then re-spells the run with
`TextModel.normalizeIndentation`. So `if` accepted four spaces in wrote its
body at twelve and its `end` at eight — one level right of the `if`.
The escape hatch is LSP's `insertTextMode`. `asIs` says "the string is taken
as it is… the client will not apply any kind of adjustments". The vendored
`vscode-languageclient` 9.0.1 advertises support for it
(`completion.js:59`), turns it into `keepWhitespace: true`
(`protocolConverter.js:342-346`), and `extHostLanguageFeatures.ts` turns
*that* into the `KeepWhitespace` rule that clears `adjustWhitespace`.
So `completion.rs` sends `insertTextMode: asIs` (the `KEEP_MY_INDENTATION`
constant) on every item builder that writes more than one line. Single-line
items neither need it nor are harmed by it, so they do not send it. It is the
right answer for the plain-text spelling as well — that text is absolutely
positioned too — which is why this path did **not** switch to relative
indentation the way ghost text had to. An inline completion has no
`insertTextMode` field at all; see
`docs/features/inline-templates/README.md`'s *The indentation contract*.
**Amended 2026-08-30:** that used to be *two* builders, the template tier and
the module-instantiation skeleton. The module item is a plain word now — the
instantiation moved to ghost text
(`docs/features/inline-instantiation/README.md`) — so the template tier is the
only multi-line item left, and the module item sends no `insertTextMode` at
all. Pinned by `tests/e2e.rs`: `insertTextMode == 1` on the template item, and
absent on the module item.
## Reconciliation with the static VS Code snippets
Nine snippets were deleted from `editors/vscode/snippets/*.json` because the
server now offers the same construct under the same typing. The list, the
reasoning and the verification are in
`docs/features/editor-snippets/README.md`'s work log (2026-08-24, M2); in
brief: `always_ff`, `always_comb`, `case`, `initial` from
`systemverilog.json`, and `always`, `alwayscomb`, `case`, `for`, `initial`
from `verilog.json`. `alwayscomb` is the only one whose prefix does not collide
outright — VS Code matches a typed `always` against it as a subsequence and it
had a byte-identical body to the server's `always @(*)`.
Everything **file-level stays static**, because a file template is worth having
before the server has started and is not position-dependent: `module`,
`modulep`, `fsm`, `enum`, `struct`, `function`, `task`, `interface`, `package`,
`class`, `assertp`, `genfor`, `uniquecase`, `tb`, `guard`. `uniquecase` and
`genfor` are kept deliberately — `unique case` is a different construct from
`case`, and a generate loop is a module item, not the procedural `for` the
server offers.
## Version 0.4.0
Every place `tools/RELEASING.md` names, plus the install examples it does not:
- [x] `Cargo.toml` `[workspace.package] version` → `0.4.0` (all eight crates
inherit it)
- [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
- [x] `README.md` — the `dist/lucisv-0.4.0.vsix` install example
- [x] `editors/vscode/README.md` — both install examples
- [x] `tools/RELEASING.md` — the `dist/` listing, the install commands, the
`git tag v0.4.0` example and the appendix's publish commands
- [x] `CHANGELOG.md` — a `0.4.0 — 2026-08-24` section in the existing voice
- [x] Verified: `target/debug/lucisv --version` → `lucisv 0.4.0`
- [x] Verified: `node editors/vscode/smoke.js target/debug/lucisv-server` →
`smoke: OK`
Deliberately not touched: the historical `0.3.x` mentions in `CHANGELOG.md` and
in the feature READMEs that record what happened at those versions.
## Status / TODO
- [x] `templates.rs`: registry, dialect rule, one renderer for both spellings
- [x] Tier 3 in `completion.rs`, above keywords and below the semantic tiers
- [x] Statement gate (`at_statement`), reusing M4's scope chain
- [x] Item and declaration gates
- [x] `Word::statement_head`, so `end else if` completes
- [x] Dialect selection by extension, documented for the pathless buffer
- [x] Plain-text fallback with the defaults filled in
- [x] Registry-wide "every untouched expansion parses" test, both harnesses
- [x] Registry-wide `$`-escaping and flat-default tests
- [x] Gate tests: statement vs item vs declaration, subprogram bodies, case
arms, generate blocks, port lists, mid-line words, comments
- [x] Dialect tests over `.sv` and `.v` buffers
- [x] Ranking and dedup tests against the keyword and scope tiers
- [x] e2e stdio round trip: the `if` template's exact snippet text, its
replaced range, the keyword beside it, and a `.v` buffer's `always`
- [x] Nine static snippets removed, both READMEs' prefix tables updated
- [x] Version 0.4.0 across the workspace, the extension and the docs
- [x] `cargo fmt --all -- --check`, `cargo clippy --all-targets`,
`cargo test --workspace` clean; `node --check` on both JS files;
`smoke.js` OK; `vsce ls` still accepts the manifest
- [ ] Not done, deliberately: no `casex`, no `forever`/`repeat`, no `fork/join`
template, no UVM anything. Each is a template somebody wants and nobody
agrees on the shape of, and an unused item is noise in the list — the
same ruling editor-snippets made for `covergroup` and `sequence`.
- [ ] Not done: no template for `generate`/`endgenerate` or `genvar` loops.
The static `genfor` snippet covers it and is not position-dependent.
## Work log
- **2026-08-24 (dev)** — implemented.
**Registry (`crates/lucisv_server/src/templates.rs`, new).** A `Template` is
five fields: label, prefix, gate, detail, and a body written as
`(indent level, text)` lines. `for_dialect` chains the eight shared templates
onto the dialect's own, so the statement set cannot drift between `.sv` and
`.v`. `render` is the only code: it lays the lines out at a
`vlog_refactor::Layout` and either leaves the tabstops alone or replaces each
one with the text the editor would have preselected — mirrors included, so
`$1` after `${1:i}` is `i`, which is what makes the `for` loop's expansion
parse.
**Tier (`completion.rs`).** `template_tier` between `index_tier` and
`keyword_tier`, `TIER_TEMPLATE = '3'`; the keyword and word tiers moved to
`'4'` and `'5'`. `Items::template` builds the item — `CompletionItemKind::
SNIPPET`, `filterText` = the prefix, `documentation` = the expansion in a
fenced block — and goes through the same `push` as everything else, so the
cap and the dedup are unchanged.
**Gates.** `completions` now computes the scope chain **once**, guarded by
"does this word start a statement at all", and passes it to both
`at_module_item` (whose body is otherwise untouched) and the new
`at_statement`. The guard matters: before M6 a mid-expression keystroke never
ran `pairs::analyze`, and it still does not.
**Decisions worth flagging to the lead:**
1. **The tier digits shifted.** Templates had to rank above keywords, and
there is no character between `'2'` and `'3'`, so keywords became `'4'`
and project words `'5'`. One assertion outside `completion.rs` reads a
digit — `e2e.rs`'s word-tier check — and it is updated with a comment.
Every in-module test reads the `TIER_*` constants and needed no change.
2. **A pathless buffer gets the Verilog set**, not the SystemVerilog one.
Reasoning under *Dialect*; it is the conservative direction, and it is
also the one `wire-reg-mixup` already takes.
3. **`end`, `else` and `end else` are statement starts**, so `end else if`
completes. Three strings, an explicit list, and the test that pins it also
pins that `x = if` is not one.
4. **The parameter templates name a type** (`int`/`integer`) so that the
untouched expansion does not trip lucisv's own
`explicit-parameter-storage-type` rule. Found by running the expansions
through `lucisv check` while choosing the bodies.
5. **`alwayscomb` was removed from `verilog.json`** although its prefix does
not collide with anything the server offers. It is a subsequence match on
`always` with a body identical to the server's `always @(*)`, so it would
have shown as a duplicate — but it is the one reconciliation entry that is
a judgment call rather than a prefix collision.
**Performance.** M5's corpus guard, re-run in release against the 860-file
corpus: `worst request 284 µs typed / 242 µs empty`, against M5's measured
297 µs / 223 µs — unchanged inside the run-to-run noise, which is what the
single shared `pairs::analyze` and the "no gate unless the word starts a
statement" guard were for. The template path itself formats at most eighteen
short strings and touches no table.
**Suite**: 1 268 → 1 292 workspace tests (24 new: 9 in `templates.rs`, 14 in
`completion.rs`, 1 e2e), all green. `cargo fmt --all -- --check` and
`cargo clippy --all-targets` clean; `node --check` on `extension.js` and
`smoke.js`; `node editors/vscode/smoke.js target/debug/lucisv-server` →
`smoke: OK`; `npx --no-install @vscode/vsce ls` still lists both snippet
files. No new dependency.
- **2026-08-25 (dev, inline-templates round 2)** — one field, one latent bug.
While fixing the same double-indentation bug in ghost text I read
`suggestController.ts` and found the popup had it too: every multi-line item
this tier sends was being re-indented by the editor on accept, since 0.4.0.
Fixed with `insertTextMode: asIs` on `Items::template` and on `item` (the
module-instantiation skeleton), behind the `KEEP_MY_INDENTATION` constant so
the reasoning sits with the value. Full derivation and sources in *The
indentation contract* above; the inline half is in
`docs/features/inline-templates/README.md`.
**Flagged for the lead:** the module-skeleton item belongs to
`refactor-instantiate`, not to this feature — the code is in
`completion.rs`, it is the identical bug, and leaving it broken beside the
fixed template item would have been the odd choice. `templates.rs` itself is
untouched: no body, no label, no gate, no renderer changed. Two `e2e.rs`
assertions added; nothing else.
## QA log
**2026-08-24 — QA agent.**
### Gates
- `cargo fmt --all -- --check` — clean.
- `cargo clippy --all-targets --workspace` — clean, zero warnings (re-ran
after `touch`ing `completion.rs` to defeat the cache; still clean).
- `cargo test --workspace` — green. Summed every `test result:` line myself
rather than trusting the total: **1292**, matching the Work log's
`1268 → 1292` claim exactly.
- `node --check` on `extension.js` and `smoke.js` — clean.
- `node editors/vscode/smoke.js target/debug/lucisv-server` — `smoke: OK`.
- `cd editors/vscode && npx --no-install @vscode/vsce ls` — accepts the
manifest; filtering the `node_modules/**` noise out of the listing (as the
M1 QA pass for editor-snippets also did — `.vscodeignore` does not touch
`node_modules`, so `vsce ls` prints it regardless) leaves exactly
`package.json`, `extension.js`, `README.md`, `LICENSE`,
`snippets/verilog.json`, `snippets/systemverilog.json`.
- `cargo build -p lucisv` → `target/debug/lucisv --version` → `lucisv 0.4.0`.
- `cargo test --release -p lucisv_server a_keystroke_over_the_whole_corpus_stays_in_budget -- --nocapture`
— `worst request 225.875µs typed / 182.792µs empty` against the claimed
284µs/242µs; faster, inside run-to-run noise. Budget test passes.
All gates: **pass, claims confirmed.**
### Priority — the real UX, driven live over stdio
Not trusting the e2e test alone: wrote a standalone Python LSP-stdio client
(`/tmp/lucisv_qa/driver.py`, `ux_check.py`, `edge_check.py`, `untitled_check.py`
— scratch, not committed) and drove `target/debug/lucisv-server` directly,
independent of the test suite.
- `.sv` buffer, `if` typed inside an `always_comb` body: `if begin/end`
(kind Snippet=15) and `if/else` both offered, `filterText: "if"`,
`textEdit.newText` = `"if (${1:cond}) begin\n $0\n end"`
(tabstops, correct indentation at the site). The bare keyword `if` (kind
Keyword=14) is present at one tier below (`sortText` `3…` vs `4if`).
**Confirmed exactly as claimed.**
- `case`/`casez` inside a begin block: both offered, correct bodies.
- `always_ff`/`always_comb` at SV item position: all three always_ff/comb
templates offered.
- `logic name;` / `logic [N:0] name;` at SV declaration position: both
offered.
- `.v` buffer, `always` at item position: `always @(posedge clk)`,
`always @(posedge clk or negedge rst_n)`, `always @(*)` offered;
`always_ff`/`always_comb` templates **not** offered (the bare keywords
`always_ff`/`always_comb` still show, correctly, at the keyword tier —
templates are dialect-gated, keywords are not).
- `.v` buffer: `wire`/`reg` declaration templates offered; `logic` template
**not** offered anywhere in a `.v` buffer (checked at declaration position
with prefix `lo`: only `localparam integer NAME = 0;` came back).
- Untitled buffer (`untitled:Untitled-1`, `languageId: "systemverilog"`,
no path) with prefix `l`: only `localparam integer NAME = 0;` — the
**Verilog** set, confirmed live, exactly as *Dialect* documents (and
despite the client-declared language id, which the server correctly never
consults for this).
**Confirmed exactly as claimed** — the plan's exact UX ("type `if` inside a
module + inside an always/initial body", "the bare keyword `if` ALSO present
at a lower tier", "`.v` buffer: `always_ff` NOT, `logic` NOT") all hold live,
not just in the unit/e2e suite.
### Attacks — gates
All driven live over stdio, independent scripts, not just re-running the
existing tests:
| Attack | Result |
|---|---|
| `if` at module-item position (not inside a block) | **not offered** |
| `always_ff` inside a begin block (`always_comb`) | **not offered** |
| statement template inside `fork`/`join` | **offered** (fork is a statement scope, correctly) |
| statement template inside a `function` body | **offered** |
| statement template inside a `generate`/`endgenerate` block | **not offered** (item position, not statement) |
| `case` arm (`case (s) if`) | **not offered** |
| template inside a port list (`module top (\n if\n)`) | **not offered** |
| template inside a parameter list (`module top #(\n if\n)`) | **not offered** |
| template inside a connection list (`.a(if`) | **not offered** |
| cursor in a `// if` comment | **no completions at all** (whole response declines) |
| cursor inside an open string (`$display("if`) | **no completions at all** |
| `end el` (else-tail after `end` on the same line) | **offered** (`else if`, `else begin/end`) |
| `x = if` (bare identifier before `if`, mid-expression) | **not offered**; keyword tier still answers |
| `end el` (double space between `end` and `else`) | **offered** — `Word::statement_head`'s `split_whitespace().join(" ")` normalizes it |
| `end foo el` (garbage between `end` and `else`) | **not offered** — correctly refused |
Every one of the plan's specific break attempts held. No corruption risk:
`verify.rs` is untouched by this feature (confirmed by `git diff` — no
changes outside the stated scope), so hard invariant 4 does not apply here;
the "attack" surface for this milestone is *wrong completions*, not corrupted
formatter output, and none were found.
### Expansion validity — re-derived independently, not trusted from the test
Extracted all 26 `Template` entries straight out of `templates.rs`'s source
text with a standalone regex parser (not importing or calling
`Defaults::substitute`), wrote a **second, independent** tabstop-stripping
implementation in Python, planted each stripped body in the same probe shapes
the registry's own test uses, and fed every probe to a throwaway Rust binary
(`/tmp/lucisv_qa/probe_checker`, a 10-line `main.rs` depending on `vlog_parser`
by path) that calls `vlog_parser::parse_source_tolerant` directly — no lucisv
code from this feature involved in the check at all.
Result: **26/26 parse clean**, independently. Count matches the claim (8
shared + 8 SV-only = 16 SV templates; 8 shared + 10 V-only = 18 V templates).
**On "does it test `.v` templates against Verilog parsing settings?"** — no,
and it can't: `vlog_parser` has no dialect concept anywhere
(`grep -rn "Dialect\|dialect" crates/vlog_parser/src/*.rs` — zero hits).
`parse_source_tolerant` is one grammar, a syntactic superset of both
dialects; dialect-specific rejection (e.g. `always_ff` being illegal in a
`.v` file) is enforced only by *this feature's own gate* (`templates::
dialect`), never by the parser. So the registry test is exactly as strong as
it can be — there is no stricter parsing mode to test `.v` templates against
anywhere in lucisv today. Worth recording, not a finding: a reader could
otherwise assume "parses" implies "parses under Verilog-2001 rules
specifically", which nothing in lucisv currently checks for *any* file.
`$`-escaping: grepped the body text for `$` followed by a letter
(`grep -oE '"\$[a-zA-Z_]+' templates.rs`) — zero hits; every `$NAME`/`$n` in
the file is inside a doc comment, not a body. No system task in any template
body today, consistent with the claim.
Mirrors: the independent stripper resolves `$1` after `${1:i}` to `i` the
same way `Defaults::substitute` does (verified by the same 26/26 pass,
including both `for` loop templates, whose bodies are the only ones with
three mirrored tabstops).
### Dialect
`.svh`/`.vh` — covered by the registry's own
`the_dialect_comes_from_the_extension_and_defaults_to_verilog` test
(`.SVH` case-insensitive → SystemVerilog, `.vh` → Verilog); re-read the
assertions, they match the README's claim. Documented in *Dialect* and (see
above) reconfirmed live for the untitled-buffer case, including the
`languageId` red herring the README calls out by name.
### Reconciliation
Parsed both snippet JSONs directly (`python3 -c 'json.load(...)'`) rather
than trusting the diff: `systemverilog.json` 19 → **15** entries, `verilog.json`
11 → **6**, matching the claim. `git diff` on the two files' removed
`"prefix"` lines gives exactly the 9 named in the feature README's
*Reconciliation* section (4 SV: `always_ff`, `always_comb`, `case`,
`initial`; 5 V: `always`, `alwayscomb`, `case`, `for`, `initial`) — none
missing, none extra.
Keeper prefixes: SV = `module`, `modulep`, `uniquecase`, `fsm`, `enum`,
`struct`, `function`, `task`, `interface`, `package`, `class`, `assertp`,
`genfor`, `tb`, `guard`; V = `module`, `function`, `task`, `genfor`, `tb`,
`guard`. Cross-checked against every server template prefix in the matching
dialect (`if`, `else`, `case`, `casez`, `while`, `initial`/`for`,
`always_ff`/`always_comb` or `always`, `logic`/`reg`/`wire`, `localparam`,
`parameter`) — **no exact string collision** in either dialect.
Near-misses, as the plan asked to check by name: `genfor` vs `for` and
`uniquecase` vs `case` both contain the server's word as a literal
substring, so a client that fuzzy-matches by subsequence (VS Code's
completion filter does) can surface both for the same keystrokes — exactly
what the feature README's own *Reconciliation* section already discloses for
`alwayscomb` vs `always`. Not a new finding: the labels (`Generate for` /
`for loop`, `Unique case` / `case/endcase`) are distinct in the list, so a
user reading labels — which is the whole reason every template label is
prose, not a keyword, per this feature's own first Assumption — can always
tell them apart. No undisclosed near-miss found beyond what the README
already names.
### Tier digits
`grep -rln "sortText\|sort_text\|TIER_" crates editors` — exactly two hits,
`completion.rs` and `e2e.rs`, both already inspected in the diff above and
both consistent with the new scheme (`0`=module, `1`=scope, `2`=index,
`3`=template, `4`=keyword, `5`=word). `candidates.rs` has no tier-digit
literals at all. No straggler found.
### Version
- `Cargo.toml`, all 8 `Cargo.lock` package entries, `package.json`,
`package-lock.json` (both places), `README.md`, `editors/vscode/README.md`,
`tools/RELEASING.md` — all `0.4.0`, checked directly (not by grep-and-eyeball
alone; the 8 `Cargo.lock` entries were extracted programmatically with
`awk`).
- `grep -rn "0\.3\.1"` outside `CHANGELOG.md` — zero hits. The `0.3.1`
section of `CHANGELOG.md` itself is correctly left as history.
- **Finding, fixed directly (small, unambiguous):** `CHANGELOG.md`'s 0.4.0
entry said the static snippets "shed the **eight** that would otherwise
have been offered twice (`always`, `always_ff`, `always_comb`, `case`,
`for`, `initial` and their Verilog twins)". The actual count, verified
against `git diff` on both snippet JSONs and against this feature's own
*Reconciliation* section and Work log ("Nine static snippets removed" /
"9 static snippets removed"), is **nine**: 4 from `systemverilog.json`
(`always_ff`, `always_comb`, `case`, `initial`) + 5 from `verilog.json`
(`always`, `alwayscomb`, `case`, `for`, `initial`). The old wording also
never named `alwayscomb` and left its count ambiguous under "and their
Verilog twins". Reworded to name all nine explicitly and state the correct
count — see `CHANGELOG.md`'s 0.4.0 section. This is a release-note
accuracy issue only; nothing in code or tests was affected.
### Verdict
**Ship.** Every dev claim checked out exactly as stated, including the ones
phrased as UX promises rather than test assertions — verified live over
stdio with independent scripts, not just by re-running the shipped suite.
The one finding (CHANGELOG miscount) was cosmetic, unambiguous, and fixed
in place. No gate, attack, or reconciliation check turned up anything that
needs dev rework.
**2026-08-25 — QA agent, round 2 (the `insertTextMode` popup fix).**
This feature's only change in round 2 is the four-line diff in
*The indentation contract* above (`completion.rs`): `insert_text_mode:
Some(KEEP_MY_INDENTATION)` on `Items::template`
(`crates/lucisv_server/src/completion.rs:459`) and on `item`, the
module-instantiation skeleton (`:612`); `layout_at`
(`crates/lucisv_server/src/completion.rs:326-329`) re-privatized because
`inline.rs` no longer names it. `templates.rs` is untouched, confirmed by
`git diff --stat` (absent from the diff entirely). Full attack and gate
detail — the trigger-table work is this round's real surface — is in
`docs/features/inline-templates/README.md`'s 2026-08-25 round-2 QA entry;
this entry covers only what round 2 touched here.
- **The wire value.** `crates/lucisv_server/src/completion.rs:156` in
`lsp-types` 0.97.0 (registry source, read directly):
`pub const AS_IS: InsertTextMode = InsertTextMode(1)`;
`ADJUST_INDENTATION = InsertTextMode(2)`. So `KEEP_MY_INDENTATION` is `1`,
matching LSP 3.17's `InsertTextMode` enum (`asIs = 1`). Both pins in
`tests/e2e.rs` assert `insertTextMode == 1` — the template item at
`crates/lucisv_server/tests/e2e.rs:1258` and the module skeleton at
`:1625` — and both are correct. (The QA brief itself floated "`asIs` (2)"
as a parenthetical; that would have been `AdjustIndentation`, not `AsIs`
— checked against the source rather than trusted, and the shipped code is
right.)
- **No leak onto single-line items.** `grep -n "insert_text_mode"
crates/lucisv_server/src/completion.rs` returns exactly the two call sites
above. `Items::simple` (`completion.rs:412-430`, the keyword/word/index
tiers' single-line items) builds its `CompletionItem` with
`..Default::default()`, which leaves `insert_text_mode: None` — confirmed
by reading the struct literal, not inferred. So plain keyword and word
items are unaffected, as required.
- **Client capability path.** `editors/vscode/node_modules/
vscode-languageclient/lib/common/completion.js:59` advertises
`insertTextModeSupport.valueSet: [asIs, adjustIndentation]` as part of the
standard completion capabilities — no code in this repo has to opt into
it, unlike `inlineCompletion`'s proposed-feature registration.
`protocolConverter.js:342-346` turns `insertTextMode === asIs` into
`result.keepWhitespace = true`, which `extHostLanguageFeatures.ts` turns
into the `KeepWhitespace` insert-text rule `suggestController.ts` checks
before calling `adjustWhitespace`. Traced end to end; matches the Work
log's claim.
- **Gates, re-run independently:** `cargo fmt --all -- --check` clean;
`cargo clippy --all-targets --workspace` zero warnings; `cargo test
--workspace` 1644 passed / 0 failed / 4 ignored (up from the round-2 dev's
1633 — 11 new tests, all in `inline.rs`, none in this feature's own
files); `node editors/vscode/smoke.js target/debug/lucisv-server` →
`smoke: OK`; `node --check` on `smoke.js` and a `JSON.parse` of
`package.json` both clean.
No findings against this feature's own round-2 diff. No commit, no push.
## Review
**2026-08-24 — lead.** Reviewed after QA's ship verdict — second clean
first-pass in a row; gates run independently (1292 tests, 0 failures,
clippy silent). The registry-as-data with one renderer for both spellings
is the right shape, and `Word::statement_head` is a neat, honest gate for
`else if` (offered after `end`, refused after an identifier). QA
independently re-derived and re-parsed all 26 template expansions with its
own stripper — exactly the level of distrust the expansion-parses promise
deserves. Dev's three judgment calls approved: the tier-digit shift (all
call sites audited), the conservative Verilog set for pathless buffers
(every Verilog template is legal SV), and removing `alwayscomb` from the
static set. QA's CHANGELOG miscount fix (eight → nine, `alwayscomb` named)
accepted. Lead post-review fix: the extension README's relative link to
this doc broke `vsce package` (no repository URL to resolve it against) —
demoted to plain-text path. M6 checked off in the umbrella plan and
TODO.md §8; ships as 0.4.0.
**2026-08-25 — lead review of the insertTextMode fix.** The popup's
skeletons were latently double-indented in VS Code since 0.4.0 — same
root cause as inline-templates round 2, different fix because the
completion protocol has the opt-out the inline one lacks:
`insertTextMode: asIs` (verified = 1 on the wire against lsp-types
source, by QA) on the two multi-line tiers only. `templates.rs` and the
plain-text fallback untouched, `lucisv.indent` still meaningful here.
Approved; ships as 0.7.0.