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]>
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 whenTokenMetadata.getTokenType(tokenMetadata) === StandardTokenType.Otherand the token's balanced-bracket bit is set; the metadata comes fromtextModel.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 buildsinitialAstWithoutTokenswithFastTokenizer; when background tokenization is still in progress it builds it from the buffer's current tokens (untokenized lines are oneOthertoken each). Every colourising query readsthis.initialAstWithoutTokens || this.astWithTokens, token-only changes never updateinitialAstWithoutTokens(handleEdits(…, tokenChange)skips it), and it is cleared only inhandleDidChangeBackgroundTokenizationStateonce the state isBackgroundTokenizationState.Completed.TextMateTokenizationSupport.tokenizeEncoded(read from VS Code 1.145.2's shippedworkbench.desktop.main.jsand its tokenization worker):line.length >= maxTokenizationLineLength ? nullTokenizeEncoded(languageId, state) : …— a line at leasteditor.maxTokenizationLineLength(default 20 000) characters long is oneOthertoken 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, no1024, 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 matchingSEMANTIC_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/unbalancedBracketScopeson the grammar contribution: no help — they only set the balanced-bracket bit on TextMate tokens, and the token-blind tree reads no tokens.colorizedBracketPairs: []inlanguage-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.enabledviaconfigurationDefaults: 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-textmate9.3.2 andvscode-oniguruma1.7.0 that VS Code 1.145.2 ships (extracted from itsnode_modules.asarinto a scratch directory; not a dependency of anything here), compared per character against the server's owncommentsemantic tokens, on 309 OpenTitan files (every 13th ofhw/, 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`definebody 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-commentsemantic tokens start inside a comment, by the lexer's spans or by the grammar's. Repeated through the large-file window path (semanticTokens/rangeon one 12 MB, 357 172-line concatenation of 1 500 OpenTitan files, sosemantic_tokens_in_windowanswers): again 0. The server only ever emits tokens from lexer tokens, whose comments are trivia, and frominstantiation::overrides, keyed by syntax-tree token starts. Nothing to fix incrates/lucisv_server/src/tokens*, so no Rust changed. - lucisv's own rainbow. It paints only
begin/end/fork/joinranges frompairs.rs, computed overDocument.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 acontributes.colorsdefault 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/semanticTokenScopesrather 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 forverilog/systemverilog. With another grammar active, the scan may disagree with what is drawn. - VS Code draws a decoration's
colorover 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. SoTODOskipsTODO_reg,myTODO,$TODO,TODO1, andREVIEW:matches inREVIEW: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ÄNDERNlights insidefooÄ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// TODOon 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 incustom. 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
escapeRegExpbefore 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 ofaand 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. Thepackage.jsonschema says the same (minLength,maxLength,pattern: ^\S+$,maxItems,uniqueItems), so the settings editor warns before the extension has to. - Case: case-sensitive by default (
todoin 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'scommentsandstringsrules and the shape of every other top-level rule. Promise to whoever edits the grammar:commentScan_test.jsfails 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"; updatecommentScan.jsin 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) andeditor.largeFileOptimizations(read, never written). - Provides the settings
lucisv.commentKeywords.builtIn,lucisv.commentKeywords.custom,lucisv.commentKeywords.caseSensitiveand the colourlucisv.commentKeyword. The server receives them inworkspace/didChangeConfigurationwith the rest oflucisvand ignores them (it only reads named keys; checked insettings.rs). - extension.js: one
requireand one construction inactivate, after the rainbow's decoration types; the module pushes its decoration type and every listener (includingonDidOpenTextDocument, for language-mode changes) intocontext.subscriptions. It needs nothing from the server. - Packaging:
commentKeywords.jsandcommentScan.jsare runtime modules (listed intools/RELEASING.md's runtime-module sentence and the.vscodeignoreheader); their two*_test.jsfiles 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,maxTokenizationLineLengthhonoured.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-textmateover all of OpenTitanhw(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//bis drawn as a comment from//on, and — worse —\a/*bopens a block comment that runs to the next*/, possibly many lines down (QA F6). A\\\S+rule ahead of#commentswould fix both — but it changes the scan's mirrored rules too, so it goes with acommentScan.jschange. - 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 paintsbegin/end/fork/join; the server's semantic tokens never include punctuation except the instantiation#overrides. - Verified VS Code's bracket colourisation against
microsoft/vscodemain(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 realvscode-textmatevs the server's semantic tokens, over LSP stdio) andagree.js(commentScan.jsvs the real tokenizer). Numbers in Goal. Every run went throughtools/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):
- A
.svfile with// TODO: x,/* FIXME */,// FIX_ME TBD, a three-line/* … TODO … */,"// TODO"in a string,TODO_regin code: the four in comments are bold orange (Dark Modern and Light Modern), the string and the identifier are not. - Add
"lucisv.commentKeywords.custom": ["XXX", "a.b"]in settings.json:XXXlights at once,a.blights butaxbdoes not — no reload."builtIn": falseremoves the four at once;"caseSensitive": falselightstodo. - Type
/*at the top of a file: every TODO below lights up after a beat; delete it: they go back. - Open a multi-MB OpenTitan-sized file and scroll to the end: the keywords appear as you scroll, typing stays smooth.
- Part 1, the cause: open a large
.sv(a few MB) withx[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. workbench.colorCustomizations: { "lucisv.commentKeyword": "#FF0000" }recolours them.
- A
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.jsreadseditor.maxTokenizationLineLengthwith 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.svdocument and not to averilogone, and dropping it recomputes. - F3: verified in
src/vscode-dts/vscode.d.ts(main, 2026-11-19):onDidOpenTextDocument/onDidCloseTextDocumentfire "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 inextension.jshas 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.largeFileOptimizationson and > 20 MiB of text —offsetAtof the end, UTF-16 units, asgetValueLengthcounts — or300 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.jshas 14 tests andcommentKeywords_test.js8, as claimed.node --checkis clean oncommentScan.js,commentKeywords.js,extension.jsand both tests.package.jsonparses,versionis0.65.2.- Scope:
git status --untracked-files=alllists onlyeditors/vscode/*,tools/RELEASING.mdanddocs/features/comment-highlighting/. npx --no-install @vscode/vsce ls --no-dependencies: shipscommentKeywords.jsandcommentScan.js; nothing matching_testorsmokeships.- Reproduced the dev's full-corpus number myself:
tools/guard.sh -m 4 -t 600 -- node agree.js … all.txtprinted{"docs":4029,"lines":1185823,"chars":39294203,"commentChars":8391566,"mismatchedLines":0}. On the scripts:agree.jsis a sound per-character comparison ofscanLinechained across lines against the realvscode-textmate, so it does prove agreement with the grammar on OpenTitan. It does not exerciseLineStates, edits ormaxLineLength; myprop_edit.jscovers 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:getMetadatasets only font/foreground bits). Its usage line says--windowbut the code reads--range. That is cosmetic. - QA scripts (scratchpad
qa71/, not shipped):scan_attack.js(82 crafted lines vsvscode-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-208treats a bracket as a bracket only ifgetTokenType === StandardTokenType.OtherandcontainsBalancedBrackets(metadata).FastTokenizer(:282) reads no tokens.bracketPairsTree.ts:65-79builds the token-blindinitialAstWithoutTokenswhen the model has no tokens yet, or from the current tokens while background tokenization is in progress.:84-93clears it only onBackgroundTokenizationState.Completed. Token changes never update it (:121). Lines that are not tokenized yet getgetDefaultMetadata(tokens/contiguousTokensStore.ts:247-256), which does setBALANCED_BRACKETS_MASK, so they produce brackets. Case 1 is right. - F1 (medium, documentation): case 2 is wrong. A line of
maxTokenizationLineLengthor more is tokenized bynullTokenizeEncoded(tokenizationSupportWithLineLimit.ts:40-41; the worker uses the same wrapper,textMateWorkerTokenizer.ts:108).nullTokenizeEncoded(languages/nullTokenize.ts:22-31) sets noBALANCED_BRACKETS_MASK. The 1.145.2 bundle agrees: the long-line token is(s<<0|0|0|32768|2<<24)>>>0with no1024bit, 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 incommentKeywords.jsstill 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: []inlanguage-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 howFastTokenizerderives its pairs fromcolorizedBracketPairs. 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*/\TODOand😀TODO😀match.TODOsTODO_xxTODO$TODOTODO$TODO1FIX_ME_LATERandtodo(case-sensitive) do not.TODOin a string or in code is not painted. - Overlaps: the longest word wins at the same start (
FIX_MEoverFIX,TBDoverTB,!!!over!!).FIXalone never lights insideFIX_ME. Matches never overlap (a.b/b.cona.b.cgivesa.b). - Metacharacters are literal:
a.b(notaxb),(x,[,\,^$,.*(nothello),|,?,+,{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 incustomare dropped. 60 words give 50 used and 10 skipped. A non-arraycustomgives the built-ins only (silently, with no log line: fine).caseSensitive:falsematchestodo/Todoand 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:falsewith an emptycustomclears 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, withmaxTokenizationLineLengthforced 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
lineAtcost 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
#FF9E3Dscores 8.01 on#1F1F1F, 8.11 on#1E1E1E, 7.45 on#252526and 7.30 on#002B36(Solarized Dark). Light#A85000scores 5.51 on white, 4.96 on#F3F3F3and 5.11 on#FDF6E3. HC#FFA500on black: 10.63. HC-light#9C4A00on white: 6.19. All are ≥ 4.5.lucisv.commentKeywordis spelled identically inpackage.json:491,commentKeywords.js:15and the README.
Findings
- F1 (medium, doc): see Part 1 above.
- F2 (low):
commentKeywords.js:75readsgetConfiguration('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 (paintEditorreturns before clearing). Switching a.txtto SystemVerilog paints nothing until the next scroll or edit. Reproduced with the fake inkw_attack.js. The rainbow (extension.jsrepaintVisible) 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_CHARis ASCII, so a custom word starting or ending in a non-ASCII letter has no boundary there (ÄNDERNlights insidefooÄ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//bcase filed. - F7 (info): in a string continued with backslash-newline, the
continuation line is code to the grammar (the string ends at
$), so a// TODOon 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.jswiring 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 thebegin/endrainbow inextension.js.