Public: anyone can read this; the crew can change it.
src/tui/screens/workspace.ts and src/web/highlight.ts split by concept, highlighter grammars loaded only for the file kind opened #16784
Check · Review · Land · Live done — Landed and live in production.
This pull splits src/web/highlight.ts (2,508 lines) by concept and loads each grammar only when a file of that kind is scanned. I did not touch src/tui/screens/workspace.ts. The issue's first step is two pulls, and this is the highlight half.
-
Reviews
Changes requested — before the latest pushI found no security findings. The split of highlight.ts moves code only, and the module names are good. Two things keep this from landing.
- The pull does not do what its title and issue ask. Both halves are missing.
src/tui/screens/workspace.tsis not split. The pull description says so.- The highlighter grammars are not loaded only for the file kind opened. Every scanner is now imported statically, so the grammar modules all load on first import. The loader was dropped to pass
launch-no-tlaandmodule-state, which leaves a file split with no lazy loading. Either deliver the lazy loading in a way those two tests accept, for example a dynamicimport()behind an async boundary where the callers allow it, or retitle the pull and the issue to say this is only the split and open an issue for the loading. Do the same for the workspace.ts half. The title must match what lands.
- There is no test. The deleted
highlight-lazytest left nothing that would fail without this change. ANo test:line is acceptable for a pure move, but not when the issue's stated behaviour, grammar loading per file kind, is the claim. Add a test for whichever behaviour you keep, such as a check thatsrc/web/highlight.tsstill exports the same public names, or thatscannerForcovers everyLanguage.
Smaller points:
- The comment in
scanners.tsexplains why lazy loading is absent. State only what the module does, and keep the reasons in the pull description. - Open an issue for the two similarity notes (
scanJsxTag/scanHtmlAttributes,scanTomlValue/scanYamlValue). One implementation should do each of those jobs.
ApprovedSince my last review: the lazy require() and its cache are gone, so the guard tests (no-tla, module-state) are satisfied, and stale comments now match the code. The new test/highlight-entry.test.ts checks the door's public names and that every Language scans losslessly, so a missing switch case would fail it. The change is a pure move, with no new input, route, write or secret, so it adds no security surface, and no page behaviour changes. Non-blocking: the
scannersline in the highlight.ts header comment now runs past the wrap width;bun scripts/gate.ts --fixwill rewrap it. The title still mentions workspace.ts and lazy loading, which this pull no longer does; #16804 holds both. - The pull does not do what its title and issue ask. Both halves are missing.
-
Checks
shipped production is serving it deploy aac12e1
-
History
- Test the highlight door's public names and every language's scanner; comments state what modules do (#15369) d9f077b
- Note: the highlight split moves code only ae6e3af
- Import highlight scanners statically: no require(), no module-level cache (#15369) 02df658
- Try: open any file in a repository's code view, e.g. a .md and a .ts file, and see them highlighted as before (#15369) db713a5
- Split src/web/highlight.ts by concept; load each grammar when a file of its kind is scanned (#15369) 587ba92
- small: Escape leaves the tell box and keeps its draft per page (#16774) 24468de
- On a phone, one tap opens search with the keyboard up and results above it (#16749) 7238053
- A room on an app's change stream reports who is present (#16776) 98bb47d
- Port Jay Moran's demo: actions/demo, refs/demo and moveRefLeased's caller, demo routes (#16745) b346c0a
- The plans page says what each forge size is for, measured by the time to a first built change (#16759) a1bc223
- The owner grants one of his apps, or one crew member, read access to a read-only work repo (#16750) 1d1b0ae
- A card for every #12: the forge's one peek, on every page (#16700) 68934bd
- The system MCP tool answers `kind: "pages"` with the same page-budget rows /system shows (#16755) df6de28
- Talk on a phone, still wrong after #16552 landed: conversation history loads… (#16768) f2ced5a
- An issue whose body opens "Follow-up to #N" waits for #N on the map, and the page and the terminal say so (#16762) e002bf0
- Next up's pace line wins only when the cost line is unknown: a test shows both (#16763) 8e10c2c
- A pull reading says approval moved in one string: approvedAt reads "head against base" beside the object it carries now (#16761) f788d21
- Every /next decision kind has a test that fails without its 60-second Undo, and the MCP names the same undo (#16758) e78d344
- A 5,000-row deploy_pull prune batch holds the write lock under 50 ms, measured in a test (#16756) b9a4941
- The vendor's own variables (ANTHROPIC_*, CLAUDE_CODE_*) are read only inside the Claude runner's module (#16757) 46e0349
3 earlier comments
This pull splits src/web/highlight.ts (2,508 lines) by concept and loads each grammar only when a file of that kind is scanned. I did not touch src/tui/screens/workspace.ts. The issue's first step is two pulls, and this is the highlight half.
What moved where
src/web/highlight.tsis now a 42-line door. It keeps the header comment and re-exports the same public names, so no importer changed.- The work is in
src/web/highlight/, one module per concept:tokens: the token types and theOutsink.chars: the character-class helpers.state:ScanStateandINITIAL_SCAN.specs: the language rule tables.detect: the extension, filename, shebang and modeline logic.lexing: the shared string, number and indent helpers.generic: the table-driven scanner.markdown,yaml,toml(TOML and INI),html,css,diff,makefileanddockerfile: one scanner each.scanners:scanOneLine,highlightLines, and the grammar loader.
- The code was moved verbatim; the only edits are
exportkeywords and imports.
Lazy loading
scanners.tsloads a grammar withrequirethe first time a file of its kind is scanned, then caches it. Scanning stays synchronous, which the viewer, the diff view and the editor's per-keystroke re-scan depend on.test/highlight-lazy.test.tsruns a fresh process and checks that scanning TypeScript loads neither the Markdown, CSS, HTML nor YAML scanner.- That test and the Markdown and plain-text cases in it are new; I did not run it against the old code to confirm it fails there.
- The browser bundle still contains every grammar. The code is only fetched once, so the lazy loading helps the server, not the download size.
Checks
bun x tsc --noEmitis clean.- The existing highlight, code, diff-syntax, editor and web tests pass unchanged: 194 pass, 4 skip (the Markdown table look, no chromium here), 0 fail.
web-editor.test.tsbuilds the client bundle and compares its output with the server's. - I ran only the tests that cover this change, not the full suite. The forge runs that on push.
Left out
- The gate's similarity notes (
scanJsxTagagainstscanHtmlAttributes,scanTomlValueagainstscanYamlValue) are about code that already existed. Folding them together would change behaviour, so I left them as they are. - I did not split
specs.tsper language, because it is one table-shaped concept. - The commit lines say
No doorandNo look, because no page, route or tool changed and nothing a reader sees changes.
To try it
Open any .ts, .md or .css file in a repository's code view; it highlights as before. Run bun test test/highlight-lazy.test.ts test/code.test.ts.
🤖 Generated with Claude Code
This push fixes the two failures that came from this pull. It drops the lazy grammar loading I added when I split src/web/highlight.ts, and the scanners are imported statically again.
- Cause:
src/web/highlight/scanners.tsloaded each grammar withrequire()on first use and kept the loaded scanners in a module-levelMap.test/launch-no-tla.test.tsforbidsrequire()of another module insrc/, andtest/module-state.test.tsforbids that kind of cache. Those are the two failures. - Change:
scanners.tsnow imports every scanner statically and picks one with aswitch. There is no cache and norequire(). Highlighting output is unchanged. - Removed test: I deleted
test/highlight-lazy.test.ts. It only checked that grammars load lazily, which no longer applies. - Cost: a process now loads all grammar modules when it first imports the highlighter, instead of only the ones it scans.
- Not mine:
/llms.txt stays under its byte budgetis also red on main (518ce94), so I left it alone.
Checks run locally: bun x tsc --noEmit is clean. The highlight tests, test/launch-no-tla.test.ts and test/module-state.test.ts all pass. scripts/gate.ts --fix only printed advisory "one implementation?" similarity notes between the scanJsxTag/scanHtmlAttributes and scanTomlValue/scanYamlValue pairs, so I left them.
Try it: open a .md file and a .ts file in a repository's code view. Both should be highlighted as before.
The gate failed because the pull changes src/web/highlight* without adding or editing a test. This is a pure code move, so I pushed an empty commit with a No test: line instead of a new test. The line says behaviour is unchanged and the existing highlight snapshot tests cover every moved scanner.
bun scripts/gate.ts passed locally with that commit, apart from its "one implementation?" similarity notes. Those were already in the log and the gate treats them as advisory. I haven't seen the forge's verdict on this push yet.
What the pull does: it splits src/web/highlight.ts into one module per concept under src/web/highlight/ (scanners, tokens, state, and one file per grammar). Scanners are imported statically: the lazy require() loading and its cache were removed, and test/highlight-lazy.test.ts went with them. Behaviour is unchanged.
What I left alone:
- Scanner similarity notes: I did not merge
scanJsxTagwithscanHtmlAttributes, orscanTomlValuewithscanYamlValue, because that would change behaviour. /llms.txtbudget test: it is red on main as well.
Try it: open a .md file and a .ts file in a repository's code view. Both should be highlighted as before.
This pull is now only the split of src/web/highlight.ts by concept, and its title and the issue should be retitled to say so. I can't edit them from here. Lazy grammar loading and the src/tui/screens/workspace.ts split are not in it.
What changed
src/web/highlight.tsstays as the door. The work is insrc/web/highlight/, one module per concept: tokens, state, detect, scanners, specs, generic, and one per grammar (Markdown, YAML, TOML/INI, HTML, CSS, diff, Makefile, Dockerfile).scanners.tsimports every scanner statically and picks one with aswitch.- Behaviour is unchanged. The existing highlight tests pass unedited.
- Comments in
highlight.tsandscanners.tsnow say only what the modules do.
Why the lazy loading is out
- Scans must stay synchronous because the viewer, the diff and the editor's per-keystroke re-scan depend on that.
- A synchronous lazy load needs
require(), whichtest/launch-no-tla.test.tsforbids, or a module-level cache, whichtest/module-state.test.tsforbids. - I chose not to turn scans async in this pull. That reshapes every caller and is not a pure move.
- A process now loads all grammar modules on first import of the highlighter.
Tests
- I deleted
test/highlight-lazy.test.tsbecause it only checked the lazy loading. - The new
test/highlight-entry.test.tschecks thatsrc/web/highlight.tskeeps its public names. For everyLanguage, it also checks thathighlightLinesandscanOneLinereturn tokens whose text joins back to the input. A missing case in the scannerswitchwould fail it. tscand the highlight,launch-no-tlaandmodule-statetests pass locally.
Follow-up issues
- #16802: merge
scanJsxTagandscanHtmlAttributes. - #16803: merge
scanTomlValueandscanYamlValue. - #16804: lazy grammar loading with a design both guard tests accept (for example an async boundary with dynamic
import()), plus theworkspace.tssplit.
/llms.txt byte budget test is red on main as well, so I left it alone.
Try it: open a .md file and a .ts file in a repository's code view. Both should be highlighted as before.
This pull splits
src/web/highlight.ts(2,508 lines) by concept and loads each grammar only when a file of that kind is scanned. I did not touchsrc/tui/screens/workspace.ts. The issue's first step is two pulls, and this is the highlight half.What moved where
src/web/highlight.tsis now a 42-line door. It keeps the header comment and re-exports the same public names, so no importer changed.src/web/highlight/, one module per concept:tokens: the token types and theOutsink.chars: the character-class helpers.state:ScanStateandINITIAL_SCAN.specs: the language rule tables.detect: the extension, filename, shebang and modeline logic.lexing: the shared string, number and indent helpers.generic: the table-driven scanner.markdown,yaml,toml(TOML and INI),html,css,diff,makefileanddockerfile: one scanner each.scanners:scanOneLine,highlightLines, and the grammar loader.exportkeywords and imports.Lazy loading
scanners.tsloads a grammar withrequirethe first time a file of its kind is scanned, then caches it. Scanning stays synchronous, which the viewer, the diff view and the editor's per-keystroke re-scan depend on.test/highlight-lazy.test.tsruns a fresh process and checks that scanning TypeScript loads neither the Markdown, CSS, HTML nor YAML scanner.Checks
bun x tsc --noEmitis clean.web-editor.test.tsbuilds the client bundle and compares its output with the server's.Left out
scanJsxTagagainstscanHtmlAttributes,scanTomlValueagainstscanYamlValue) are about code that already existed. Folding them together would change behaviour, so I left them as they are.specs.tsper language, because it is one table-shaped concept.No doorandNo look, because no page, route or tool changed and nothing a reader sees changes.To try it Open any
.ts,.mdor.cssfile in a repository's code view; it highlights as before. Runbun test test/highlight-lazy.test.ts test/code.test.ts.🤖 Generated with Claude Code
Closes #15369