Skip to content

Replace CodeMirror/Lezer syntax highlighting with Shiki#12808

Merged
mtsgrd merged 1 commit intomasterfrom
shiki-highlighter-integration
Mar 12, 2026
Merged

Replace CodeMirror/Lezer syntax highlighting with Shiki#12808
mtsgrd merged 1 commit intomasterfrom
shiki-highlighter-integration

Conversation

@mtsgrd
Copy link
Copy Markdown
Contributor

@mtsgrd mtsgrd commented Mar 12, 2026

Replace the custom CodeMirror/Lezer-based syntax highlighting in the
diff view with Shiki, which uses TextMate grammars (same as VS Code)
for better language coverage and highlighting quality.

Key changes:

  • Add shikiHighlighter.ts module that manages a singleton Shiki
    highlighter with lazy async initialization and DOM-based theme
    detection (github-light/github-dark matched to the app's light/dark
    mode).
  • Refactor diffParsing.ts to use Shiki's tokenizer instead of
    CodeMirror parsers, with language ID string caches replacing the
    old WeakMap caches.
  • Observe class mutations so highlighting caches are cleared
    and components re-render when the app theme toggles.
  • Map .svelte and .vue to TypeScript for line-by-line highlighting,
    since their SFC grammars require full-file context.
  • Remove 24 @codemirror/* and @lezer/* dependencies in favor of the
    single shiki package.

After:
image

Before:
image

After:
image

Before:
image

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gitbutler-web Ready Ready Preview, Comment Mar 12, 2026 10:41pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates UI diff/code-block syntax highlighting from CodeMirror/Lezer-based token classes to a Shiki-based highlighter, aiming to reduce dependency surface and support theme-aware highlighting via Shiki themes.

Changes:

  • Replaced CodeMirror parser/highlight pipeline in diffParsing.ts with Shiki tokenization and new caching logic.
  • Added a Shiki highlighter singleton with theme-change observation and language/filename mapping.
  • Removed the old token-class-based syntax CSS and dropped CodeMirror/Lezer-related dependencies (adding shiki).

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pnpm-lock.yaml Updates lockfile for removal of CodeMirror/Lezer deps and addition of Shiki deps.
packages/ui/src/styles/sharable/syntax-highlighting.css Removes syntax token class styling; keeps only word-diff highlighting styles.
packages/ui/src/lib/utils/shikiHighlighter.ts Introduces Shiki singleton highlighter, theme detection, and language mapping/tokenization helpers.
packages/ui/src/lib/utils/diffParsing.ts Switches diff tokenization from CodeMirror highlight tree to Shiki tokens + language-keyed caches.
packages/ui/src/lib/components/hunkDiff/HunkDiffBody.svelte Recomputes diff rows when Shiki becomes ready or theme changes.
packages/ui/package.json Removes CodeMirror/Lezer-related dev deps and adds shiki.
apps/web/src/lib/components/chat/MessageCode.svelte Recomputes chat code rendering when Shiki becomes ready or theme changes.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

You can also share your feedback on Copilot code review. Take the survey.

Comment thread packages/ui/src/lib/utils/shikiHighlighter.ts
Comment thread packages/ui/src/lib/utils/shikiHighlighter.ts Outdated
Comment thread packages/ui/src/lib/utils/diffParsing.ts
Comment thread packages/ui/src/lib/components/hunkDiff/HunkDiffBody.svelte Outdated
Comment thread apps/web/src/lib/components/chat/MessageCode.svelte Outdated
Comment thread packages/ui/package.json
Replace the custom CodeMirror/Lezer-based syntax highlighting in the
diff view with Shiki, which uses TextMate grammars (same as VS Code)
for better language coverage and highlighting quality.

Key changes:
- Add shikiHighlighter.ts module that manages a singleton Shiki
  highlighter with lazy async initialization and DOM-based theme
  detection (github-light/github-dark matched to the app's light/dark
  mode).
- Refactor diffParsing.ts to use Shiki's tokenizer instead of
  CodeMirror parsers, with language ID string caches replacing the
  old WeakMap<Parser> caches.
- Observe <html> class mutations so highlighting caches are cleared
  and components re-render when the app theme toggles.
- Map .svelte and .vue to TypeScript for line-by-line highlighting,
  since their SFC grammars require full-file context.
- Remove 24 @codemirror/* and @lezer/* dependencies in favor of the
  single shiki package.
Copilot AI review requested due to automatic review settings March 12, 2026 22:39
@mtsgrd mtsgrd force-pushed the shiki-highlighter-integration branch from 3b2d45c to d2ebcd5 Compare March 12, 2026 22:39
@mtsgrd mtsgrd enabled auto-merge March 12, 2026 22:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

You can also share your feedback on Copilot code review. Take the survey.

Comment thread packages/ui/src/lib/utils/shikiHighlighter.ts
Comment thread packages/ui/src/lib/utils/diffParsing.ts
Comment thread packages/ui/src/lib/utils/shikiHighlighter.ts
@mtsgrd mtsgrd merged commit 0959379 into master Mar 12, 2026
41 checks passed
@mtsgrd mtsgrd deleted the shiki-highlighter-integration branch March 12, 2026 22:55
mtsgrd added a commit that referenced this pull request Mar 12, 2026
…tion

Replace CodeMirror/Lezer syntax highlighting with Shiki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants