Skip to content

feat: Shiki-backed syntax highlighting with VS Code theme bridge (#1026) - #1028

Merged
jeonghun-jj-lee merged 8 commits into
mainfrom
jj/1026-shiki-syntax-highlighting
Sep 12, 2026
Merged

feat: Shiki-backed syntax highlighting with VS Code theme bridge (#1026)#1028
jeonghun-jj-lee merged 8 commits into
mainfrom
jj/1026-shiki-syntax-highlighting

Conversation

@jeonghun-jj-lee

Copy link
Copy Markdown
Contributor

Closes #1026

Slice 1: VS Code theme extraction + bridge

Adds syntax_theme_bridge.ts — resolves the active VS Code color theme to either a Shiki built-in name (fast path, ~30 popular themes) or a full TextMate theme object extracted from the contributing extension's filesystem.

What it does

  • Known theme matching: maps popular VS Code themes (Dark+, Dracula, Nord, One Dark Pro, etc.) to Shiki built-in names — no file reading needed
  • Custom theme extraction: finds the contributing extension via vscode.extensions.all, reads the theme JSON, resolves include chains (max depth 5, cycle detection), and returns the full TextMate theme object
  • User override merging: layers editor.tokenColorCustomizations.textMateRules on top
  • Wired into ChatPanel: fires on onDidChangeActiveColorTheme, workbench.colorTheme, and editor.tokenColorCustomizations changes
  • Lane 2 allowlist: adds syntax-theme to both relay allowlists so the message reaches the framed app

Testing

  • 8 new tests in syntax_theme_bridge.test.ts covering all behaviors
  • Full suite (205 files, 3243 tests) passes

Remaining slices (fork changes)

  • Slice 2: Shiki theme state + registration (webview)
  • Slice 3: Shiki CM6 decoration plugin
  • Slice 4: Language expansion (@codemirror/language-data)
  • Slice 5: Consistency unification (markdown + @pierre/diffs)

Add syntax_theme_bridge.ts: resolves the active VS Code color theme to
either a Shiki built-in name (fast path, ~30 popular themes) or a full
TextMate theme object extracted from the contributing extension's
filesystem. Handles include chains (max depth 5, cycle detection) and
merges editor.tokenColorCustomizations user overrides.

Wire into ChatPanel: postSyntaxTheme() fires on theme change, on
workbench.colorTheme change, and on tokenColorCustomizations change.
Add 'syntax-theme' to both Lane 2 relay allowlists so the message
reaches the framed app.

8 tests covering: built-in matching, custom extraction, include chains,
cycle detection, user override merging, and fallback behavior.
@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

…#1026)

Overlay promotion from opencode fork branch with Slices 2-5:
- shiki-theme-state.ts: reactive theme state for the webview
- shiki-highlight-worker.ts: dedicated Shiki tokenization Web Worker
- shiki-highlight-plugin.ts: CM6 ViewPlugin with Shiki decorations
- editor-core.ts: wired Shiki extension + language-data fallback
- preview-editor.tsx + editable-diff-view: pass lang to baseExtensions
- markdown-shiki.worker.ts: theme-update support
- pierre/worker.ts: active theme for @pierre/diffs pools
- app.tsx: syntax-theme message handler

Plus opencode fork upstream changes included in the full promotion.
Three bugs fixed in the fork:
1. Empty fallback theme: worker init now uses the actual OpenCodeTheme
   (30+ TextMate scope rules) instead of an empty stub
2. Worker URL: uses Vite ?worker&url import pattern matching existing
   markdown-shiki and @pierre/diffs workers
3. Test compat: extracted pure decoration logic to shiki-highlight-
   decorations.ts; editor-core.ts lazy-imports the plugin module

New integration test verifies Shiki produces colored tokens + valid
CM6 decorations for Julia, TypeScript, Python, Rust, Go, YAML, and
Shell (16 tests, all green).
…fa55b660a)

Previous incremental syncs used intermediate fork commits as the base,
causing new Shiki files to be missing from the overlay. Redo as a
full fork-vs-upstream-base delta to get all 18 files correctly.

Fixes: shiki-highlight-plugin.ts, shiki-highlight-worker.ts,
shiki-highlight-decorations.ts, shiki-theme-state.ts and tests now
present in the overlay. The binary was already built from the correct
fork commit (afc0f1c26a) — this fixes only the overlay tracking copy.
The extension previously posted syntax-theme only after a later VS Code
theme/configuration change. A newly opened Preview tab therefore stayed
on the OpenCode fallback palette forever.

Post the resolved syntax theme on the existing app-ready handshake,
when the iframe listener is guaranteed to exist. Restore live refreshes
for colorTheme and tokenColorCustomizations changes, and admit the
message through both Lane 2 relay render paths.

Add regression coverage proving a fresh panel receives dark-plus after
app-ready and both relays contain syntax-theme.
The overlay sync in earlier commits wiped amicode-side patches (#929, #832,
#987, OAuth bridge, titlebar interactions) because the fork's local/amicode
branch doesn't carry them yet. Restore the full overlay from main; the
proper sync happens after the fork PR merges into local/amicode.
The sync:apply rewrote the manifest to point at the Shiki feature branch
(afc0f1c26a) instead of local/amicode. Restore main's manifest so the
drift gate passes against local/amicode as-is.
@jeonghun-jj-lee
jeonghun-jj-lee marked this pull request as ready for review September 12, 2026 02:53
@jeonghun-jj-lee
jeonghun-jj-lee merged commit 9b09145 into main Sep 12, 2026
10 checks passed
@jeonghun-jj-lee
jeonghun-jj-lee deleted the jj/1026-shiki-syntax-highlighting branch September 12, 2026 02:53
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.

Shiki-backed syntax highlighting with VS Code theme bridge

1 participant