codediff 0.0.14

Fast, robust, syntax-aware code diffing using tree-sitter ASTs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --border: #d8d8d8;
  --panel-bg: #fafafa;
  --unmarked: #6b6b6b;
  --matched: #0969da;
  --deleted: #cf222e;
  --inserted: #1a7f37;
  --update: #9a6700;
  --moved: #8250df;
  --selected-bg: #ffe58a;
  --selected-fg: #1a1a1a;
  --highlight-bg: #cfe6ff;
  --link: #0969da;
  --button-bg: #f0f0f0;
  --button-border: #c8c8c8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --fg: #e6edf3;
    --muted: #9aa4af;
    --border: #30363d;
    --panel-bg: #161b22;
    --unmarked: #9aa4af;
    --matched: #58a6ff;
    --deleted: #ff7b72;
    --inserted: #56d364;
    --update: #d29922;
    --moved: #a371f7;
    --selected-bg: #6b5900;
    --selected-fg: #f5e6a8;
    --highlight-bg: #16324a;
    --link: #58a6ff;
    --button-bg: #21262d;
    --button-border: #30363d;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 1rem 5rem;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  background: var(--bg);
  color: var(--fg);
}

a {
  color: var(--link);
}

.page-header {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.page-header h1 {
  font-size: 1.1rem;
  margin: 0.25rem 0;
}

.back-link {
  font-size: 0.85rem;
}

.language-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
}

.source-link {
  display: inline-block;
  margin-left: 0.75rem;
  font-size: 0.8rem;
}

.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin: 0.5rem 0 0;
  padding: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.3em;
}

.fixture-table {
  border-collapse: collapse;
  max-width: 60rem;
  width: 100%;
}

.fixture-table th,
.fixture-table td {
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.fixture-table td:nth-child(n + 3),
.fixture-table th:nth-child(n + 3) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.fixture-table th {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.fixture-table th:hover {
  color: var(--fg);
}

.fixture-table th[aria-sort="ascending"],
.fixture-table th[aria-sort="descending"] {
  color: var(--matched);
}

.fixture-table th[aria-sort="ascending"]::after {
  content: " \25b4";
}

.fixture-table th[aria-sort="descending"]::after {
  content: " \25be";
}

.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 900px) {
  .panels {
    grid-template-columns: 1fr;
  }
}

.panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  padding: 0.5rem 0.75rem;
  overflow-x: auto;
}

.panel[data-focused="true"] {
  border-color: var(--matched);
}

.panel h2 {
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tree {
  white-space: nowrap;
}

.node {
  display: block;
}

details.node {
  margin: 0;
}

details.node > summary {
  cursor: pointer;
  list-style: none;
}

details.node > summary::-webkit-details-marker {
  display: none;
}

details.node > summary::before {
  content: "\25b8";
  display: inline-block;
  width: 1em;
  color: var(--muted);
}

details.node[open] > summary::before {
  content: "\25be";
}

details.node > *:not(summary) {
  margin-left: 1.1em;
}

.node.leaf {
  padding-left: 1.1em;
}

.node.leaf,
details.node > summary {
  padding: 0.05rem 0.2rem;
  border-radius: 3px;
}

.node.leaf:hover,
details.node > summary:hover {
  background: color-mix(in srgb, var(--matched) 12%, transparent);
}

.status-unmarked {
  color: var(--unmarked);
}

.status-matched {
  color: var(--matched);
}

.status-deleted {
  color: var(--deleted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.status-inserted {
  color: var(--inserted);
}

/* A `status-matched` node that's a real edit (Update/MatchButNotIdentical), not a genuinely
   identical match - see `render_node`'s `changed_class` in generate_mapping_site.rs. Bold rather
   than a new color: it's still a "matched" pair (blue), just one the "hide identical matches"
   toggle below must never hide. */
.changed {
  font-weight: 700;
}

/* Which kind of matched pair this is - independent of `.changed` above, and overrides
   `.status-matched`'s plain blue (two classes beats one on specificity, so this wins regardless of
   the two rules' order in this file). `.op-update`: a leaf whose text changed (still `.changed` -
   yellow AND bold). `.op-moved`: a genuinely `Identical` pair - same content - that nonetheless
   sits at a different position than before (see `Caches::before_moved` in human_mapping.rs); never
   `.changed` and not bold, since nothing about its content differs, only where it is. */
.status-matched.op-update {
  color: var(--update);
}

.status-matched.op-moved {
  color: var(--moved);
}

/* Toggled on <body> by viewer.js's "hide identical matches" button/keybinding. Hides any node
   that's neither itself deleted/inserted/changed nor an ancestor of one (:has() finds a
   qualifying node at any depth, not just a direct child) - i.e. every genuinely-identical match
   and every never-annotated node, unless something interesting is nested underneath it. */
body.hide-identical .node:not(.status-deleted, .status-inserted, .changed):not(
    :has(.status-deleted, .status-inserted, .changed)
  ) {
  display: none;
}

.node.placeholder {
  font-style: italic;
  opacity: 0.75;
}

.node.selected > summary,
.node.leaf.selected {
  background: var(--selected-bg) !important;
  color: var(--selected-fg) !important;
}

.node.counterpart > summary,
.node.leaf.counterpart {
  background: var(--highlight-bg) !important;
}

.page-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

#file-issue,
#toggle-identical {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
}

#file-issue[aria-disabled="true"] {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

#toggle-identical[aria-pressed="true"] {
  background: var(--matched);
  color: #fff;
  border-color: var(--matched);
}

#status-line {
  color: var(--muted);
  font-size: 0.8rem;
}

#help-overlay {
  position: fixed;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.5rem;
  max-width: 30rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 10;
}

#help-overlay.hidden {
  display: none;
}

#help-overlay dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 1rem;
  margin: 0.5rem 0 0;
}

#help-overlay dt {
  font-weight: bold;
  color: var(--matched);
}

#help-overlay dd {
  margin: 0;
  color: var(--fg);
}

#search-prompt {
  position: fixed;
  bottom: 3.2rem;
  left: 1rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  z-index: 10;
}

#search-prompt.hidden {
  display: none;
}

#search-prompt input {
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--button-border);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
}

/* ---------------------------------------------------------------- code panels
 * The rendered-source counterpart to the tree panels. Uses the same four operation colors as the
 * tree, but as backgrounds rather than text color: code has its own reasons to want the foreground
 * (and a whole line tinted is what makes a change findable while scrolling), so each operation gets
 * a muted background token alongside the strong foreground one it already had.
 */

:root {
  --deleted-bg: #ffd7d5;
  --inserted-bg: #cdf3d5;
  --update-bg: #f7e6bd;
  --moved-bg: #e6dbfb;
  --deleted-row-bg: #ffefee;
  --inserted-row-bg: #eaf9ee;
  --update-row-bg: #fbf4e2;
  --moved-row-bg: #f3eefc;
  --counterpart-outline: #0969da;
}

@media (prefers-color-scheme: dark) {
  :root {
    --deleted-bg: #67282c;
    --inserted-bg: #1f5c30;
    --update-bg: #5c4409;
    --moved-bg: #402e63;
    --deleted-row-bg: #2b1b1d;
    --inserted-row-bg: #172a1d;
    --update-row-bg: #2a2413;
    --moved-row-bg: #221c2f;
    --counterpart-outline: #58a6ff;
  }
}

.code-panels {
  margin-bottom: 1rem;
}

.code {
  white-space: pre;
  line-height: 1.45;
}

.cl {
  display: flex;
  align-items: flex-start;
}

.cl .ln {
  flex: 0 0 4ch;
  text-align: right;
  padding-right: 1ch;
  color: var(--muted);
  user-select: none;
}

.cl .lt {
  flex: 1 1 auto;
  min-width: 0;
}

.cl.fold {
  color: var(--muted);
  font-style: italic;
  border-top: 1px dashed var(--border);
  border-bottom: 1px dashed var(--border);
  margin: 0.15rem 0;
}

.cl.row-cd-delete {
  background: var(--deleted-row-bg);
}
.cl.row-cd-insert {
  background: var(--inserted-row-bg);
}
.cl.row-cd-update {
  background: var(--update-row-bg);
}
.cl.row-cd-move {
  background: var(--moved-row-bg);
}

.cd {
  border-radius: 2px;
  cursor: pointer;
}

.cd-delete {
  background: var(--deleted-bg);
}
.cd-insert {
  background: var(--inserted-bg);
}
.cd-update {
  background: var(--update-bg);
}
.cd-move {
  background: var(--moved-bg);
}

/* A zero-width placeholder range: the side with nothing to show for an insert/delete still gets a
 * range at the position the other side's text belongs (see TextRange's doc comment). Drawn as a
 * caret between two characters - it is the only thing marking, say, where a deleted function used
 * to be on the after side. Clickable like any other span, and its counterpart is the real text. */
.cd.cd-gap {
  display: inline-block;
  width: 0;
  background: none;
  border-left: 2px solid var(--deleted);
  margin: 0 -1px;
}

.cd.cd-gap.cd-insert {
  border-left-color: var(--inserted);
}

.cl.row-gap .ln {
  border-right: 2px solid var(--muted);
}

.cd.selected {
  outline: 2px solid var(--selected-fg);
  outline-offset: -1px;
}

.cd.counterpart {
  outline: 2px dashed var(--counterpart-outline);
  outline-offset: -1px;
}

/* Only the tree panels carry the "hide identical matches" behaviour and the keyboard cursor; the
 * view switch below is what hides one half or the other wholesale. */
body[data-view="code"] .tree-panels,
body[data-view="tree"] .code-panels {
  display: none;
}

.view-switch {
  display: inline-flex;
  gap: 0;
  margin-top: 0.5rem;
}

.view-switch button {
  font: inherit;
  padding: 0.15rem 0.6rem;
  background: var(--button-bg);
  color: var(--fg);
  border: 1px solid var(--button-border);
  cursor: pointer;
}

.view-switch button:first-child {
  border-radius: 4px 0 0 4px;
}

.view-switch button:last-child {
  border-radius: 0 4px 4px 0;
}

.view-switch button + button {
  border-left: none;
}

.view-switch button[aria-pressed="true"] {
  background: var(--matched);
  border-color: var(--matched);
  color: var(--bg);
}

.notice {
  margin: 0 0 0.75rem;
  padding: 0.4rem 0.6rem;
  border-left: 3px solid var(--update);
  background: var(--panel-bg);
  color: var(--muted);
}

/* The tree legend names foreground dot colors, the code legend background swatches - the same four
 * operations, but a reader comparing them side by side would be comparing two different palettes,
 * so each view shows only its own. */
body[data-view="tree"] .code-legend,
body[data-view="code"] .legend:not(.code-legend) {
  display: none;
}

.cd-inserted-swatch {
  display: inline-block;
  width: 1.2em;
  height: 0.85em;
  cursor: default;
}

/* ---------------------------------------------------------------- code renderings
 *
 * A fixture page stacks every account of the same edit as code - the node mapping projected to
 * text, plus one panel per human painting - and viewer.js shows one at a time. They are stacked
 * rather than laid out side by side on purpose: the two are compared by flipping between them
 * with the rows in identical positions, which is also why generate_mapping_site.rs folds every
 * rendering on the same row set. */
.code-panels.hidden {
  display: none;
}

.painting-switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.painting-switch-label {
  color: var(--muted);
}

/* Same segmented-control treatment as the view switch, so the two read as the same kind of
 * control - one chooses which half of the page you see, the other which answer it shows. */
.painting-switch button {
  font: inherit;
  padding: 0.15rem 0.6rem;
  background: var(--button-bg);
  color: var(--fg);
  border: 1px solid var(--button-border);
  cursor: pointer;
}

.painting-switch button:first-of-type {
  border-radius: 4px 0 0 4px;
}

.painting-switch button:last-of-type {
  border-radius: 0 4px 4px 0;
}

.painting-switch button + button {
  border-left: none;
}

.painting-switch button[aria-pressed="true"] {
  background: var(--matched);
  border-color: var(--matched);
  color: var(--bg);
}

/* The switch belongs to the code view, so it goes wherever the code panels go. */
body[data-view="tree"] .painting-switch,
body[data-view="tree"] .painting-notice {
  display: none;
}

.fixture-table td.paintings {
  color: var(--muted);
}

/* ---------------------------------------------------------------- provenance and notes
 *
 * What a fixture is (its description.md) and where it came from (the upstream commit it was
 * sampled from) - both previously visible only in src/test/data/diffs.csv. */
.description {
  margin: 0 0 0.75rem;
  padding: 0.4rem 0.6rem;
  border-left: 3px solid var(--matched);
  background: var(--panel-bg);
  white-space: pre-wrap;
}

.source-path {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
}

/* Second line of the fixture-name cell, not a column: free prose has no fixed width, and it should
 * read as a subtitle of the name above it rather than compete with the counts beside it. */
.fixture-note {
  color: var(--muted);
  font-size: 0.9em;
  margin-top: 0.15rem;
  max-width: 60ch;
}