Skip to content

feat(plugins): syntax packs highlight unknown files in a worker, live - #30759

Closed
nwparker wants to merge 8 commits into
nwparker/plugins-v2-6-settings-uxfrom
nwparker/plugins-v2-7-syntax-packs
Closed

nwparker wants to merge 8 commits into
nwparker/plugins-v2-6-settings-uxfrom
nwparker/plugins-v2-7-syntax-packs

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​913 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​911
Prod 40 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2123 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2105

ELI5

Plugins can now teach Orca's editor to color a new language. If Orca shows a file as plain text and an installed plugin knows its file type, the editor highlights it right away, with no reload. A broken or very slow grammar can't freeze Orca; the file just stays plain.

What Changed

Before: only Orca's built-in languages were highlighted. Any other file type was plain text.

After:

  • A plugin can contribute syntaxes: a TextMate grammar, optional comment and bracket settings, and the file extensions and file names it claims.
  • Files that Orca would show as plain text use a matching plugin syntax in the editor and in diffs. Built-in languages always win.
  • Highlighting follows the plugin live. Enabling, updating or disabling it re-highlights open files without a reload, and edits are re-highlighted as you type.
  • When a grammar is too slow, crashes, or a file is too big, that file stays plain. A pathological grammar never blocks the window.

How it works:

  • Manifest (plugin-content-pack-contributions.ts, plugin-manifest.ts): contributes.syntaxes, at most 16 per plugin. Each entry is { id, label, scopeName, path, configuration?, extensions, filenames }. Ids and scope names must be unique.
  • Validation (src/shared/plugins/plugin-syntax-artifact.ts, src/main/plugins/plugin-syntax-registry.ts):
    • When a plugin is approved, main parses every grammar: allowed rule keys only, scope must match, at most 1 MiB, bounded nesting and node count.
    • Includes are checked once, in linear time. A #key or sibling scope#key inside the plugin must resolve, or the plugin card shows the error. An include of an outside scope, such as an embedded source.js, is allowed and resolves to nothing, so that region stays plain.
    • plugins:loadSyntax returns a language's grammars only when a matching file opens.
  • Worker (plugin-grammar.worker.ts, plugin-grammar-tokenization.ts, plugin-grammar-worker-client.ts):
    • The grammar compiles once per worker on Orca's Oniguruma build, and the worker stays warm between edits. It stops after 60 s idle.
    • Setup (loading the engine, compiling the grammar) has its own 20 s deadline and ends with a "ready" message, so a slow cold start is never mistaken for a stalled document.
    • Lines get core's limits (1,000 characters, 50 ms); from a line that exceeds them, the rest stays plain.
    • A superseded pass is cancelled at the next 100 ms slice and dropped by job id.
    • If progress stops for 2 s, the pass runs over 30 s, or the worker crashes, it is terminated. The language then stays plain, no further passes are scheduled, and the plugin card says highlighting stopped.
    • Results are validated against the text that was sent.
  • Monaco (plugin-syntax-engine.ts, plugin-syntax-token-legend.ts, plugin-syntax-editor-options.ts):
    • Tokens are applied as Monaco semantic tokens. Monaco asks only for models shown in an editor, keeps one request per model (newest text wins), and keeps painting the previous colors, shifted by edits, until the new pass lands.
    • Colors come from the token names Monaco's built-in light and dark themes style (type, number, string, comment, keyword, keyword.flow, delimiter, tag, and so on). Each token takes the innermost scope that maps to one, skipping punctuation, so a comment's // and a string's quotes share its color. Function and variable names stay plain, as in Orca's own languages.
    • Size is checked with getValueLength()/getLineCount() before any text is read.
    • Semantic highlighting is turned on as an editor option, because standalone themes leave it off.
  • Slots (plugin-syntax-slot-pool.ts, plugin-syntax-runtime.ts):
    • Monaco can't unregister a language, so plugin languages borrow from up to 512 fixed language ids. A slot is keyed by syntax id and revision and counted by the editors that use it.
    • When no editor uses a language, its models move back to plain text, so a reused slot never paints them with another grammar.
    • Up to 16 idle slots stay bound for a quick reopen, and least recently used idle slots are reused first.
  • Editor (use-plugin-syntax-language.ts, plugin-syntax-editor-options.ts): MonacoEditor, DiffViewer and DiffSectionBody resolve their language through this one hook. After mounting, they put kept models back on that language, because the editor library reuses a kept model without resetting it.
  • Example (examples/plugins/orca-gleam-syntax): an official-style data pack with the upstream Gleam grammar (Apache-2.0, provenance and license alongside).
  • Preview: the marketplace preview now lists app themes, terminal themes, icon themes and syntaxes. Before, those packs read "Manifest metadata only".
  • Catalog: releases can declare syntax. Docs are in docs/reference/plugin-syntax.md.

Why

  • A worker instead of the window's thread. One regex scan can't be interrupted, so a plugin grammar runs where Orca can terminate it. Keeping the worker warm with the compiled grammar means typing never pays the compile cost again.
  • Semantic tokens instead of a line-by-line provider. Monaco's line provider sees one line and the previous line's state, never the model, so worker results could only be matched by line text, and everything below an edit went plain until the next pass. Semantic tokens are per model, requested only for visible editors, and keep the previous colors in place during a pass.
  • Fill gaps; don't override built-ins. A plugin can't silently change how Orca highlights a language it already supports. There's no per-file override yet.
  • A slot pool. A language id per plugin, version and reload would grow without bound, because Monaco can't unregister languages.

Linked Issue

None. This is part of the plugin platform rework (maintainer change).

Visual Proof

Screenshots from a hidden dev window (ORCA_BACKGROUND_LAUNCH=1, isolated profile, mock keychain), captured over CDP:

  • A 5,600-line Gleam file with the example pack. Types, numbers, comments, keywords and brackets take the dark theme's own colors: 7-big-gleam-highlighted.png
  • Close-up: 10-zoom-keywords-types.png
  • Mid-typing: lines below the edit keep their colors on every keystroke (17 of 25 non-empty visible lines stay multi-token; the rest are lone braces): 8-mid-typing-big-file.png
  • After typing settles: 9-after-typing-big-file.png
  • Live install, grammar update and disable/re-enable (first engine; now re-verified by plugin-syntax-smoke.spec.ts): 2-hot-loaded.png 4-after-grammar-update.png 6-reenabled.png

Testing

  • Unit tests:

    • Grammar and configuration validation: Orca's real Typst grammar, scope mismatch, caps, includes inside and outside the plugin, and a 40,000-include grammar checked in under a second (plugin-syntax-artifact.test.ts).
    • The registry: associations, revision, sibling grammars, and include errors on the card (plugin-syntax-registry.test.ts).
    • The Gleam example passes production install inspection and loads (plugin-example-gleam-syntax.test.ts).
    • Real-engine tokenization: the Typst grammar, long-line cut-off, cancellation, size, and an embedded outside scope staying plain (plugin-grammar-tokenization.test.ts).
    • The worker client with a fake worker: a slow setup never counts as a stall, setup that never finishes or can't compile fails cleanly, one compile across documents, a superseded pass dropped by id without terminating, stall → terminate and respawn, idle shutdown, crash, invalid results and size (plugin-grammar-worker-client.test.ts).
    • The legend: every token name is styled by both built-in themes, punctuation is skipped, and scopes map to the right names (plugin-syntax-token-legend.test.ts).
    • The slot pool: 600 languages opened and closed never exhaust it, plus sharing, LRU eviction, all-open fallback, double release, and models released when no editor uses a language (plugin-syntax-slot-pool.test.ts).
    • File matching (plugin-syntax-packs.test.ts).
  • Local suites: 41,330 tests across plugins, shared, IPC, persistence, renderer lib/store/editor/settings/hooks and preload pass. tc:node, tc:web, oxlint, check:code-quality:changed and localization checks are clean.

  • End-to-end: all plugin specs pass locally. plugin-syntax-smoke.spec.ts uses the Gleam pack. It checks the actual comment, type and number colors against the built-in themes, switches tabs away and back (this check fails with the remount fix removed), then updates and disables the pack.

  • Platforms: macOS locally. This draft skips most CI jobs, so Linux and Windows aren't covered yet.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

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

  • Stall path, stated plainly: Oniguruma's retry limit ends each catastrophic scan in about 85 ms, so core's line limits stop a slow grammar first. I couldn't make a real grammar stall the worker. The 2 s progress deadline guards against engine hangs and crashes, and is tested with a fake worker only.
  • Security: grammars are data. They are parsed and allowlisted in main, re-validated at renderer ingress, run off the main thread, and can't include grammars outside their plugin. Worker errors never echo grammar or document text.
  • SSH: highlighting uses only the file's name and the text already in the editor, so remote files behave the same.
  • Not in this PR:
    • a per-file language picker and user associations
    • letting a plugin override a built-in language
  • Depends on: the plugin settings UX PR.

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). Targeted suites, tc:node, tc:web, oxlint, the change-quality gate and plugin e2e pass locally; full pnpm lint not run.

@nwparker
nwparker force-pushed the nwparker/plugins-v2-6-settings-ux branch from cbe1dea to 42f40c5 Compare October 19, 2026 21:42
@nwparker
nwparker force-pushed the nwparker/plugins-v2-7-syntax-packs branch 2 times, most recently from bbec1a5 to 65098ae Compare October 21, 2026 06:34
@nwparker
nwparker force-pushed the nwparker/plugins-v2-6-settings-ux branch 2 times, most recently from 111ab32 to b04942d Compare October 21, 2026 12:23
@nwparker
nwparker force-pushed the nwparker/plugins-v2-7-syntax-packs branch from 65098ae to 4d4c87c Compare October 21, 2026 12:23
@nwparker
nwparker marked this pull request as ready for review October 21, 2026 12:24
@nwparker
nwparker force-pushed the nwparker/plugins-v2-6-settings-ux branch from b04942d to c50d65b Compare October 21, 2026 20:10
@nwparker
nwparker force-pushed the nwparker/plugins-v2-7-syntax-packs branch from 4d4c87c to 7aa0734 Compare October 21, 2026 20:10
@nwparker
nwparker force-pushed the nwparker/plugins-v2-6-settings-ux branch from c50d65b to 00f479d Compare October 24, 2026 11:43
@nwparker
nwparker force-pushed the nwparker/plugins-v2-7-syntax-packs branch 3 times, most recently from 1815b6e to bf08223 Compare October 25, 2026 05:23
@nwparker
nwparker force-pushed the nwparker/plugins-v2-6-settings-ux branch 2 times, most recently from 7452b90 to eb24515 Compare October 26, 2026 12:04
@nwparker
nwparker force-pushed the nwparker/plugins-v2-7-syntax-packs branch 2 times, most recently from 20e19c6 to ad09422 Compare October 26, 2026 12:32
@nwparker
nwparker force-pushed the nwparker/plugins-v2-6-settings-ux branch 2 times, most recently from 0d68d0b to e835a1e Compare October 28, 2026 04:57
@nwparker
nwparker force-pushed the nwparker/plugins-v2-7-syntax-packs branch from ad09422 to 48cb49b Compare October 28, 2026 04:57
@nwparker
nwparker force-pushed the nwparker/plugins-v2-6-settings-ux branch from e835a1e to 086c8f0 Compare October 28, 2026 05:30
@nwparker
nwparker force-pushed the nwparker/plugins-v2-7-syntax-packs branch from 48cb49b to 65e407c Compare October 28, 2026 05:30
A plugin can contribute up to 16 syntaxes: a TextMate grammar, optional
language configuration, and the file extensions and names it claims.
Main validates every grammar when the plugin is approved (shape, scope,
size, nesting) and lists only the file associations. A language's
grammars cross IPC only when a matching file opens, and includes must
resolve inside the same plugin. Catalog releases can declare syntax.
Files Orca shows as plain text use a matching plugin syntax. Its grammar
compiles once in a worker that stays warm between edits and runs under
core's per-line limits; a worker that stops reporting progress or crashes
is terminated, the language stays plain, and the plugin card says so.
Tokens reach Monaco as semantic tokens, so Monaco asks only for models
shown in an editor, keeps one request per model, and keeps painting the
previous colors, shifted by edits, until the new pass lands. Plugin
languages borrow ids from a pool of fixed Monaco languages, counted by
the editors using them; a language no editor uses moves its models back
to plain text, and the least recently used idle slots are reused first.
An official-style data plugin with the upstream Gleam TextMate grammar
(Apache-2.0, provenance and license alongside) and language
configuration. A test installs it through the production inspection and
loads it through the syntax registry.
…view

The preview's Includes line named only language packs, commands,
shortcuts, VM recipes, panels and events, so a theme or syntax pack read
as "Manifest metadata only".
…x id

A grammar that failed in revision A kept the plugin card flagged after revision B
replaced it. Failures are now keyed by id@revision, matching the runtime slots,
and dropped when the installed list no longer contains that revision.
@nwparker
nwparker force-pushed the nwparker/plugins-v2-7-syntax-packs branch from 65e407c to 58bfd00 Compare October 28, 2026 10:53
@nwparker
nwparker force-pushed the nwparker/plugins-v2-6-settings-ux branch from 086c8f0 to 26d649b Compare October 28, 2026 10:53
@nwparker nwparker mentioned this pull request Oct 28, 2026
7 of 9 tasks
@nwparker

Copy link
Copy Markdown
Contributor Author

Folded into #35470 (Plugin Alpha), which lands the rest of the plugin stack in one PR.

@nwparker nwparker closed this Oct 28, 2026
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