Commit 480ba7a
authored
🤖 Add syntax highlighting to code review diffs (#328)
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`_1 parent 43870e3 commit 480ba7a
File tree
6 files changed
+413
-26
lines changed- src
- components
- Messages
- tools
- styles
- utils/git
6 files changed
+413
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | | - | |
| 4 | + | |
6 | 5 | | |
7 | 6 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | 7 | | |
18 | 8 | | |
19 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| |||
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
76 | | - | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
108 | | - | |
| 110 | + | |
109 | 111 | | |
110 | 112 | | |
111 | 113 | | |
112 | 114 | | |
113 | | - | |
| 115 | + | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
| |||
119 | 121 | | |
120 | 122 | | |
121 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
122 | 129 | | |
123 | 130 | | |
124 | 131 | | |
| |||
130 | 137 | | |
131 | 138 | | |
132 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
133 | 144 | | |
134 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
135 | 182 | | |
136 | 183 | | |
137 | 184 | | |
| |||
146 | 193 | | |
147 | 194 | | |
148 | 195 | | |
| 196 | + | |
| 197 | + | |
149 | 198 | | |
150 | 199 | | |
151 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
152 | 204 | | |
153 | 205 | | |
154 | 206 | | |
155 | 207 | | |
156 | | - | |
| 208 | + | |
157 | 209 | | |
158 | 210 | | |
159 | 211 | | |
| |||
193 | 245 | | |
194 | 246 | | |
195 | 247 | | |
196 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
197 | 251 | | |
198 | 252 | | |
199 | 253 | | |
200 | 254 | | |
201 | | - | |
| 255 | + | |
202 | 256 | | |
203 | 257 | | |
204 | 258 | | |
205 | 259 | | |
206 | | - | |
| 260 | + | |
207 | 261 | | |
208 | 262 | | |
209 | 263 | | |
| |||
255 | 309 | | |
256 | 310 | | |
257 | 311 | | |
258 | | - | |
259 | 312 | | |
260 | 313 | | |
261 | 314 | | |
| |||
284 | 337 | | |
285 | 338 | | |
286 | 339 | | |
287 | | - | |
| 340 | + | |
288 | 341 | | |
289 | | - | |
290 | | - | |
| 342 | + | |
| 343 | + | |
291 | 344 | | |
292 | 345 | | |
293 | 346 | | |
| |||
303 | 356 | | |
304 | 357 | | |
305 | 358 | | |
306 | | - | |
307 | 359 | | |
308 | 360 | | |
309 | 361 | | |
| |||
396 | 448 | | |
397 | 449 | | |
398 | 450 | | |
| 451 | + | |
399 | 452 | | |
400 | 453 | | |
401 | 454 | | |
402 | 455 | | |
403 | 456 | | |
404 | 457 | | |
405 | 458 | | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
406 | 462 | | |
407 | 463 | | |
408 | 464 | | |
| |||
494 | 550 | | |
495 | 551 | | |
496 | 552 | | |
497 | | - | |
| 553 | + | |
498 | 554 | | |
499 | 555 | | |
500 | 556 | | |
| |||
522 | 578 | | |
523 | 579 | | |
524 | 580 | | |
525 | | - | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
526 | 584 | | |
527 | 585 | | |
528 | 586 | | |
| |||
542 | 600 | | |
543 | 601 | | |
544 | 602 | | |
545 | | - | |
| 603 | + | |
546 | 604 | | |
547 | 605 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| 121 | + | |
| 122 | + | |
120 | 123 | | |
121 | 124 | | |
122 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
0 commit comments