Skip to content

feat(tui): chroma syntax highlighting for diff and content preview - #868

Merged
edenreich merged 1 commit into
mainfrom
feat/chroma-syntax-highlighting-for-diff-content
Jul 11, 2026
Merged

edenreich merged 1 commit into
mainfrom
feat/chroma-syntax-highlighting-for-diff-content

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

Add language-aware syntax highlighting using chroma (already a transitive dependency via glamour) for diff content and file content previews in the card-based tool-call formatter, keyed off file extension with a plain fallback.

Changes

  • diffview/diffview.go — Add WithChromaStyle fluent setter on DiffView. Nil/no-call preserves exact current behavior. Clears the syntax cache on set.
  • diff_renderer.go — Add private chromaStyle() method deriving github (light) or github-dark from the active theme's brightness. Wire it into buildDiffView() and renderContentPreview() (which now takes a filePath parameter for lexer selection).
  • diff_renderer_test.go — Three new tests: known language (.go), unknown extension (.xyzabc), and nil style provider (no crash).

Key Design Decisions

Decision Rationale
Chroma style gated on chromaStyle == nil inside highlightCode() Existing guard — nil = no highlighting, no perf cost
Highlight() with lineNumbers=false for content previews Custom gutter is already rendered; Highlight handles tab expansion, normalization, tokenisation
contentPreviewLimit cap applied after highlighting Lexing only processes the shown lines (default 50), no unbounded work
LLM format also gets chroma Diff output already has ANSI backgrounds from #865; chroma tokens are additive readability improvement

Testing

  • task precommit:run — all hooks pass
  • Existing TestDiffRenderer_* tests pass
  • New TestDiffRenderer_SyntaxHighlight_* tests pass

Closes #866

Add language-aware syntax highlighting using chroma (already a transitive
dependency via glamour) for diff content and file content previews in the
card-based tool-call formatter, keyed off file extension with a plain
fallback.

- Add WithChromaStyle fluent setter to diffview.DiffView
- Add chromaStyle() helper on DiffRenderer, deriving github/github-dark
  from the active theme's brightness
- Wire chroma into buildDiffView() for diff syntax highlighting
- Wire chroma into renderContentPreview() for file content previews
- Three unit tests covering known language, unknown extension, and nil
  style (no crash) scenarios
@edenreich
edenreich requested a review from a team as a code owner July 11, 2026 23:50
@edenreich
edenreich merged commit 3d10d94 into main Jul 11, 2026
1 check passed
@edenreich
edenreich deleted the feat/chroma-syntax-highlighting-for-diff-content branch July 11, 2026 23:55
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.143.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Syntax highlighting for code in diff/content rendering (chroma)

1 participant