Public: anyone can read this; the crew can change it.

Load highlighter grammars only for the file kind opened; split src/tui/screens/workspace.ts #17109

opened this

Merged 41h 4m ago, live in production

This pull does the workspace.ts split from #16804 and leaves the lazy grammar loading undone. That half is in #17107. The tests that cover the move pass and tsc is clean.

Notes

opened this

This pull does the workspace.ts split from #16804 and leaves the lazy grammar loading undone. That half is in #17107. The tests that cover the move pass and tsc is clean. I did not run the full bun test, because the fast-path picker named 642 files; the forge runs the full check on this push.

What moved: src/tui/screens/workspace.ts went from 4109 to about 2640 lines. The code moved verbatim into four modules, each named for one concept:

  • workspace_tables.ts has each isXPath and xTable pair for files that read as a table (CSV, subtitles, ICS, HAR, SARIF and so on).
  • workspace_tab.ts has the Tab class, buildLines, CacheEntry and the markdown and patch path tests.
  • workspace_tree.ts has the explorer's node model: nodeOf, flatten, findNode, landing.
  • workspace_draw.ts has the ref pill, tab bar, tree, code and table drawing, plus PROSE_MARK.

workspace.ts keeps the screen, the memory between visits and the doors other screens use. It re-exports buildLines, harTable and timelineTable because existing tests import them from there; I changed no test.

Not done: lazy grammar loading. Every caller scans synchronously (the page highlightPrefix, hunkSyntax, the TUI editor's 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. A loader added beside the synchronous API would load nothing less, and with no caller it would fail the "done means reachable" bar.

The design both tests accept is in #17107. loadScanner(lang) would dynamic-import() one module per grammar family, so the module system is the cache. scanOneLine and highlightLines would take the loaded scanner, which keeps scans synchronous. Callers migrate one at a time, with the async ones first. I did not run bun scripts/similar.ts, since I wrote no new functions.

To try it: open a repository's workspace in the terminal, then open a .csv, a .har and a .ts file. They should draw as before.

🤖 Generated with Claude Code

Closes #16804

commented

This pull does the workspace.ts split from #16804 and leaves the lazy grammar loading undone. That half is in #17107. The tests that cover the move pass and tsc is clean. I did not run the full bun test, because the fast-path picker named 642 files; the forge runs the full check on this push.

What moved: src/tui/screens/workspace.ts went from 4109 to about 2640 lines. The code moved verbatim into four modules, each named for one concept:

  • workspace_tables.ts has each isXPath and xTable pair for files that read as a table (CSV, subtitles, ICS, HAR, SARIF and so on).
  • workspace_tab.ts has the Tab class, buildLines, CacheEntry and the markdown and patch path tests.
  • workspace_tree.ts has the explorer's node model: nodeOf, flatten, findNode, landing.
  • workspace_draw.ts has the ref pill, tab bar, tree, code and table drawing, plus PROSE_MARK.

workspace.ts keeps the screen, the memory between visits and the doors other screens use. It re-exports buildLines, harTable and timelineTable because existing tests import them from there; I changed no test.

Not done: lazy grammar loading. Every caller scans synchronously (the page highlightPrefix, hunkSyntax, the TUI editor's 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. A loader added beside the synchronous API would load nothing less, and with no caller it would fail the "done means reachable" bar.

The design both tests accept is in #17107. loadScanner(lang) would dynamic-import() one module per grammar family, so the module system is the cache. scanOneLine and highlightLines would take the loaded scanner, which keeps scans synchronous. Callers migrate one at a time, with the async ones first. I did not run bun scripts/similar.ts, since I wrote no new functions.

To try it: open a repository's workspace in the terminal, then open a .csv, a .har and a .ts file. They should draw as before.

🤖 Generated with Claude Code

commented

This pull is the src/tui/screens/workspace.ts split alone. Lazy grammar loading is not in it, so it should be retitled to the split. I can't edit the title from here. The grammar half stays on its own issue (#17107), and I did not land it here. No behaviour changes.

What moved

  • Tables, tabs, the explorer tree and drawing each moved out of workspace.ts into their own modules:
    • workspace_tables.ts: the table views and the is*Path checks.
    • workspace_tab.ts: Tab, CacheEntry, isMarkdownPath and buildLines.
    • workspace_tree.ts: Node, nodeOf, flatten, findNode and landing.
    • workspace_draw.ts: drawRefPill, drawTabBar, drawTree, drawCode, drawTable and the table status helpers.
  • workspace.ts re-exports harTable, timelineTable and buildLines, so existing importers still resolve.

This round's fixes

  • I deleted the two orphaned doc comments (isTablePath and isMarkdownPath, which had moved out).
  • I restored the multi-line import blocks for commit, contribute, common and where. The unused-import removals stay.

Checks run

  • bun test on tui-workspace*.test.ts and workspace-*.test.ts: 99 pass, 0 fail. I did not run the whole suite; the forge's check runs it on push.
  • Those tests cover the moved workspace tab, tables and drawing code.
  • The re-exports are exercised by render-har.test.ts (harTable), render-timelines.test.ts (timelineTable) and render-ansi.test.ts and blob-private-key.test.ts (buildLines). I did not run these four files, so that the re-exports still resolve is not confirmed by a run.
  • bun scripts/gate.ts --explain: 32 rules read, 0 fail. --fix changed nothing.
  • bun x tsc --noEmit: clean.

How to try it Open the terminal workspace, open a .csv, a .har and a README, and confirm they look as before.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs