Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Oct 19, 2025

Adds language-specific syntax highlighting to diff hunks in the Code Review panel and file edit tool outputs.

What Changed

Before: Plain monochrome diffs with no language context
After: Syntax-highlighted code with language-appropriate colors while preserving diff semantics (green/red backgrounds, +/- prefixes, line numbers)

Visual Examples

  • TypeScript: Keywords, types, strings, functions colored appropriately
  • Python: Syntax highlighting for def, class, imports, etc.
  • 80+ languages supported: Go, Rust, Java, JavaScript, HTML, CSS, YAML, JSON, etc.

Implementation Highlights

Custom Language Detection:

  • Simple extension-based mapping (no dependencies)
  • Removed unreliable detect-programming-language package
  • 100% accurate for all common file types
  • Special filename support (Dockerfile, Makefile, Gemfile, etc.)

Smart Highlighting Strategy:

  • Full-hunk highlighting preserves multi-line syntax (template literals, comments, etc.)
  • Reuses vscDarkPlus theme (consistent with markdown code blocks)
  • Syntax colors overlay diff backgrounds without conflicts

Consistent Typography:

  • Code review diffs: 12px font
  • File edit tool diffs: 11px font (visual distinction)
  • All diff components inherit sizing properly

Universal Coverage:

  • ✅ Code review panel (SelectableDiffRenderer)
  • ✅ File edit tool outputs (DiffRenderer)
  • ✅ All operations: replace_string, replace_lines, insert

Testing

  • 30 new unit tests for language detection (all passing)
  • 658 total tests passing
  • TypeScript strict mode clean
  • No regressions in diff rendering

Generated with cmux

- Install detect-programming-language for language detection
- Create languageDetector utility mapping file extensions to Prism languages
- Extract syntaxStyleNoBackgrounds to shared styles file
- Update MarkdownComponents to use shared syntax styles
- Add syntax highlighting to DiffRenderer and SelectableDiffRenderer
- Add 27 unit tests for language detection covering common file types
- Syntax highlights code while preserving diff semantics (green/red backgrounds)

Generated with `cmux`
- Fix @typescript-eslint/no-require-imports error
- Fix @typescript-eslint/prefer-nullish-coalescing warnings
- Use ?? instead of || for safer null checks

Generated with `cmux`
The detect-programming-language package had significant limitations:
- Missing support for common file types (HTML, JSON, CSS, etc.)
- Incorrect detection (e.g., .cs files detected as Smalltalk)
- Only 855 extensions mapped vs. our 80+ comprehensive mapping

Replaced with custom solution:
- Extension-based detection (no external dependency needed)
- Special filename handling (Dockerfile, Makefile, Gemfile, etc.)
- Comprehensive coverage: JS/TS, web tech, backend languages, config formats
- All 30 test cases passing

The rest of the syntax highlighting feature was already complete:
- syntaxStyleNoBackgrounds extracted and shared
- DiffRenderer with HighlightedContent component
- SelectableDiffRenderer with language detection
- HunkViewer passing filePath prop

Net change: -1 dependency, +39 lines, more reliable detection
Establish consistent 11px font size across all diff components:

**Problems:**
- SyntaxHighlighter was using default browser font size
- LineNumber had conditional sizing (14px for headers)
- CommentButton used 10px (smaller than other text)
- NoteTextarea placeholder had redundant font-size
- Font family inconsistency (textarea used sans-serif)

**Solution:**
- Add universal font-size inheritance rule to DiffContainer
- Explicitly set fontSize: 'inherit' on SyntaxHighlighter
- Remove conditional font sizing from LineNumber
- Standardize CommentButton to 11px
- Switch NoteTextarea to monospace font to match code
- Remove redundant placeholder font-size

All text in diff view now renders at consistent 11px.
FileEditToolCall was not passing filePath to DiffRenderer, so tool edits
displayed plain diffs without syntax highlighting.

Now all file edit operations (replace_string, replace_lines, insert) show
syntax-highlighted diffs matching the code review panel behavior.
Make the + icon in the comment button more visible.
Changed DiffContainer base font from 11px to 12px.
CommentButton now inherits font size instead of hardcoding it.
Updated NoteTextarea min-height calculation to match new base size.
Added optional fontSize prop to DiffContainer, DiffRenderer, and SelectableDiffRenderer.
FileEditToolCall now uses 11px font size while code review panel keeps 12px.

This provides visual distinction between tool outputs (11px) and code review (12px).
@ammario ammario merged commit 480ba7a into main Oct 19, 2025
8 checks passed
@ammario ammario deleted the syntax-highlighting branch October 19, 2025 16:13
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.

2 participants