Server (lucisv_server only): on_type/auto_end.rs — the newline answer adds the owed end at the owning statement's indentation (lucisv.autoEnd); always_ff @( / always @( ghosts and popup templates lead with posedge clk or negedge rst_n; completion tiers put names declared and used in this buffer ahead of the index, templates and keywords (completion/buffer.rs); inline/keywords.rs ghosts the rest of a keyword and follows the popup's selected entry (lucisv.inlineKeywords); connection items keep connected ports as a second group marked 'connected' and insert name($1), pre-filled with a same-named signal (completion/connection.rs). Extension: typing.js sends the newline on-type request itself when editor.formatOnType is off and restores the cursor; the inline-completion context is converted to LSP shapes. Dev + QA (Opus 5.5) + one fix round; unit 1823, e2e 102, node 9 files, smoke OK. Not yet seen in a running VS Code. docs/features/completion-ux. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
28 KiB
completion-ux
Goal
Completion that keeps up with typing (TODO §68.1, owner's order 2026-11-17).
Five changes to the editing loop the VS Code extension drives, all served by
lucisv-server so other LSP clients get them too:
begin+ Enter writes theend. The newline on-type answer, when the line above ends inbegin/begin : labeland the block still owes anend, also writesendon the line after the new one, at the owning statement's indentation; the cursor stays on the indented body line. The extension sends that request itself wheneditor.formatOnTypeis off.- Clock and reset in the
alwaystemplates.always_ff @(andalways @(ghostposedge ${1:clk} or negedge ${2:rst_n}) begin … endfirst; the clock-only form stays as the second choice, in the ghost and in the popup. - Current-file names rank first in the popup: what this buffer declares (any scope), then the words it uses, ahead of other files' names, the templates and the keywords.
- Keyword ghosts. A typed proper prefix of a keyword shows the rest as grey inline text, following the popup's selected item while the popup is open.
- Port items. After the
.of a connection, unconnected ports first, connected ones after them markedconnected; accepting one writes.name($1)with the cursor inside the parentheses, pre-filled with a same-named signal when the instantiating scope has one.
Assumptions
-
Auto-
end— whichbeginowes anend.pairs::analyzeis a stack matcher, so abegintyped inside a balanced block steals that block'sendand the outerbegincomes out unmatched. The rule (on_type/auto_end.rs::owes_an_end): noendif thisbeginis matched by anendthat is first on its line at exactly the indentation the answer would write; otherwise anendiff anybeginat or before this one is inunmatched_open. Fix round: thebeginalso counts as closed when its matchedendstarts its line at thebegin's own line's indentation (GNU layout,beginon its own line), and an unmatchedbegininside a`ifdef/`ifndefregion that has an`else/`elsifarms nothing. Consequence: an unrelated unclosedbeginearlier in the file still arms it (accepted heuristic, lead's ruling); a hand-mis-indentedendbelonging to an outer block at either column disarms it. -
Auto-
endand`ifdefbranches (QA finding 1). Two branches that each open the same block (`ifdef A always … begin `else always … begin `endifand one sharedend) are complete code that the stack matcher reads as one unmatchedbegin. What is right after the first branch'sbeginis noend: the block'sendis the shared one after the`endif, and a second would break the other branch. The cheap rule — an unmatchedbegininside a branched conditional region never arms the answer — gets that right. Known limit it buys: a genuinely newbegintyped inside such a region whose only unmatchedbeginis itself gets noend(the plain indent answer instead). The region scan is by directive word over the token stream; a region never closed runs to end of buffer. -
Auto-
end— the owner line. Read backwards from thebeginover a parenthesised header,@/#and its operand, one header keyword (if,for,foreach,while,repeat,forever, thealwaysfamily,initial,final) and the qualifiers in front of it (else,unique,unique0,priority). Anything else ends the walk. Theendtakes that line's leading whitespace as written (tabs stay tabs). An unmatched)leaves thebegin's own line as the answer. -
Auto-
end— the body line. The nesting model's level (spaces, as the plain newline answer) when it lies deeper than theend; else theend's indent plus onelucisv.indent-width step; a tab-indentedendgets one more tab. -
Auto-
end— only on a blank new line. Enter pressed mid-line carries text down, and that line gets the plain indent answer only. The previous line must end inbegin/begin : label; comments are trivia and do not count. Onlybegin— notfork,case,module. -
Auto-
endedit shape. Two edits: the new line's leading whitespace (omitted when already right) and an insertion of<indent>end<eol>at column 0 of the line after the new one, so no edit touches the cursor position. When the new line is the file's last line there is nowhere else to put it: one edit replaces the new line withbody<eol><indent>end. The line ending is the one just typed (\r\nfiles stay\r\n). -
Extension path.
editors/vscode/typing.jsacts on anonDidChangeTextDocumentevent with exactly one content change, noreason(undo/redo are skipped),rangeLength0, text matching^\r?\n[ \t]*$, a line before it ending inbegin/begin : label(a//comment stripped),editor.formatOnTypenot on for the document (language overrides honoured viagetConfiguration('editor', document)), andlucisv.autoEndnotfalse. The request goes out on the next tick (setTimeout 0) so the language client's owndidChangefor the same event is sent first. The answer is applied only if the document version is unchanged and the answer writes anend(an indent-only answer is formatting the user never turned on). Applied witheditor.edit(…, { undoStopBefore: false, undoStopAfter: true }), then the cursor is put at the end of the new line. -
Undo. The edit has no undo stop before it, so VS Code should fold it into the Enter's own undo step: one
Ctrl+Zremoves theend, the indent and the newline together. Not verified in a running VS Code (see QA). -
Templates. Popup template
sortTextis now5+ three-digit registry rank + label, so templates reached by the same prefix show in registry order; the with-resetalways_ff/ Verilogalways @(posedge … or negedge …)were moved ahead of the clock-only ones. Labels unchanged. -
Ranking — the final tier table (
completion/mod.rs; the first character of everysortText, a label follows, so the order is total):digit tier source 0module names (item position) / members (exclusive answer) index / site 1visible at the cursor (scope chain); in a connection list: already-connected ports Semantics2declared anywhere in this buffer Semantics::symbols()3identifiers used in this buffer (not the token under the cursor) token stream 4what the project declares (units, members, `defines)index 5templates ( 5+ rank + label)templates.rs6keywords vlog_parser::KEYWORDS7project words candidate tables Dedup by label is unchanged: the first (best) tier wins. VS Code sorts by its own fuzzy score first and uses
sortTextamong equal scores, so the tier order decides between equally good matches only. -
Ranking — the typed word itself. The buffer-word tier skips the token starting at the cursor's word, so a half-typed
cis no longer offered back asc(it used to be, by the old word tier). A saved copy of the same file still contributes it through the project-word table. -
Keyword ghosts.
inline/keywords.rs. Asked only when no template trigger answered and the rest of the line is blank (the existing ghost rule). The word: the token ending exactly at the cursor,IdentorKeyword, ASCII identifier characters starting with a letter, length ≥ 2, not after./::, and not exactly a name this buffer declares (fix round:in,re,outas signals stay quiet; an undeclared word ghosts in any position, expressions included). A word that is already a keyword only extends across_(always→always_ff;end,for,caseget nothing — a ghost after a finished keyword is noise a stray Tab accepts) — unless the popup has that keyword selected: an explicit selection wins (endwithendmoduleselected ghostsendmodule). Choice: the popup'sselectedCompletionInfo.textwhen present and its range is exactly the typed word (start of the word to the cursor; any other range is read as no selection and never echoed back) — ghost exactly it, over that range, if it is a reserved word of the dialect extending the word, otherwise no ghost, since VS Code would hide a disagreeing one; else the first of a fixed priority list (PRIORITY); else shortest-then-alphabetical overKEYWORDS. A.vbuffer is limited to the IEEE 1364-2005 reserved words. Item shape: with no selection, empty range at the cursor and the suffix as a snippet value (the existing ghosts' shape); with a selection, the selection's range and the whole keyword (LSP 3.18: "must extend the text of the selected item and use the same range"). -
Extension bridge (corrected in the fix round, QA finding 2).
vscode-languageclient9 passes VS Code'sselectedCompletionInfothrough unconverted, so avscode.Rangegoes out in itstoJSONarray shape and the trigger kind as VS Code's 0/1 rather than LSP's 1/2. Nothing was broken by this: serde decodes the server'sRangestruct from a two-element sequence and the trigger kind is ani32newtype, so the request decoded and the template ghosts kept working (pinned byqa_an_array_shaped_range_and_a_zero_trigger_kind_still_decode). Themiddleware.provideInlineCompletionItemsre-spelling both (typing.protocolInlineContext) is correctness hygiene: the spec's spelling on the wire, and correct trigger kinds for any server that reads them. -
Port items.
completion/connection.rs. Applies to both connection lists — ports afterinst (and parameters after#(. Connected entries are thoseconnected_namesfinds (the entry being re-typed excluded); they getsortText1<name>andlabelDetails.description = "connected". Within each group the order is the match order, as before (sortTextis alphabetical by name within a digit, also as before). Snippetname(${1:fill})/name(${1})only for a client with snippet support, no(after the identifier run being replaced (same line, spaces/tabs skipped), and a plain-identifier name. Pre-fill when the scope chain at the cursor binds aNet/Var/Port(ports) orParam/LocalParam(parameters) of the same name. An auto-closed)is not handled: the popup is reached after a., where no paren has been typed yet; if the user had typed.cl(and gone back, the(check already gives the bare name. -
Known limits accepted by the lead (QA notes 6–11).
- LIMIT starvation moved (6): with ≥ 512 names in this file matching a
one-letter prefix (a synthetic 600-
logic aN;buffer), templates and keywords fall out of the one-letter answer;isIncompleteis true, so the second letter re-asks and gets them. Largest real case seen: 220 items (rinibex_core.sv). - Token under the cursor (7): tier 3 skips it even mid-word, so a word this file uses exactly once and declares nowhere drops out while the cursor is inside it.
- Body indent inside
fork(8): the body line's indent is the existing nesting model's answer (identical to the plain newline answer), soinitial fork\n begin+ Enter gives an 8-space body over a 4-spaceend. - Pre-fill (9) accepts a same-named signal declared after the instance — the scope chain binds it either way.
- Last line under formatOnType (11): there the answer is one edit whose
range contains the cursor, so VS Code probably leaves the cursor after
the
end; the extension path puts it back itself.
- LIMIT starvation moved (6): with ≥ 512 names in this file matching a
one-letter prefix (a synthetic 600-
Handshakes
- Consumes
pairs::analyze(unchanged),on_type::level_at(unchanged, called from the child module),Semantics::symbols()/scopes(),signature::enclosing_list,candidates::{Query, rank_cmp}. - Changed, crate-internal:
on_type::on_type_formattingtakes a fifth argumentauto_end: bool(one caller,server/formatting.rs). The inline entry point is nowinline::inline_completions_in_context(ws, uri, position, selected); the old three-argumentinline_completionssurvives as a#[cfg(test)]wrapper soinstantiate.rs's test (outside this lane's files) compiles unchanged.completion::member_answertakessnippets.tiers::visible_symbolsispub(super). Fix round:on_type::begin_owes_an_end(doc, begin_index)(pub(crate), re-exported fromon_type/auto_end.rs) is whatinline.rs'sbeginghost gate now asks. - Changed, protocol-visible: popup
sortTextdigits (table above) — any client or test that pinned2/3/4/5for index/template/keyword/word sees4/5/6/7; templatesortTextgains a rank; connection items gainlabelDetailsand snippettextEdits. Settingslucisv.autoEnd,lucisv.inlineKeywords(both boolean, default true, absent = on). - Outside the file list, flagged:
editors/vscode/.vscodeignoregainedtyping_test.js(andtyping.jsin its comment), as the lane brief's pointer to the restart.js/.vscodeignore pattern implied. - No request to the parser, semantic or formatter crates.
Status / TODO
- auto-
endon Enter: server (on_type/auto_end.rs, setting, wire) and extension (typing.js,extension.js,package.json) - clock+reset templates (ghost + popup order)
- current-file ranking (
completion/buffer.rs, tier table) - keyword ghosts (
inline/keywords.rs, setting, extension bridge fix) - port items (
completion/connection.rs,member.rs) - unit, e2e and node tests; VS Code README; TODO §68.1 ticked
- confirmed in a running VS Code (see QA log — nobody has seen it yet)
Work log
-
2026-11-17 (dev, Opus 5.5). All five deliverables.
on_type/auto_end.rs(new child module ofon_type.rs): the begin-newline answer;on_type_formattingtries it first whenauto_endand falls back to the unchanged indent answer. Old on-type tests passfalse, so their pins are untouched; 15 new tests (steal case, balanced, inner-closed with outer missing, label + comment, wrapped header,end else begin, case item, tabs, CRLF, last line, setting off, non-begin lines, text carried down, begin two lines up).templates.rs/inline.rs/completion: with-reset first; templatesortTextby registry rank (the label alone sortedalways @(*)first).completion/buffer.rs(new): tiers 2 and 3;word_tierreads only the table now. Decision: the typed token itself is not offered back (goldenthe_short_answers_are_what_they_always_wereupdated, reasoned in place).inline/keywords.rs(new): keyword ghosts. Deviation from the brief's "proper prefix of a keyword": a finished keyword only extends across_. Found and fixed theselectedCompletionInfo/trigger-kind serialization gap in the client bridge.completion/connection.rs(new) +member.rs: connected ports kept and marked, snippet entries, pre-fill; parameters treated the same way.- Extension:
typing.js+typing_test.js(35 checks), wired inextension.js(middleware + change listener), two settings inpackage.json, README feature table and settings. smoke.jsnot changed: no existing probe's expectation moved (smoke run recorded in the report).
-
2026-11-17 — fix round 2026-11-17 (dev, Opus 5.5), after QA and the lead's rulings:
owes_an_end: closed also when the matchedendsits at thebegin's own line's indentation; an unmatchedbeginin a branched`ifdefregion arms nothing (branched_regions). Tests:a_gnu_style_begin_already_closed_under_itself_gets_no_end,qa_ifdef_branches_sharing_one_end_get_no_second_end(both QA repro cases),an_ifdef_with_no_else_still_arms_the_answer.- "Extension bridge" assumption reworded: nothing was broken.
- Keyword ghost: none for a word that is exactly a name the buffer
declares (
Semantics::symbols()scan). - An explicit popup selection skips the finished-keyword rule
(
reserved_extension). - A selection whose range is not exactly the typed word is read as absent.
typing.jsstrips trailing/* … */comments too (4 new checks).- The inline
beginghost gate askson_type::begin_owes_an_end(newpub(crate)re-export), so the stealing case ghosts itsend; testa_begin_typed_inside_a_balanced_block_still_offers_its_end. Known limits 6–11 written into Assumptions.
QA log
-
2026-11-17 (QA, Opus 5.5). Verdict: pass with findings — no MUST-FIX. Two SHOULD-FIX, the rest NOTEs for the lead.
Gates (re-run by QA).
cargo fmt --checkclean. Guardedcargo clippy -p lucisv_server --all-targets: 0 warnings. Guardedcargo test -p lucisv_server: 1813 unit passed / 36 ignored, e2e 102 / 2 ignored, grammar 3, opentitan_references 0 / 2 ignored (guard exit 0); after the QA tests below, 1816 unit.node --test editors/vscode/*_test.js: 9 files pass (typing_test 35 checks, 48 with QA's). Release build +node editors/vscode/smoke.js target/release/lucisv-server: OK, 67 messages.Scope. Diff touches only the §68.1 file list plus the flagged
.vscodeignoreline; no parser/formatter/linter/semantic change. (gemini_review.mdat the root is untracked but dated 2026-10-19 — not this lane's.) Production lines (beforemod tests):auto_end.rs184,keywords.rs242 (125 of them the Verilog word table),buffer.rs68,connection.rs55,inline.rs331 (was 319),on_type.rs361 (354),completion/mod.rs287 (245),member.rs209 (187),tiers.rs162 (186),settings.rs240 (234),templates.rs326 — none near 600; no new function over 80 lines. Nounwrap/expect/panic!in added non-test code;auto_end.rsindexestokens[...]with indices bounded by construction (prev < first <= begin < len).How. A Python stdio LSP driver against the release binary, and the same driver against a release build of
HEAD(exported withgit archive, own target dir) for before/after; sabotage-free throwaway copy for the corpus sweep. Scripts and outputs: the QA scratchpadqaA/(autoend.py,ghosts.py,ports.py,perf.py,labels.py,starve.py).Auto-
end. 46 hand cases applied to the buffer and read: nested stealing inside a balancedalways_comb, case items, generateif/nestedfor … begin : g, function/task/class method,fork … join,begin : label(any spacing),begin // c,begin /* c */,else begin,end else begin, wrappedelse if (b &&\n c) begin,@*,@(*),#5 begin,assert … else begin,unique if,blk: begin, header on the line above thebegin, tabs, CRLF, last line with and without a final newline, whitespace-only new line with the cursor mid-indent — all write the rightendat the right column. Declines (and the declined answer is byte-identical toHEAD's indent answer in every case): balanced block,beginin a comment / string / escaped identifier / attribute,`defineline (with and without\continuation),begin endon one line, text carried down, two blank lines, a buffer that does not lex.autoEnd=falseequalsHEADin all 46. Idempotence: applying each answer and asking again at the same spot never writes a secondend. Corpus sweep (860 files, every one of 8 235 lines ending inbegin, Enter simulated after it): 0 spuriousends; positive control (file truncated after its firstbegin): 512/525 armed; 0 corpus files have a permanently unmatchedbegin. Timing: < 1 ms per answer.Ghost/popup templates.
always_ff @(ghosts with-reset then clock-only;always @(with-reset, clock-only,*; popupalwin.sv:always_ff with reset,always_ff @(posedge clk),always_comb begin/end; in.v: with-reset, clock-only,@(*). Snippet syntax well-formed, tab stops 1, 2 (mirrored$2in the popup body), 3/4,$0.Ranking. Tier digits match the table; dedup by first push. Labels offered at 68 positions in
ibex_core.sv(mid-word and word-end): none lost againstHEAD. Timing per completion (20 requests, minus an empty session; two runs each), HEAD → NEW:picorv32.va0.25/0.29 → 0.43/0.35 ms,r0.36/0.33 → 0.50/0.58;ibex_core.sva0.09/0.22 → 0.27/0.33,r0.65/0.63 → 0.71/0.74. Sub-millisecond either way.Keyword ghosts. None in a line/block comment, an unterminated string, after
./::/backtick, for$dis, or mid-word;.vgetsalways/localparam(nologic); each setting off independently. Selection present with a keyword → that keyword over its range; with a non-keyword → nothing. The extension bridge is real:vscode-languageclient9.0.1asInlineCompletionParamspassescontextthrough (InlineCompletionContext.create(triggerKind, selectedCompletionInfo)), andmiddleware.provideInlineCompletionItems(document, position, context, token, next)is the hook it calls.Port items. Unconnected first, connected after with
connected(including a port connected after the cursor and a port connected twice);.name(${1}), pre-filled only from a visible net/var/port (a same-namedlocalparamis not used for a port; aclkin a named block or another module of the file is not used);#(.pre-fills from alocalparam; escaped port → bare name;.*present → fine; unknown module → empty;.cl|(x)→ bare; no snippet support → bare everywhere.Findings.
- SHOULD-FIX — a second
endin complete code when the file holds another unmatchedbeginand this block'sendis not at the owner's column. The accepted heuristic, but the GNU layout makes it reachable in valid code:module m;\n`ifdef A\n always @(posedge clk) begin\n`else\n always @(posedge clk or negedge rst) begin\n`endif\n if (x)\n begin\n|\n y <= 1;\n end\n end\nendmodule→endwritten under theif, so the file now has oneendtoo many. Same with the cursor after the first`ifdefbranch'sbegin(anendlands inside branch A). Any mid-edit unmatchedbeginabove has the same effect on a GNU-style block below. Corpus exposure measured at 0 (no corpus file is permanently unbalanced). Suggested: also treat thebeginas closed when its matchedendstarts its line at thebegin's own line indentation. Lead to rule. - SHOULD-FIX (docs) — the "Extension bridge" assumption overstates the
bug it fixes. The server does decode VS Code's array-shaped range and
trigger kind 0 (serde reads a struct from a sequence); before the bridge
the request did not fail and the template ghosts did not die. The bridge
is still right (spec spelling, correct trigger kinds). Pinned by
qa_an_array_shaped_range_and_a_zero_trigger_kind_still_decode. The README paragraph should say so. - NOTE — keyword ghosts with no popup open fire on declared names and in
expression position:
assign out = in→put,x = re→turn(returnis ahead ofreginPRIORITY;.svonly),x = ou→tput,x = al→ways_ff. With the popup open VS Code's selection is normally the exact-match signal, which silences the ghost. Lead to rule whether an exact declared name or a non-statement position should suppress it. - NOTE — the finished-keyword rule also applies to an explicit popup
selection: typed
endwithendmoduleselected → no ghost (spec says the ghost follows the selected item). Preview only; the popup accepts it anyway. - NOTE — a
selectedCompletionInfowhose range is elsewhere is echoed back as the item range (VS Code would drop it); one missingtextfails the whole request with -32602 (pre-existing decode behaviour). - NOTE —
LIMITstarvation moved: with ≥ 512 names in this file matching a one-letter prefix (synthetic: 600logic aN;in another module), templates and keywords fall out of the answer (HEADkept them;isIncompleteis true, so the second letter re-asks). Not seen on real files (largest: 220 items forrinibex_core.sv). - NOTE — the typed token itself is skipped by tier 3 even mid-word, so a
word the file uses exactly once and declares nowhere drops out while the
cursor is inside it (68-position check found no case in
ibex_core.sv). - NOTE —
fork … joinbody:initial fork\n begin+ Enter gives an 8-space body over a 4-spaceend; the body indent is the nesting model's (identical toHEAD's plain answer), not the lane's. - NOTE — pre-fill accepts a signal declared after the instance
(
sub u (.);\n logic clk;→clk(${1:clk})). - NOTE —
typing.jsstrips//comments only:begin /* c */+ Enter gets anendwitheditor.formatOnTypeon (server answers) but not with it off (extension never asks). - NOTE (unverifiable here) — the last-line answer is one edit whose
range contains the cursor; with
editor.formatOnTypeon, VS Code will likely leave the cursor after theend, not on the body line (the extension path puts it back itself). Needs a running VS Code, as do: the one-step undo, the extension'sdidChange-before-request ordering (readingvscode-languageclient9.0.1 it holds: the incrementaldidChangeis sent from microtasks before thesetTimeout(0)task), and the ghost following the popup.
QA tests added.
on_type/auto_end.rs:qa_asking_again_after_the_answer_is_applied_adds_no_second_end(9 armed shapes),qa_a_declined_newline_is_exactly_the_plain_indent_answer(9 declining shapes, incl.`define,`ifdefboth branches, string, escaped\begin).inline/keywords.rs:qa_an_array_shaped_range_and_a_zero_trigger_kind_still_decode.editors/vscode/typing_test.js:qaEdges(13 checks: multi-cursor, redo, no editor, refused edit, CRLF position, pastes, context without a range). - SHOULD-FIX — a second
Review
2026-11-17 — lead (after dev, QA, one fix round)
Accepted. QA found no corruption, crash or spec violation; both SHOULD-FIX items and the rulings below went into the fix round, and the dev's gates after it are green (unit 1 823, e2e 102, node 9 files, smoke OK).
Rulings recorded:
- Auto-
endis armed by any unclosedbeginat or before this one, not by thisbegin's own span (the stack matcher lets a new innerbeginsteal the outerend). Closed means: matched by anendthat starts its line at the indentation the answer would write, or at thebegin's own line's (GNU layout). Abeginunclosed inside anifdefregion with anelse/elsifarms nothing — the sharedendafterendifis itsend. - No keyword ghost for a word that is exactly a name this buffer
declares (
in,re,outas signals stay quiet). Anything else that is a keyword prefix ghosts, in any position — the owner asked for "always". - An explicit popup selection wins over the "finished keyword only
extends across
_" rule; a selection whose range is not the typed word is ignored. - Accepted limits (in Assumptions): LIMIT 512 can drop templates/keywords in a 600-same-prefix buffer; the token under the cursor is not offered back; port pre-fill accepts a later declaration; the last-line answer is one edit that contains the cursor.
Not verified by anyone: every behaviour in a running VS Code — the
cursor after begin + Enter (formatOnType on and off), one-step undo, the
ghost following the popup selection, the dimmed connected detail. The
list is in the dev's report and the QA log; it is the owner's acceptance.