Templates 0.4.0: context-gated statement/item snippet completion
A template tier between index names and keywords: if / if-else / else-if (gated on the line head, so it appears after end but not after an identifier), case and casez with default, loops, always_ff (plain and reset variants), always_comb, always @(...), initial, and declaration templates - logic/localparam/parameter in .sv, wire/reg/integer twins in .v; pathless buffers get the conservative Verilog set. One renderer spells each body as snippet and plain text so the two cannot drift, and a registry-wide test parses every untouched expansion. Nine overlapping static VS Code snippets moved server-side; file-level ones stay static. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
ab89152264
commit
e9b7510ca4
18 files changed
+1872
-149
No files matched your search
@@ -0,0 +1,618 @@
|
||||
# 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 vfmt'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.
|
||||
- **`vfmt.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 `vfmt.toml` recorded there.
|
||||
- **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/vfmt_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 `vfmt_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 vfmt'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 instantiation skeletons (M4) |
|
||||
| `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.
|
||||
|
||||
## 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/vfmt-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/vfmt --version` → `vfmt 0.4.0`
|
||||
- [x] Verified: `node editors/vscode/smoke.js target/debug/vfmt-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/vfmt_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 vfmt's own
|
||||
`explicit-parameter-storage-type` rule. Found by running the expansions
|
||||
through `vfmt 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/vfmt-server` →
|
||||
`smoke: OK`; `npx --no-install @vscode/vsce ls` still lists both snippet
|
||||
files. No new dependency.
|
||||
|
||||
## 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/vfmt-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 vfmt` → `target/debug/vfmt --version` → `vfmt 0.4.0`.
|
||||
- `cargo test --release -p vfmt_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/vfmt_qa/driver.py`, `ux_check.py`, `edge_check.py`, `untitled_check.py`
|
||||
— scratch, not committed) and drove `target/debug/vfmt-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/vfmt_qa/probe_checker`, a 10-line `main.rs` depending on `vlog_parser`
|
||||
by path) that calls `vlog_parser::parse_source_tolerant` directly — no vfmt
|
||||
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 vfmt today. Worth recording, not a finding: a reader could
|
||||
otherwise assume "parses" implies "parses under Verilog-2001 rules
|
||||
specifically", which nothing in vfmt 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.
|
||||
|
||||
## 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.
|
||||
@@ -87,6 +87,10 @@ SystemVerilog.
|
||||
- [x] Register both files in `package.json` → `contributes.snippets`.
|
||||
- [x] Verify the packaged `.vsix` includes them (`vsce ls`).
|
||||
- [x] Feature README.
|
||||
- [x] **2026-08-24, M6:** hand the statement- and block-level templates to the
|
||||
server and keep only the file-level ones here — nine snippets removed,
|
||||
the two READMEs' prefix tables updated. See the work-log entry below and
|
||||
`docs/features/completion-templates/README.md`.
|
||||
- [ ] Not done, deliberately: no snippets for UVM (`uvm_component_utils`,
|
||||
factory registration) — they belong with a UVM-aware feature, not in a
|
||||
base file the whole ecosystem sees. No `always_latch`, no `covergroup`,
|
||||
@@ -175,6 +179,49 @@ no snippets item to check off — §6's shipped-capabilities list mentions
|
||||
"declaration snippets" only as part of `hover`, which is a different thing —
|
||||
so it was left alone.
|
||||
|
||||
### 2026-08-24 — M2: nine templates moved server-side in M6
|
||||
|
||||
`completion-templates` (M6) makes the server offer the statement and block
|
||||
templates itself, gated by where the cursor actually is and by the file's
|
||||
dialect — something a static `contributes.snippets` entry cannot do, since VS
|
||||
Code offers a snippet on prefix alone, anywhere in the file. Two lists offering
|
||||
the same prefix would have meant two near-identical items in one completion
|
||||
list, so the overlapping snippets were **removed here** rather than duplicated:
|
||||
|
||||
| File | Snippet | Prefix | Replaced by |
|
||||
|---|---|---|---|
|
||||
| `systemverilog.json` | always_ff | `always_ff` | server `always_ff with reset` |
|
||||
| `systemverilog.json` | always_comb | `always_comb` | server `always_comb begin/end` |
|
||||
| `systemverilog.json` | Case with default | `case` | server `case/endcase` |
|
||||
| `systemverilog.json` | Initial block | `initial` | server `initial begin/end` |
|
||||
| `verilog.json` | Clocked always block | `always` | server `always @(posedge clk or negedge rst_n)` |
|
||||
| `verilog.json` | Combinational always block | `alwayscomb` | server `always @(*)` |
|
||||
| `verilog.json` | Case with default | `case` | server `case/endcase` |
|
||||
| `verilog.json` | For loop | `for` | server `for loop` |
|
||||
| `verilog.json` | Initial block | `initial` | server `initial begin/end` |
|
||||
|
||||
`alwayscomb` is the one removal whose prefix does *not* collide: VS Code
|
||||
matches a typed `always` against it as a subsequence, so it appeared beside the
|
||||
server's `always @(*)` with a byte-identical body. Removing it is a judgment
|
||||
call and is flagged as one.
|
||||
|
||||
**Everything file-level stays**, and stays static, so it still works with no
|
||||
server on `PATH`: `module`, `modulep`, `fsm`, `enum`, `struct`, `function`,
|
||||
`task`, `interface`, `package`, `class`, `assertp`, `genfor`, `uniquecase`,
|
||||
`tb`, `guard`. `uniquecase` is kept deliberately — `unique case` is a different
|
||||
construct from `case`, not a second spelling of it, and the server offers no
|
||||
template for it. `genfor` is kept for the same reason: a `generate` loop is a
|
||||
module item, not the procedural `for` the server offers.
|
||||
|
||||
**Verified.** Both files re-parsed as JSON; prefixes unique within each file;
|
||||
the `$`-escaping check re-run over what remains (`\$display`, `\$finish`,
|
||||
`\$error` in the two `tb` snippets and `assertp` — the three occurrences the
|
||||
*Assumptions* section names, all still escaped, none of them in a removed
|
||||
snippet). `npx --no-install @vscode/vsce ls` still accepts the manifest and
|
||||
still lists both `snippets/*.json`. Counts: `systemverilog.json` 19 → 15,
|
||||
`verilog.json` 11 → 6. `editors/vscode/README.md`'s two prefix tables were
|
||||
rewritten to match and now say where the statement templates went.
|
||||
|
||||
## QA log
|
||||
|
||||
_(empty — no QA pass yet)_
|
||||
|
||||
@@ -108,6 +108,16 @@ the work is reviewed**. Owner-priority items first (2026-08-24).
|
||||
- [x] **Version 0.3.0** — workspace + extension bump with a CHANGELOG entry
|
||||
covering the whole refactoring layer (M1–M5) → M5
|
||||
|
||||
### Templates (owner request, 2026-08-24 night)
|
||||
- [x] **Statement/item template completion** — context-gated snippet items
|
||||
from the server (both editors): `if`/`if-else`/`else-if`, `case` with
|
||||
`default`, `always_ff`/`always_comb`/`always @(...)`, `for`/`while`,
|
||||
`initial`, declarations (`logic x;`-style), each with tabstops (condition
|
||||
first, then body) → `docs/features/completion-templates/README.md` (M6)
|
||||
- [x] **Reconcile with the static VS Code snippets** — no prefix offered
|
||||
twice; file-level templates (module, tb, FSM) stay static → M6
|
||||
- [x] **Version 0.4.0** → M6
|
||||
|
||||
### Structural refactorings (backlog, post-M4)
|
||||
- [ ] **Extract module** from a selected statement range (infer ports from
|
||||
read/driven sets) — the flagship, hardest one
|
||||
@@ -198,7 +208,8 @@ commit — in order:
|
||||
- [x] M3 refactor-ports — done, QA clean after one rework round, reviewed
|
||||
- [x] M4 refactor-instantiate — done, QA clean after one rework round, reviewed
|
||||
- [x] M5 completion-core — done, QA clean first pass, reviewed
|
||||
- [ ] Backlog triage after M5
|
||||
- [x] M6 completion-templates — done, QA clean first pass, reviewed
|
||||
- [ ] Backlog triage after M6
|
||||
|
||||
## Work log
|
||||
|
||||
|
||||
Reference in new issue
Block a user