Files
Guoliang ChenandClaude Mythos 5.2 948f8a0b32
release / build-and-publish (push) Successful in 5m28s
Release 0.65.3: comment keywords, and the brackets in comments explained
TODO §71.8. TODO, FIXME, FIX_ME and TBD inside // and /* */ comments are
drawn bold in a new theme colour (lucisv.commentKeyword), as whole words and
never in strings or code; lucisv.commentKeywords.custom adds the user's own
words, .builtIn switches the four off, .caseSensitive ignores case, all live.
Client-side editor decorations: commentScan.js finds comments with the
grammar's own comment and string rules (0 mismatched lines against
vscode-textmate over OpenTitan hw's 1 185 823 lines), commentKeywords.js
matches literally over the visible lines only, with the block-comment state
cached per document.

The brackets sometimes coloured inside comments are VS Code's bracket-pair
colourisation before background tokenization completes, not lucisv (grammar
and semantic tokens measured clean); explained in the notes, not changed.

Dev, QA (pass with findings, one fix round) and lead review are in
docs/features/comment-highlighting/README.md. Not seen in a running editor.

Version bump (Cargo.toml, Cargo.lock, editors/vscode/package.json and both
package-lock.json spots); notes in CHANGELOG.md (## 0.65.3) and
editors/vscode/CHANGELOG.md.

Gates: tools/gates.sh PASS on this tree (20261119-050504), node 37/0.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-19 05:06:35 -08:00
..

comment-highlighting

Goal

The owner (TODO §71.8): "Sometimes there is syntax highlighting in the comment. Like a signal with bracket like signal[]. I saw the [] are getting highlighted. Not needed. But there is one thing that is needed: please highlight the TODO, FIXME, FIX_ME, TBD in the comment. Also give the user an option to highlight a custom word that is specifically in the comment."

Two parts. Part 1 finds out why [] inside a comment is ever coloured, and fixes whatever of that is lucisv's. Part 2 paints TODO, FIXME, FIX_ME and TBD — and any words the user lists in lucisv.commentKeywords.custom — in a bold theme colour wherever they appear as whole words inside // or /* */ comments, and nowhere else.

Part 1 — why [] inside a comment gets coloured

The colour on [] is VS Code's bracket pair colourisation (editor.bracketPairColorization.enabled, on by default), which colours every pair from language-configuration.json's brackets — unless the token under the bracket is not StandardTokenType.Other. Three candidate causes were checked; neither lucisv's server nor its grammar is the cause. The colour comes from one VS Code state in which the grammar's comment scopes are not consulted at all, which an extension cannot change. Part 1 is an explanation, not a fix: there is no fix in the extension's power that does not also take bracket colours away from code (see the mitigations below).

How VS Code decides (verified against microsoft/vscode main, 2026-11-19).

  • bracketPairsTree/tokenizer.ts, NonPeekableTextBufferTokenizer.read(): a bracket is a bracket only when TokenMetadata.getTokenType(tokenMetadata) === StandardTokenType.Other and the token's balanced-bracket bit is set; the metadata comes from textModel.tokenization.getLineTokens(...). A comment token (comment.* scope → StandardTokenType.Comment) never yields a bracket. FastTokenizer, in the same file, reads no token metadata: it runs one regex over the whole text and treats every match as a bracket.
  • bracketPairsTree/bracketPairsTree.ts, constructor: when the model has no tokens yet it builds initialAstWithoutTokens with FastTokenizer; when background tokenization is still in progress it builds it from the buffer's current tokens (untokenized lines are one Other token each). Every colourising query reads this.initialAstWithoutTokens || this.astWithTokens, token-only changes never update initialAstWithoutTokens (handleEdits(…, tokenChange) skips it), and it is cleared only in handleDidChangeBackgroundTokenizationState once the state is BackgroundTokenizationState.Completed.
  • TextMateTokenizationSupport.tokenizeEncoded (read from VS Code 1.145.2's shipped workbench.desktop.main.js and its tokenization worker): line.length >= maxTokenizationLineLength ? nullTokenizeEncoded(languageId, state) : … — a line at least editor.maxTokenizationLineLength (default 20 000) characters long is one Other token and carries the state across unchanged. That token has no balanced-bracket bit (nullTokenize.ts; QA's reading of the 1.145.2 bundle: (s<<0|0|0|32768|2<<24)>>>0, no 1024, where the store default for a not-yet-tokenized line has it), so once such a line is tokenized its brackets are not colourised at all — in code or in comments.
  • semanticTokensProviderStyling.ts, getMetadata: semantic tokens set only font-style and foreground bits (plus the matching SEMANTIC_USE_* flags); never the token-type bits. So no semantic token can make a bracket in a comment coloured, or one in code uncoloured.

So [] in a comment is coloured exactly when the file was just opened, until background tokenization finishes. The first AST is token-blind, and stays in charge until the whole file has been tokenized — on a multi-megabyte file that takes visibly long, which matches "sometimes". Then the colours in comments disappear by themselves. (A variant of the same mechanism, from QA: after an edit opens or closes a /* above, the lines below keep their old tokens until the background tokenizer reaches them again, so their brackets may briefly keep or lose colour.)

Corrected after QA F1: the first version of this README named a second case, lines of editor.maxTokenizationLineLength or more. That was wrong: such a line's null token lacks the balanced-bracket bit, so after tokenization its brackets are not coloured at all; it is coloured only during the same token-blind phase as every other line.

Bracket colourisation is off entirely above 5 000 000 characters (bracketPairsImpl.ts, canBuildAST), and tokenization above 20 MiB or 300 000 lines (textModel.ts, _isTooLargeForTokenization), so neither of those is another case.

Mitigations considered, none adopted:

  • balancedBracketScopes/unbalancedBracketScopes on the grammar contribution: no help — they only set the balanced-bracket bit on TextMate tokens, and the token-blind tree reads no tokens.
  • colorizedBracketPairs: [] in language-configuration.json (QA's note): it would remove the colouring in comments, but it also removes every bracket-pair colour in code, for every user. A net loss, and the owner's call, not this lane's. A user who wants it can set "[systemverilog]": { "editor.language.colorizedBracketPairs": [] } (and the same for [verilog]) themselves.
  • Decorations repainting brackets in comments with the comment colour: there is no theme colour for the theme's comment token colour, and it would compete with VS Code's own bracket decorations.
  • editor.bracketPairColorization.enabled via configurationDefaults: the user's switch, not ours to flip. lucisv cannot shorten VS Code's background tokenization either.

What was ruled out, with evidence (one-off scripts, 2026-11-19).

  • The TextMate grammar. Run through the real vscode-textmate 9.3.2 and vscode-oniguruma 1.7.0 that VS Code 1.145.2 ships (extracted from its node_modules.asar into a scratch directory; not a dependency of anything here), compared per character against the server's own comment semantic tokens, on 309 OpenTitan files (every 13th of hw/, 69 249 lines): 0 characters the lexer calls comment that the grammar does not, so in the steady state every bracket the lexer considers commented-out is uncoloured. The other direction has 39 lines — comments inside a `define body or inside a macro call's arguments (`DV_SPINWAIT(… // …)), which the lexer keeps as macro text and the grammar (rightly, visually) shows as comment. Neither direction colours a bracket in something that looks like a comment. Every comment form the brief named is scoped: // after a macro or a `ifdef, /* */ across lines, comments after directives; (* *) is correctly not a comment (it is an attribute, and its parentheses are code).
  • Server semantic tokens. In the same run (semanticTokens/full): 0 non-comment semantic tokens start inside a comment, by the lexer's spans or by the grammar's. Repeated through the large-file window path (semanticTokens/range on one 12 MB, 357 172-line concatenation of 1 500 OpenTitan files, so semantic_tokens_in_window answers): again 0. The server only ever emits tokens from lexer tokens, whose comments are trivia, and from instantiation::overrides, keyed by syntax-tree token starts. Nothing to fix in crates/lucisv_server/src/tokens*, so no Rust changed.
  • lucisv's own rainbow. It paints only begin/end/fork/join ranges from pairs.rs, computed over Document.tokens (comments excluded) — never a bracket.

One divergence between the grammar and the lexer was found and is not the reported problem: an escaped identifier containing // (\a//b ) is an identifier to the lexer and a line comment to the grammar. It is filed under Status / TODO as a follow-up.

Part 2 — mechanism, and why

Editor decorations for every word (option (b) of the brief), in two new modules: commentScan.js (pure — where the comments are, which words match) and commentKeywords.js (the VS Code wiring). Considered and rejected:

  • (a) TextMate patterns for the built-ins, decorations for custom words. Two mechanisms painting the same thing in two different ways: a TextMate scope is coloured by the theme's tokenColors, which most themes do not define for a TODO scope, so the built-ins would look different from the custom words, and a contributes.colors default cannot reach a TextMate scope. Turning the built-ins off would also need a grammar the user cannot edit.
  • (c) A server-side semantic-token modifier. Splits every comment token, colours through semanticTokenColors/semanticTokenScopes rather than a contributed colour (so no guaranteed visible default), is Rust outside this lane's mandate, and the server would have to learn the words.

Decorations give one colour id (lucisv.commentKeyword, contributed with opaque defaults for all four theme kinds), apply to built-in and custom words identically, and re-read settings in the extension host without a round trip.

Comment detection agrees with the grammar, by construction and by measurement. The grammar decides "comment" with exactly two rules (//.*; /\* … \*/, multi-line) and hides them with one (a string, " … " or end of line, \\. escapes). Every other top-level rule (directives, macros, system tasks, numbers, keywords) is built only of characters that can never be / or ", so it can neither swallow nor reveal a comment start — commentScan.js mirrors those three rules and nothing else, and commentScan_test.js pins them: the comment and string rules must deep-equal what the scanner mirrors, and no other top-level rule may contain /, ", ., [^, \S, \W, \D or \N. Measured against the real tokenizer (the extracted vscode-textmate, as above) over all 4 029 OpenTitan hw files, 1 185 823 lines, 39.3 M characters, 8.39 M of them comment: 0 lines where the scan and the grammar disagree on a single character, plus a table of 20 hand-written edge lines (strings holding // and /*, escaped quotes, an escaped backslash before the closing quote, a backslash at end of line, an unterminated string, /*/, /**/, /***/, `define with a trailing comment, `ifdef with one, (* *), an escaped identifier). The pictures in the scanner test's comment table are copied from that tokenizer's output, not hand-counted.

Why the grammar's notion and not the lexer's: the keyword is meant to stand out where the user sees a comment, and what they see is the grammar (the server's comment semantic token covers a subset of it — see Part 1). Matching the lexer instead would leave a TODO inside a `define body's // comment unpainted although it is drawn as a comment.

Cheap on big files. Only the visible ranges plus 50 lines either side are scanned for words. Whether a line starts inside a block comment is kept per document (LineStates), computed lazily from the top and truncated from the first edited line down — so typing re-scans nothing above the edit, scrolling re-scans nothing it has already passed, and the first paint at the bottom of a file reads each line above it once (indexOf-driven, no tokenizer). An edit above the viewport does re-walk every line from the edit down to the viewport (state only, no word matching): QA measured, on a fake 100 000-line document, first paint at the bottom 12.3 ms / 100 000 reads, repaint 0.17 ms / 110 reads, edit at the top while viewing the bottom 7.9 ms / 100 000 reads, edit in the middle 3.3 ms / 50 000 reads, edit inside the viewport 0.10 ms / 110 reads (the fake understates lineAt's real cost). Edits are debounced 100 ms. A line of editor.maxTokenizationLineLength or more — read with the document as scope, so a [systemverilog] override counts — is skipped and carries the state across, exactly as VS Code does, and a megabyte-long netlist line is never scanned. A file VS Code does not tokenize at all (with editor.largeFileOptimizations on: more than 20 MiB of text or more than 300 000 lines) is not painted at all; VS Code makes that decision once per model and so does this, on a document's first paint. So the highlight appears only where VS Code draws comment colour.

Assumptions

  • The grammar file is the one in syntaxes/ and no other extension's grammar replaces it for verilog/systemverilog. With another grammar active, the scan may disagree with what is drawn.
  • VS Code draws a decoration's color over the token colour (both semantic and TextMate). This is how decoration colours have always rendered; not verified in a running editor here.
  • "Whole word" means \b-style boundaries with $ counted as a word character (Verilog identifiers contain $): a word that starts with [A-Za-z0-9_$] must not have one just before it, and one that ends with one must not have one just after. So TODO skips TODO_reg, myTODO, $TODO, TODO1, and REVIEW: matches in REVIEW:x. The word characters are ASCII only ([A-Za-z0-9_$], Verilog's identifier set): a custom word that starts or ends with a non-ASCII letter has no boundary on that side, so ÄNDERN lights inside fooÄNDERN (QA F5; as designed, not changed).
  • A string continued with backslash-newline ends, to the grammar, at the end of its line ("|$), so the continuation line is code and a // TODO on it is painted — which matches what is drawn (QA F7; by design).
  • Words are matched only in a comment's body — never across its own //, /* or */ — so a custom word made of * or / cannot light up a delimiter.
  • Editor background colours of the built-in themes used for the contrast test: Dark Modern #1F1F1F, Dark+ #1E1E1E, Light Modern/Light+ #FFFFFF, HC Dark #000000, HC Light #FFFFFF. A comment line with the current-line highlight or a selection behind it is not measured.

Decisions the brief asked for

  • Can the built-in four be removed? All together, yes: lucisv.commentKeywords.builtIn: false. Individually, no — that is a list edit with no use case named; anyone who wants two of them turns the built-ins off and lists those two in custom. The custom list is additive (default []), so adding a word never silently loses the built-ins — which is what would happen if the four were the array's default, because VS Code replaces an array setting rather than merging it.
  • Regex metacharacters are matched literally: every word goes through escapeRegExp before it joins the alternation; nothing a user types is ever interpreted as a pattern.
  • No catastrophic patterns: the matcher is an alternation of escaped literals, longest first, each wrapped in at most one one-character lookbehind and one one-character lookahead — no quantifiers at all. The test runs the worst the caps allow (50 near-identical 40-character words of a) over a 19 993-character comment of a and requires it under 2 s; it takes ~4 ms.
  • Caps: at most 50 custom words (entries past the 50th are ignored), each 1–40 characters with no whitespace. An unusable entry — empty, too long, containing whitespace, not a string — is skipped, and one line (lucisv: lucisv.commentKeywords.custom: ignored N entries (…)) goes to the lucisv output channel. The package.json schema says the same (minLength, maxLength, pattern: ^\S+$, maxItems, uniqueItems), so the settings editor warns before the extension has to.
  • Case: case-sensitive by default (todo in prose stays plain); a boolean, lucisv.commentKeywords.caseSensitive, makes it insensitive — it costs one regex flag, so it is offered. Duplicates are dropped case-insensitively then.

Handshakes

  • Consumes syntaxes/systemverilog.tmLanguage.json's comments and strings rules and the shape of every other top-level rule. Promise to whoever edits the grammar: commentScan_test.js fails on any change to those two rules, on a reordering that moves them off the top, and on any other top-level rule that could match / or "; update commentScan.js in the same change. The Rust keyword test (crates/lucisv_server/tests/grammar.rs) is untouched — the grammar did not change.
  • Consumes editor.maxTokenizationLineLength (per document, language overrides included) and editor.largeFileOptimizations (read, never written).
  • Provides the settings lucisv.commentKeywords.builtIn, lucisv.commentKeywords.custom, lucisv.commentKeywords.caseSensitive and the colour lucisv.commentKeyword. The server receives them in workspace/didChangeConfiguration with the rest of lucisv and ignores them (it only reads named keys; checked in settings.rs).
  • extension.js: one require and one construction in activate, after the rainbow's decoration types; the module pushes its decoration type and every listener (including onDidOpenTextDocument, for language-mode changes) into context.subscriptions. It needs nothing from the server.
  • Packaging: commentKeywords.js and commentScan.js are runtime modules (listed in tools/RELEASING.md's runtime-module sentence and the .vscodeignore header); their two *_test.js files are excluded.
  • No Handshake requests to other lanes: nothing outside this lane's file list needed changing.

Status / TODO

  • Part 1: find the cause of the bracket colouring, with evidence (VS Code's token-blind first AST and over-long lines; server and grammar cleared, measured).
  • Part 1: fix what is lucisv's — nothing is; no grammar or Rust change.
  • commentScan.js: grammar-equivalent comment scan, literal whole-word matcher, settings normalization with caps, incremental line states.
  • commentKeywords.js: decorations on visible ranges, debounced edits, immediate setting changes, maxTokenizationLineLength honoured.
  • package.json: three settings, one colour (one dot in its id).
  • Tests: commentScan_test.js (14), commentKeywords_test.js (11 after the QA round, incl. the contrast check).
  • Agreement with the real vscode-textmate over all of OpenTitan hw (one-off; recorded above).
  • README (extension), .vscodeignore, tools/RELEASING.md.
  • Follow-up, not in this lane: the grammar has no rule for escaped identifiers, so \a//b is drawn as a comment from // on, and — worse — \a/*b opens a block comment that runs to the next */, possibly many lines down (QA F6). A \\\S+ rule ahead of #comments would fix both — but it changes the scan's mirrored rules too, so it goes with a commentScan.js change.
  • QA fix round (F1–F7), see work log.
  • Seen in a running VS Code (cannot be done by the dev agent — see the QA checklist in the work log).

Work log

2026-11-19 — dev (Opus 5.5)

  • Read the grammar, language-configuration.json, tokens.rs, the rainbow wiring. The rainbow only paints begin/end/fork/join; the server's semantic tokens never include punctuation except the instantiation # overrides.
  • Verified VS Code's bracket colourisation against microsoft/vscode main (bracketPairsTree/tokenizer.ts, bracketPairsTree.ts, bracketPairsImpl.ts, textModel.ts, semanticTokensProviderStyling.ts) and the installed 1.145.2 bundle (maxTokenizationLineLength, >=).
  • Built lucisv-server (debug) in this worktree and wrote two one-off scripts in the session scratchpad (not shipped): compare.js (grammar via the real vscode-textmate vs the server's semantic tokens, over LSP stdio) and agree.js (commentScan.js vs the real tokenizer). Numbers in Goal. Every run went through tools/guard.sh.
  • Decision: no grammar change, no Rust change (Part 1 found nothing of lucisv's to fix). Decorations for all words (Part 2), detection mirroring the grammar rather than the lexer, explained in Goal.
  • Words match in a comment's body only, after a test showed a custom */ word lighting the comment's own delimiter. Word boundaries changed from "neither neighbour is a word character" to \b-style per word edge, so a word ending in punctuation (REVIEW:) still matches before a letter.
  • The window scan records each line's successor state while it scans it, so a paint reads each window line once (the visible-range test counts reads: 450 above + 121 in the window, then 121 on a repaint).
  • What a human should look at in VS Code (the dev cannot see a running editor):
    1. A .sv file with // TODO: x, /* FIXME */, // FIX_ME TBD, a three-line /* … TODO … */, "// TODO" in a string, TODO_reg in code: the four in comments are bold orange (Dark Modern and Light Modern), the string and the identifier are not.
    2. Add "lucisv.commentKeywords.custom": ["XXX", "a.b"] in settings.json: XXX lights at once, a.b lights but axb does not — no reload. "builtIn": false removes the four at once; "caseSensitive": false lights todo.
    3. Type /* at the top of a file: every TODO below lights up after a beat; delete it: they go back.
    4. Open a multi-MB OpenTitan-sized file and scroll to the end: the keywords appear as you scroll, typing stays smooth.
    5. Part 1, the cause: open a large .sv (a few MB) with x[3:0] in comments and watch the brackets inside comments lose their colour once tokenization finishes (a few seconds). If they stay coloured on a normal-length line after that, Part 1's conclusion is wrong — check Developer: Inspect Editor Tokens and Scopes on the bracket and report the scope and which extension provides the grammar.
    6. workbench.colorCustomizations: { "lucisv.commentKeyword": "#FF0000" } recolours them.

2026-11-19 — dev (Opus 5.5), QA fix round

  • F1: Part 1 now names one cause only (the token-blind tree until background tokenization completes); the long-line case is struck with the reason (null token, no balanced-bracket bit) and a "corrected after QA" note. Stated plainly that Part 1 is an explanation with no fix in the extension's power; mitigations listed, including QA's colorizedBracketPairs: [] (not adopted: it removes bracket colour in code too). Changelog paragraph corrected.
  • F2: commentKeywords.js reads editor.maxTokenizationLineLength with the document as scope; each document's record keeps the cutoff its states were computed with and starts over when it changes (so the configuration handler no longer clears a global cache). Test: a [systemverilog] override applies to the .sv document and not to a verilog one, and dropping it recomputes.
  • F3: verified in src/vscode-dts/vscode.d.ts (main, 2026-11-19): onDidOpenTextDocument/onDidCloseTextDocument fire "when the language id of a text document has been changed", setTextDocumentLanguage "will trigger the onDidCloseTextDocument event followed by the onDidOpenTextDocument event", and the open "is emitted before the document is updated in the active text editor" — so the open handler repaints on the next tick. A non-Verilog editor this module painted is cleared; one it never painted is never touched. Test with the stub: .sv → plaintext clears, back → paints without scroll/edit. The rainbow in extension.js has the same pre-existing gap (QA noted it); not changed here — it is outside this feature.
  • F4: wording fixed (here and in the extension README). Files VS Code does not tokenize (editor.largeFileOptimizations on and > 20 MiB of text — offsetAt of the end, UTF-16 units, as getValueLength counts — or

    300 000 lines) are not painted; decided once per document. Tests: 300 001 lines, 20 MiB + 1, exactly 20 MiB (painted), and the option off (painted).

  • F5, F7: documented as by design under Assumptions. F6: the escaped-identifier follow-up names \a/*b.

Changelog paragraph (for the lead)

Comment keywords. TODO, FIXME, FIX_ME and TBD inside // and /* */ comments are now bold, in a new lucisv.commentKeyword theme colour — as whole words, never in strings or code. lucisv.commentKeywords.custom adds your own words (matched literally, up to 50), lucisv.commentKeywords.builtIn turns the four off and lucisv.commentKeywords.caseSensitive makes matching case-insensitive; every change applies immediately. Only the lines on screen are searched for the words (an edit above the screen re-reads the lines down to it), and a file too large for VS Code to tokenize is not painted. Brackets that are sometimes coloured inside comments come from VS Code's bracket-pair colourisation while a newly opened file has not finished tokenizing, not from lucisv — its grammar and semantic tokens were measured to colour nothing inside a comment — and the colours go once tokenization completes; there is no extension-side fix that would not also remove bracket colours in code.

QA log

2026-11-19 — QA (Opus 5.5)

Verdict: PASS WITH FINDINGS. Part 2 (the code) holds up under every attack below. One Part 1 claim (case 2, over-long lines) is wrong against VS Code's source and the shipped 1.145.2 bundle (F1, documentation only: the code does the right thing anyway). Three low findings, three informational.

Commands and results

  • node --test editors/vscode/*_test.js: 34 files, 34 pass, 0 fail. commentScan_test.js has 14 tests and commentKeywords_test.js 8, as claimed. node --check is clean on commentScan.js, commentKeywords.js, extension.js and both tests. package.json parses, version is 0.65.2.
  • Scope: git status --untracked-files=all lists only editors/vscode/*, tools/RELEASING.md and docs/features/comment-highlighting/.
  • npx --no-install @vscode/vsce ls --no-dependencies: ships commentKeywords.js and commentScan.js; nothing matching _test or smoke ships.
  • Reproduced the dev's full-corpus number myself: tools/guard.sh -m 4 -t 600 -- node agree.js … all.txt printed {"docs":4029,"lines":1185823,"chars":39294203,"commentChars":8391566,"mismatchedLines":0}. On the scripts: agree.js is a sound per-character comparison of scanLine chained across lines against the real vscode-textmate, so it does prove agreement with the grammar on OpenTitan. It does not exercise LineStates, edits or maxLineLength; my prop_edit.js covers those. compare.js (server vs grammar) checks only where non-comment semantic tokens start. That is enough, because semantic tokens can never change a bracket's token type anyway (confirmed: getMetadata sets only font/foreground bits). Its usage line says --window but the code reads --range. That is cosmetic.
  • QA scripts (scratchpad qa71/, not shipped): scan_attack.js (82 crafted lines vs vscode-textmate), kw_attack.js (matcher, settings, wiring, perf), prop_edit.js (3 000 random edit/scroll rounds).

Part 1: VS Code source, checked independently (microsoft/vscode main, fetched 2026-11-19, plus the installed 1.145.2 workbench.desktop.main.js).

  • Confirmed: bracketPairsTree/tokenizer.ts:203-208 treats a bracket as a bracket only if getTokenType === StandardTokenType.Other and containsBalancedBrackets(metadata). FastTokenizer (:282) reads no tokens. bracketPairsTree.ts:65-79 builds the token-blind initialAstWithoutTokens when the model has no tokens yet, or from the current tokens while background tokenization is in progress. :84-93 clears it only on BackgroundTokenizationState.Completed. Token changes never update it (:121). Lines that are not tokenized yet get getDefaultMetadata (tokens/contiguousTokensStore.ts:247-256), which does set BALANCED_BRACKETS_MASK, so they produce brackets. Case 1 is right.
  • F1 (medium, documentation): case 2 is wrong. A line of maxTokenizationLineLength or more is tokenized by nullTokenizeEncoded (tokenizationSupportWithLineLimit.ts:40-41; the worker uses the same wrapper, textMateWorkerTokenizer.ts:108). nullTokenizeEncoded (languages/nullTokenize.ts:22-31) sets no BALANCED_BRACKETS_MASK. The 1.145.2 bundle agrees: the long-line token is (s<<0|0|0|32768|2<<24)>>>0 with no 1024 bit, while the store default is …|2<<24|1024. So once tokenization is complete, brackets on such a line are not colourised at all, in code or in comments. They are coloured only while case 1 applies, like every other line. Wrong text: Goal/Part 1 items "2." (lines 63-65), "case 2 has none" (line 72), and the changelog's "(or on a line too long to tokenize)" (line 323). The code is unaffected: skipping those lines in commentKeywords.js still matches what VS Code draws (no comment colour there). Suggested fix: drop case 2 and say over-long lines get no bracket colours once tokenized.
  • Missed transient (info): after an edit that opens or closes a /* above, the lines below keep their old tokens until the background tokenizer re-reaches them, so brackets there may briefly keep or lose colour. This is the same mechanism as case 1, and transient.
  • Mitigations in the extension's power:
    • balancedBracketScopes/unbalancedBracketScopes: no help. They only set the bit on TextMate tokens, and case 1 reads none. I agree with the dev.
    • colorizedBracketPairs: [] in language-configuration.json: it would remove case 1's colouring in comments, but it also removes bracket-pair colours in code for every user. That is a net loss and the owner's call, not this lane's. (I did not read in detail how FastTokenizer derives its pairs from colorizedBracketPairs. A user can get the same effect with a [systemverilog] editor.language.colorizedBracketPairs: [] override.)
    • Painting brackets inside comments with a decoration: not viable. There is no ThemeColor for the theme's comment token colour, and it would compete with the bracket decorations' CSS.
    • contributes.configurationDefaults: not ours to flip (bracketPairColorization.enabled).

Part 2: commentScan.js vs the real tokenizer (scan_attack.js): 82/82 lines agree. Cases covered: "//" and "/*" in strings, \", "a\\", a backslash at end of line (the string ends at $, so the next line's // TODO is a comment, as the grammar draws it), a 32-line block, /*/, /**/, /***/, /* /* */, // inside a block, /* inside //, tabs, an unterminated block to EOF, \a//b and \a/*b, `define bodies with both comment kinds, (* *), @(*), @ (*), (*), a/ *b, a*/b, a/*c*/d, a=b//c, emoji and accents (UTF-16 columns line up), " inside comments, "", "\"", "\\"", a stray */, and the bare // /* */ / " \. CRLF: VS Code hands lineAt().text without the EOL, so it is not a case for the scanner (agree.js splits on \r?\n too).

Part 2: commentKeywords / matcher (kw_attack.js):

  • Boundaries all as documented: TODO: TODO( (TODO) TODO. //TODO /*TODO*/ \TODO and 😀TODO😀 match. TODOs TODO_x xTODO $TODO TODO$ TODO1 FIX_ME_LATER and todo (case-sensitive) do not. TODO in a string or in code is not painted.
  • Overlaps: the longest word wins at the same start (FIX_ME over FIX, TBD over TB, !!! over !!). FIX alone never lights inside FIX_ME. Matches never overlap (a.b/b.c on a.b.c gives a.b).
  • Metacharacters are literal: a.b (not axb), (x, [, \, ^$, .* (not hello), |, ?, +, {2}, $, /, *. The words */, * and / never light a delimiter.
  • Junk: '', 'a b', 5, null, 41 characters and an object are skipped (6 counted). 40 characters is kept. Duplicates and a built-in repeated in custom are dropped. 60 words give 50 used and 10 skipped. A non-array custom gives the built-ins only (silently, with no log line: fine). caseSensitive:false matches todo/Todo and dedupes case-insensitively.
  • Wiring with a fake vscode: split views of one document each paint their own ranges from shared states. Plain-text editors are untouched. builtIn:false with an empty custom clears the decorations, and custom words apply live. Disposing every subscription removes all five listeners and disposes the decoration type (timer cleared).
  • Edit invalidation property (prop_edit.js): 3 000 rounds of 1–3 changes (replace, insert or delete lines made of /* */ // " \ TODO (* 😀 …) anywhere in a 400-line document, then a random viewport, with maxTokenizationLineLength forced to 30 so the long-line carry is exercised. Every paint was compared with a scan from line 0: 0 mismatches.
  • 100 000-line document (fake document, so lineAt cost is understated). First paint at the bottom: 12.3 ms, 100 000 reads. Repaint: 0.17 ms, 110 reads. Edit at top, viewing the bottom: 7.9 ms, 100 000 reads. Edit in the middle: 3.3 ms, 50 000 reads. Edit in the viewport: 0.10 ms, 110 reads. Edit at top, viewing the top: 0.12 ms, 111 reads. So word matching is bounded by the viewport, but the state walk is bounded by (viewport bottom − first edited line), not by the viewport. That cost is fine, but see F4.
  • Contrast, computed independently (WCAG relative luminance): dark #FF9E3D scores 8.01 on #1F1F1F, 8.11 on #1E1E1E, 7.45 on #252526 and 7.30 on #002B36 (Solarized Dark). Light #A85000 scores 5.51 on white, 4.96 on #F3F3F3 and 5.11 on #FDF6E3. HC #FFA500 on black: 10.63. HC-light #9C4A00 on white: 6.19. All are ≥ 4.5. lucisv.commentKeyword is spelled identically in package.json:491, commentKeywords.js:15 and the README.

Findings

  • F1 (medium, doc): see Part 1 above.
  • F2 (low): commentKeywords.js:75 reads getConfiguration('editor').get('maxTokenizationLineLength') with no language scope. VS Code reads it per language (textMateTokenizationFeatureImpl.ts:305-310, observableConfigValue('editor.maxTokenizationLineLength', languageId, …)). Repro: "[systemverilog]": { "editor.maxTokenizationLineLength": 100 }. VS Code then stops drawing comments on lines of 100+ characters, but lucisv still paints keywords there. A long line that opens /* also carries a different block state below, so keywords below can be painted in code or missed in comments. Fix: read it with the document as scope (getConfiguration('editor', document)) and keep the cutoff per document's states.
  • F3 (low): there is no handling of a language-mode change (commentKeywords.js:51-55, :110). VS Code reports it as close+open of the document, not as a visible-editors change. Switching a Verilog editor to Plain Text leaves its keyword decorations in place (paintEditor returns before clearing). Switching a .txt to SystemVerilog paints nothing until the next scroll or edit. Reproduced with the fake in kw_attack.js. The rainbow (extension.js repaintVisible) has the same pre-existing gap. Fix: onDidOpenTextDocument → paintVisible, and clear (setDecorations([])) for a non-target editor rather than returning.
  • F4 (low, doc): two claims overstate. (a) "so the highlight never appears where VS Code shows no comment" (Goal, line 163) does not hold for files VS Code does not tokenize at all (> 20 MiB or > 300 000 lines, confirmed in the 1.145.2 bundle, LARGE_FILE_SIZE_THRESHOLD=20*1024*1024, LARGE_FILE_LINE_COUNT_THRESHOLD=300*1e3). There, lucisv paints keywords in text drawn without comment colour, and the first paint walks every line above the viewport. (b) The extension README's "Only the lines on screen are scanned" leaves out that an edit above the viewport re-walks every line from the edit down to the viewport (numbers above). Arguably both are harmless behaviour, but the text should say it.
  • F5 (info): WORD_CHAR is ASCII, so a custom word starting or ending in a non-ASCII letter has no boundary there (ÄNDERN lights inside fooÄNDERN). This is consistent with the documented rule.
  • F6 (info): the escaped-identifier follow-up should also name \a/*b. The grammar (and the scan) open a block comment there that runs to the next */, possibly many lines, which is worse than the \a//b case filed.
  • F7 (info): in a string continued with backslash-newline, the continuation line is code to the grammar (the string ends at $), so a // TODO on it is painted. It matches what is drawn, by design.

Fixed by QA: editors/vscode/commentScan_test.js, the "no other top-level grammar rule can match …" test. The banned escapes now also include \H (Oniguruma non-hex, matches /), \O, \X, \R, \P, \p, \x/\u/\0 (code-point escapes that can spell / or ") and POSIX [[:. None occurs in the grammar today (14/14 still pass). A mutated grammar with `[a-zA-Z_\x2F]* now fails the test (checked in a scratch copy).

Not verifiable without a running VS Code: the decoration colour drawn over semantic and TextMate colours, bold rendering, the real ext-host lineAt cost on a multi-MB file, the language-change event sequence behind F3 (inferred from the API, not observed), and the dev's QA checklist items 1–6 (especially 5: watching comment brackets lose colour once tokenization completes).

Review

Lead, 2026-11-19. Accepted for 0.65.3.

  • Half of the owner's item is an explanation, not a change, and the changelog says so in those words. QA's F1 mattered: the dev's second cause was wrong and I had already repeated it to the owner; corrected with them and here. colorizedBracketPairs: [] is not adopted — it would take bracket colours out of code for everyone to fix a transient in comments.
  • Decorations for all words (one colour, one switch) is the boring choice and the right one. The scanner copies three grammar rules and a test pins that no other rule can match / or "; QA tightened that pin. The corpus agreement run (4 029 files, 0 lines) was reproduced by QA, not just quoted.
  • Fix round verified by re-running the suite: 37 tests, 37 pass. extension.js wiring read: the client exists before the closure can be called.
  • Owed to a human: that the decoration draws over the comment colour, and the Part 1 observation itself (work log checklist, item 5).
  • Follow-ups left open on purpose: the escaped-identifier grammar mismatch (\a//b , \a/*b), and the same language-mode gap in the begin/end rainbow in extension.js.