Skip to content

Editor: Nim and Typst on the shared TextMate layer, so a long line can't freeze the window - #26987

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/textmate-one-runtime
Oct 11, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/textmate-one-runtime

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​101 $\color{#cf222e}{\Huge{\mathbf{−}}}$​84 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​175 $\color{#cf222e}{\Huge{\mathbf{−}}}$​134 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​41

ELI5

Opening a Nim or Typst file with one very long line (for example a generated file that embeds a big hex string) could freeze the whole Orca window for seconds, or for minutes on bigger files. Now such a line simply isn't coloured, and the window stays responsive. Normal Nim and Typst files look exactly as before.

What Changed

The problem. The code editor colours Nim and Typst with a separate TextMate engine (Microsoft's vscode-textmate). It tokenized every line with no time limit and no length cap. The editor's own line-length cap only applies to its built-in grammars, not to custom tokenizers like this one. Some long lines take time that grows with the square of their length, and one regex scan over such a line can't be interrupted.
Measured on main with the shipped grammars: a 46 KB one-line Nim file holding a hex string in """…""" took 12.6 s to tokenize in Node. In the running app it froze the renderer for 8.1 s (one blocked task). A 50 KB line of dense Typst code took 36 s, and an 80 KB unbroken identifier in Nim took 49 s.
Orca also shipped two TextMate engines: that one for the editor, and Shiki's fork for native chat (#26343).

What you see now.

  • Opening the same 46 KB Nim file: the editor shows at once, with no stalled task longer than 94 ms. That line, and any lines after it, are shown as plain text instead of coloured.
  • Nim and Typst files with normal lines look exactly as before. The before/after screenshots below are byte-identical.
  • Native chat code block labels now name the language for the common tags agents write: ```ts shows "TypeScript", ```vue shows "Vue", ```powershell shows "PowerShell". Before, these showed the raw tag ("ts", "vue", "powershell") while ```python already showed "Python". Tags the catalogue doesn't know still show as written.

How it works.

  • This follows feat(native-chat): highlight code blocks and shell commands #26343. The editor's Nim/Typst token provider now runs on the same shared TextMate layer as chat (src/renderer/src/lib/syntax-highlighting/): Shiki core on Orca's one Oniguruma WASM. A new textmate-core.ts owns the regex-engine adapter and the per-line limits, and chat and the editor both call it.
  • Per-line limits, the same as chat: a line over 1,000 characters is skipped without being scanned. A line that hits the 50 ms TextMate time limit is retried twice, because the first lines through a grammar also compile its regexes, and then skipped.
  • A skipped line's end state is unknown, so the editor doesn't guess. That line and every line after it are plain. All "skipped" states are equal to each other, so the editor stops re-tokenizing that plain tail. Editing the long line re-tokenizes from the good state before it, so colouring comes back once the line is short enough.
  • Monaco's lazy registerTokensProviderFactory adapter is kept. State equality stays structural (rule-stack equals), so after an edit the editor stops re-tokenizing as soon as states converge. There's a test for that.
  • The editor keeps its own grammar registry on the shared engine. It needs one because chat's registry holds the catalogue's Nim and Typst under the same scope names.
  • Nim and Typst keep Orca's vendored grammars. The catalogue's Nim is an older 2020 fork, and its Typst is a different grammar that embeds about 40 languages and would change colours. Orca's Typst also carries tested fixes for comments and math.
  • Colours are unchanged in this PR. The editor keeps vs/vs-dark, mapped by each token's last scope as before. Adding Dark+/Light+ TextMate rules to the editor themes is a later step.
  • vscode-textmate is removed from package.json and the lockfile. vscode-oniguruma stays as the shared engine.
  • Chat labels: the code block label uses the code-block picker's translated label when it has one. Otherwise it uses the name the highlighting catalogue gives the tag or its alias. Otherwise it shows the tag as written.

Why

  • One engine, one set of limits. One TextMate implementation instead of two, and the freeze guard chat already had now protects the editor too. This is the next step of the plan posted on feat(native-chat): highlight code blocks and shell commands #26343.
  • Length cap, not just a time limit. Measured: with a 50 ms limit, a 20 K-character Typst line still took 2.2 s, because one regex scan over a long line can't be interrupted. Only a length cap bounds that. 1,000 characters keeps the worst case measured around 20 ms per line.
  • Trade-off, intended: a Typst paragraph written as one line longer than 1,000 characters now leaves the rest of that file plain. On main it was coloured, at the cost of tens of milliseconds per keystroke on that line and a possible freeze. The cap is one constant if we want to raise it for the editor (2,000 characters measured about 80 ms for dense Typst code).
  • Plain rest-of-file rather than continuing. Continuing from the state before a skipped line could colour the rest of the file wrongly, for example everything as a string. Plain is honest, and editing recovers it.
  • Not @shikijs/monaco. It monkey-patches Monaco globally, loads every grammar up front, and compares states by identity, so every edit re-tokenizes to the end of the file.

Linked Issue

Follows #26343 (no separate issue).

Visual Proof

Hidden dev app on macOS (dark theme, vs-dark editor), fresh isolated profiles, before = main 2cb2bef67e3, after = this branch. Steps were driven by a separate non-Claude QA agent over the DevTools protocol. Chat used a local stand-in agent, not a real agent.

Before (main) After
sample.nim in the editor (byte-identical) before nim after nim
sample.typ in the editor (byte-identical) before typst after typst
One-line 46 KB generated_logo.nim Renderer blocked 8,136 ms (longest task); the long line coloured as a string. before minified Longest task 94 ms; editor showed in 334 ms; the line is plain. after minified
Chat ```vue block label before vue after vue

All chat labels in the same reply, before → after: ts → TypeScript, python → Python (same), bash → Bash (same), vue → Vue, powershell → PowerShell, zzlang → zzlang (unknown, same).

Testing

  • I manually tested these changes locally (macOS hidden dev app, before/after as above)
  • Automated tests added/updated
  • New: the editor provider leaves a minified Nim line and a minified Typst line plain, without freezing (under 1 s; untimed, these lines take tens of seconds). Lines after it stay plain with an equal state, and shortening the line re-colours. States converge after an edit. The shared per-line limits retry, give up, and skip. The chat label names ts, py, yml, vue, tsx and ps1 tags.
  • Existing Nim/Typst tokenization tests (raw blocks, math, nested comments) and the chat highlighter tests pass on the shared layer.
  • Locally: web typecheck, the monaco-languages, syntax-highlighting, native-chat and editor component suites, and orca-ci-checks (22/22) pass.
  • Platforms: macOS only. Renderer-only change, with no main-process, IPC or remote code, so SSH and WSL workspaces behave the same: the editor colours whatever text it was given. Windows and Linux use the same renderer code and WASM, but I didn't run them.

Review

  • Not verified: a packaged build (the WASM path is unchanged from main, where it already ships for Nim/Typst), and Windows/Linux.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: no new inputs or channels. Performance: worst case per editor line is now bounded; normal files unchanged. Backwards compatibility: no persisted data or settings touched.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…-line limits

The editor's Nim and Typst highlighting moves from vscode-textmate onto the
Shiki core + Oniguruma layer chat uses, with the same per-line length cap and
time limit. A skipped line leaves the rest of the file plain instead of
freezing the window. Chat code block labels now name catalogue languages
(vue -> Vue, ts -> TypeScript).
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 090b4a66-0649-408f-8f08-d7e4a6e9c314

📥 Commits

Reviewing files that changed from the base of the PR and between 62878c3 and 84a7d62.


⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

📒 Files selected for processing (16)
  • package.json
  • src/renderer/src/components/native-chat/NativeChatCodeBlock.tsx
  • src/renderer/src/components/native-chat/NativeChatMessageRow.test.tsx
  • src/renderer/src/components/native-chat/code-fence-language-label.test.ts
  • src/renderer/src/components/native-chat/code-fence-language-label.ts
  • src/renderer/src/lib/monaco-languages/register-nim.test.ts
  • src/renderer/src/lib/monaco-languages/register-nim.ts
  • src/renderer/src/lib/monaco-languages/register-typst.test.ts
  • src/renderer/src/lib/monaco-languages/register-typst.ts
  • src/renderer/src/lib/monaco-languages/textmate-language-registration.test.ts
  • src/renderer/src/lib/monaco-languages/textmate-language-registration.ts
  • src/renderer/src/lib/monaco-languages/textmate-token-provider.test.ts
  • src/renderer/src/lib/monaco-languages/textmate-token-provider.ts
  • src/renderer/src/lib/syntax-highlighting/syntax-highlighter.ts
  • src/renderer/src/lib/syntax-highlighting/textmate-core.test.ts
  • src/renderer/src/lib/syntax-highlighting/textmate-core.ts

💤 Files with no reviewable changes (1)
  • package.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.



📝 Walkthrough

Walkthrough

Native chat code blocks now display language labels resolved from bundled language metadata, while preserving unrecognized tags. The syntax highlighter and Monaco language providers now use a shared TextMate core and bounded line-tokenization helper. Nim and Typst grammar loaders return language registrations without scope arguments. Provider tests cover long-line fallback and tokenization state.

Priority: ⬆️ High

Estimated code review effort:


Merge Risk: ⚪ Minimal · up to 84a7d

The shared-core grammar concern does not block merging, and no other actionable issue remains from this review.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 41.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 15 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the primary change: moving Nim and Typst editor highlighting to the shared TextMate layer to prevent freezes from long lines.
Description check Passed The description includes all required sections and provides clear user impact, implementation details, rationale, issue reference, visual proof, testing results, limitations, and checklist status. It …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR


🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025
brennanb2025 merged commit 8cc779e into main Oct 11, 2026
66 of 76 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/textmate-one-runtime branch October 12, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant