Split out of #16804, whose workspace.ts half landed. Still open: load highlighter grammars only for the file kind opened.
Why it was not done there: every caller scans synchronously (web/code.ts highlightPrefix, diff-syntax.ts hunkSyntax, tui/ui/editor.ts per-keystroke re-scan, the browser bundle), test/launch-no-tla.test.ts forbids require() and test/module-state.test.ts forbids a module-level cache.
Design that both tests accept: loadScanner(lang): Promise<Scanner|null> in src/web/highlight/ using import() of one module per family (markdown, yaml, toml/ini, html, css, diff, makefile, dockerfile, and one for generic+specs). The module system is the cache, so nothing is held at module level. scanOneLine and highlightLines then take the loaded Scanner instead of a language name, so scans stay synchronous. Migrate callers one at a time, async ones first (diffSyntax, the pull and talk pages), then highlightPrefix, the TUI viewer and editor (load on open), and last the browser bundle. test/highlight.test.ts passes await loadScanner(lang).
Split out of #16804, whose workspace.ts half landed. Still open: load highlighter grammars only for the file kind opened.
Why it was not done there: every caller scans synchronously (web/code.ts highlightPrefix, diff-syntax.ts hunkSyntax, tui/ui/editor.ts per-keystroke re-scan, the browser bundle), test/launch-no-tla.test.ts forbids require() and test/module-state.test.ts forbids a module-level cache.
Design that both tests accept:
loadScanner(lang): Promise<Scanner|null>in src/web/highlight/ usingimport()of one module per family (markdown, yaml, toml/ini, html, css, diff, makefile, dockerfile, and one for generic+specs). The module system is the cache, so nothing is held at module level.scanOneLineandhighlightLinesthen take the loadedScannerinstead of a language name, so scans stay synchronous. Migrate callers one at a time, async ones first (diffSyntax, the pull and talk pages), then highlightPrefix, the TUI viewer and editor (load on open), and last the browser bundle. test/highlight.test.ts passesawait loadScanner(lang).