Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

nativeReviewDiffAdapter.ts

628 lines20.3 KB

1import type { NativeReviewDiffRow, NativeReviewDiffTheme } from "../diffs/nativeReviewDiffSurface";
2import type {
3 NativeReviewDiffFile,
4 NativeReviewDiffLanguage,
5} from "../diffs/nativeReviewDiffTypes";
6import * as Arr from "effect/Array";
7import { pipe } from "effect/Function";
8import type { ResolvedMobileCodeSurface } from "../../lib/appearancePreferences";
9import { type MobileThemeId, type MobileThemeVariables } from "../../lib/mobileTheme";
10import { getMobileTerminalTheme, type TerminalAppearanceScheme } from "../terminal/terminalTheme";
11import { computeWordAltDiffRanges } from "./reviewWordDiffs";
12import {
13 getReviewFilePreviewState,
14 type ReviewParsedDiff,
15 type ReviewRenderableFile,
16 type ReviewRenderableLineRow,
17} from "./reviewModel";
18import type { ReviewInlineComment } from "./reviewCommentSelection";
19​
20const NATIVE_REVIEW_MAX_WORD_DIFF_RANGE_COUNT = 4;
21const NATIVE_REVIEW_MAX_WORD_DIFF_COVERAGE = 0.45;
22// Bound the rows serialized to the native heap before mapping and word matching.
23const NATIVE_REVIEW_MAX_FILE_ROWS = 2_000;
24const TRUNCATED_FILE_NOTICE = "This diff is too large to show in full.";
25const NATIVE_HEX_COLOR = /^#([\da-f]{2})([\da-f]{2})([\da-f]{2})([\da-f]{2})?$/i;
26const NATIVE_RGBA_COLOR =
27 /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)$/;
28​
29export const NATIVE_REVIEW_DIFF_CONTENT_WIDTH = 2_800;
30​
31export function buildNativeReviewSnippetRows(
32 comment: Pick<ReviewInlineComment, "id" | "diff" | "fenceLanguage">,
33): NativeReviewDiffRow[] {
34 if ((comment.fenceLanguage ?? "diff") !== "diff" || !comment.diff.trim()) return [];
35 const lines = comment.diff.replace(/\r\n/g, "\n").replace(/\n$/, "").split("\n");
36 if (lines.some((line) => !/^[ +-]/.test(line) || /^(---|\+\+\+) /.test(line))) return [];
37 return lines.map((line, index) => ({
38 kind: "line",
39 id: `${comment.id}:snippet:${index}`,
40 content: line.slice(1),
41 change: line[0] === "+" ? "add" : line[0] === "-" ? "delete" : "context",
42 oldLineNumber: null,
43 newLineNumber: null,
44 }));
46​
47function opaqueNativeHexColor(color: string, background: string): string {
48 const hex = NATIVE_HEX_COLOR.exec(color);
49 if (hex && !hex[4]) return color;
50​
51 const rgba = NATIVE_RGBA_COLOR.exec(color);
52 const backgroundHex = NATIVE_HEX_COLOR.exec(background);
53 if ((!hex && !rgba) || !backgroundHex) return background;
54​
55 const alpha = hex
56 ? Number.parseInt(hex[4] ?? "ff", 16) / 255
57 : rgba?.[4] === undefined
58 ? 1
59 : Math.min(1, Math.max(0, Number(rgba[4])));
60 const channels = [1, 2, 3].map((index) => {
61 const foreground = hex ? Number.parseInt(hex[index] ?? "0", 16) : Number(rgba?.[index]);
62 const behind = Number.parseInt(backgroundHex[index] ?? "0", 16);
63 return Math.round(foreground * alpha + behind * (1 - alpha));
64 });
65 return `#${channels.map((channel) => channel.toString(16).padStart(2, "0")).join("")}`;
67​
68export function createNativeReviewDiffStyle(
69 codeSurface: ResolvedMobileCodeSurface,
70 wordWrap: boolean,
71) {
72 return {
73 wordWrap,
74 rowHeight: codeSurface.rowHeight,
75 contentWidth: NATIVE_REVIEW_DIFF_CONTENT_WIDTH,
76 changeBarWidth: 4,
77 gutterWidth: codeSurface.gutterWidth,
78 codePadding: codeSurface.codePadding,
79 textVerticalInset: codeSurface.textVerticalInset,
80 fileHeaderHeight: 56,
81 fileHeaderHorizontalMargin: 8,
82 fileHeaderVerticalMargin: 6,
83 fileHeaderCornerRadius: 10,
84 fileHeaderHorizontalPadding: 10,
85 fileHeaderPathRightPadding: 118,
86 fileHeaderCountColumnWidth: 38,
87 fileHeaderCountGap: 5,
88 codeFontSize: codeSurface.fontSize,
89 codeFontWeight: "regular",
90 lineNumberFontSize: codeSurface.lineNumberFontSize,
91 lineNumberFontWeight: "regular",
92 hunkFontSize: 11,
93 hunkFontWeight: "medium",
94 fileHeaderFontSize: 11,
95 fileHeaderFontWeight: "semibold",
96 fileHeaderMetaFontSize: 10,
97 fileHeaderMetaFontWeight: "semibold",
98 fileHeaderSubtextFontSize: 11,
99 fileHeaderSubtextFontWeight: "medium",
100 fileHeaderStatusFontSize: 9,
101 fileHeaderStatusFontWeight: "bold",
102 emptyStateFontSize: 12,
103 emptyStateFontWeight: "medium",
104 } as const;
106​
107export interface NativeReviewDiffData {
108 readonly rows: ReadonlyArray<NativeReviewDiffRow>;
109 readonly files: ReadonlyArray<NativeReviewDiffFile>;
110 readonly commentTargetsByRowId: ReadonlyMap<string, NativeReviewDiffCommentTarget>;
111 readonly rowIdByCommentLineId: ReadonlyMap<string, string>;
112 readonly additions: number;
113 readonly deletions: number;
115​
116export interface NativeReviewDiffCommentTarget {
117 readonly filePath: string;
118 readonly lines: ReadonlyArray<ReviewRenderableLineRow>;
119 readonly lineIndex: number;
121​
122export interface BuildNativeReviewDiffDataInput {
123 readonly parsedDiff: ReviewParsedDiff;
124 readonly comments?: ReadonlyArray<ReviewInlineComment>;
126​
127interface CachedNativeReviewDiffData {
128 readonly prepared: PreparedNativeReviewDiffData;
129 readonly commentsKey: string;
130 readonly data: NativeReviewDiffData;
132​
133interface PreparedNativeReviewFileRows {
134 readonly fileId: string;
135 readonly filePath: string;
136 readonly lineCount: number;
137 readonly truncated: boolean;
138 readonly rows: ReadonlyArray<NativeReviewDiffRow>;
139 readonly commentTargetsByRowId: ReadonlyMap<string, NativeReviewDiffCommentTarget>;
140 readonly rowIdByCommentLineId: ReadonlyMap<string, string>;
141 commentedRows: {
142 readonly commentsKey: string;
143 readonly rows: ReadonlyArray<NativeReviewDiffRow>;
144 } | null;
146​
147interface PreparedNativeReviewDiffData extends Omit<NativeReviewDiffData, "rows"> {
148 readonly fileRows: ReadonlyArray<PreparedNativeReviewFileRows>;
150​
151const nativeReviewDiffDataCache = new WeakMap<ReviewParsedDiff, CachedNativeReviewDiffData>();
152const nativeReviewFileRowsCache = new WeakMap<ReviewRenderableFile, PreparedNativeReviewFileRows>();
153​
154function buildReviewCommentsCacheKey(comments: ReadonlyArray<ReviewInlineComment>): string {
155 if (comments.length === 0) {
156 return "none";
157 }
158​
159 return JSON.stringify(
160 comments.map((comment) => [
161 comment.id,
162 comment.sectionId,
163 comment.sectionTitle,
164 comment.filePath,
165 comment.startIndex,
166 comment.endIndex,
167 comment.rangeLabel,
168 comment.text,
169 ]),
170 );
172​
173export function createNativeReviewDiffTheme(
174 scheme: TerminalAppearanceScheme,
175 themeId: MobileThemeId,
176 appTheme: MobileThemeVariables,
177): NativeReviewDiffTheme {
178 const terminalTheme = getMobileTerminalTheme(themeId, scheme);
179 const [, terminalRed] = terminalTheme.palette;
180 // Swift expects #RRGGBB/#RRGGBBAA while Android expects #RRGGBB/#AARRGGBB.
181 // Flatten translucent app tokens onto the code surface so both native
182 // implementations receive the one unambiguous shared format.
183 const screen = opaqueNativeHexColor(
184 appTheme["--color-screen"],
185 scheme === "dark" ? "#000000" : "#ffffff",
186 );
187 const background = opaqueNativeHexColor(appTheme["--color-md-code-bg"], screen);
188 const nativeColor = (color: string) => opaqueNativeHexColor(color, background);
189​
190 if (scheme === "dark") {
191 return {
192 background,
193 text: nativeColor(appTheme["--color-md-code-text"]),
194 mutedText: nativeColor(appTheme["--color-foreground-muted"]),
195 headerBackground: background,
196 border: nativeColor(appTheme["--color-border"]),
197 hunkBackground: nativeColor(appTheme["--color-subtle-strong"]),
198 hunkText: nativeColor(appTheme["--color-foreground"]),
199 addBackground: "#0d2f28",
200 deleteBackground: "#391415",
201 addBar: "#00cab1",
202 deleteBar: terminalRed ?? "#ff2e3f",
203 addText: "#5ECC71",
204 deleteText: "#FF6762",
205 };
206 }
207​
208 return {
209 background,
210 text: nativeColor(appTheme["--color-md-code-text"]),
211 mutedText: nativeColor(appTheme["--color-foreground-muted"]),
212 headerBackground: background,
213 border: nativeColor(appTheme["--color-border"]),
214 hunkBackground: nativeColor(appTheme["--color-subtle-strong"]),
215 hunkText: nativeColor(appTheme["--color-foreground"]),
216 addBackground: "#e5f8f5",
217 deleteBackground: "#ffe6e7",
218 addBar: "#00cab1",
219 deleteBar: terminalRed ?? "#ff2e3f",
220 addText: "#199F43",
221 deleteText: "#D52C36",
222 };
224​
225function mapChangeType(file: ReviewRenderableFile): NativeReviewDiffRow["changeType"] {
226 switch (file.changeType) {
227 case "change":
228 return "modified";
229 case "new":
230 case "deleted":
231 case "rename-pure":
232 case "rename-changed":
233 return file.changeType;
234 default:
235 return "modified";
236 }
238​
239function getLanguageForPath(
240 filePath: string,
241 languageHint: string | null,
242): NativeReviewDiffLanguage {
243 const hinted = languageHint?.toLowerCase();
244 if (hinted === "typescript" || hinted === "tsx" || hinted === "javascript" || hinted === "jsx") {
245 return hinted;
246 }
247 if (hinted === "json" || hinted === "yaml" || hinted === "bash" || hinted === "diff") {
248 return hinted;
249 }
250​
251 const normalizedPath = filePath.toLowerCase();
252 if (normalizedPath.endsWith(".tsx")) return "tsx";
253 if (normalizedPath.endsWith(".ts")) return "typescript";
254 if (normalizedPath.endsWith(".jsx")) return "jsx";
255 if (normalizedPath.endsWith(".js") || normalizedPath.endsWith(".cjs")) return "javascript";
256 if (normalizedPath.endsWith(".json") || normalizedPath.endsWith(".jsonc")) return "json";
257 if (normalizedPath.endsWith(".yml") || normalizedPath.endsWith(".yaml")) return "yaml";
258 if (
259 normalizedPath.endsWith(".sh") ||
260 normalizedPath.includes("/bin/") ||
261 normalizedPath.includes("shell")
262 ) {
263 return "bash";
264 }
265 return "diff";
267​
268function createNoticeRow(fileId: string, suffix: string, text: string): NativeReviewDiffRow {
269 return {
270 kind: "notice",
271 id: `${fileId}:notice:${suffix}`,
272 fileId,
273 text,
274 };
276​
277function noticeRowsForFile(file: ReviewRenderableFile): ReadonlyArray<NativeReviewDiffRow> {
278 if (file.notice) return [createNoticeRow(file.id, "loading", file.notice)];
279 if (file.rows.length > 0) {
280 return [];
281 }
282​
283 const previewState = getReviewFilePreviewState(file);
284 if (previewState.kind === "suppressed" && previewState.reason === "non-text") {
285 return [
286 createNoticeRow(file.id, "non-text", "Unsupported format. Diff contents are not available."),
287 ];
288 }
289​
290 if (file.changeType === "rename-pure") {
291 return [createNoticeRow(file.id, "rename", "This file was renamed without modifications.")];
292 }
293​
294 return [];
296​
297function trimWordDiffRanges(
298 content: string,
299 ranges: NonNullable<NativeReviewDiffRow["wordDiffRanges"]>,
300): NonNullable<NativeReviewDiffRow["wordDiffRanges"]> {
301 return pipe(
302 ranges,
303 Arr.flatMap((range) => {
304 let start = Math.max(0, range.start);
305 let end = Math.min(content.length, range.end);
306​
307 while (start < end && /\s/.test(content[start] ?? "")) {
308 start += 1;
309 }
310 while (end > start && /\s/.test(content[end - 1] ?? "")) {
311 end -= 1;
312 }
313​
314 return end > start ? [{ start, end }] : [];
315 }),
316 );
318​
319function nonWhitespaceLength(value: string) {
320 return value.replace(/\s/g, "").length;
322​
323function shouldUseWordDiffRanges(
324 content: string,
325 ranges: NonNullable<NativeReviewDiffRow["wordDiffRanges"]>,
326) {
327 if (ranges.length === 0 || ranges.length > NATIVE_REVIEW_MAX_WORD_DIFF_RANGE_COUNT) {
328 return false;
329 }
330​
331 const meaningfulLength = nonWhitespaceLength(content);
332 if (meaningfulLength === 0) {
333 return false;
334 }
335​
336 const highlightedLength = ranges.reduce(
337 (total, range) => total + nonWhitespaceLength(content.slice(range.start, range.end)),
338 0,
339 );
340 return highlightedLength / meaningfulLength <= NATIVE_REVIEW_MAX_WORD_DIFF_COVERAGE;
342​
343function addNativeWordDiffRanges(
344 rows: ReadonlyArray<NativeReviewDiffRow>,
345): ReadonlyArray<NativeReviewDiffRow> {
346 const nextRows = [...rows];
347 let index = 0;
348​
349 while (index < nextRows.length) {
350 const deletedRowIndexes: number[] = [];
351 const addedRowIndexes: number[] = [];
352 const fileId = nextRows[index]?.fileId;
353​
354 while (
355 nextRows[index]?.kind === "line" &&
356 nextRows[index]?.change === "delete" &&
357 nextRows[index]?.fileId === fileId
358 ) {
359 deletedRowIndexes.push(index);
360 index += 1;
361 }
362​
363 while (
364 nextRows[index]?.kind === "line" &&
365 nextRows[index]?.change === "add" &&
366 nextRows[index]?.fileId === fileId
367 ) {
368 addedRowIndexes.push(index);
369 index += 1;
370 }
371​
372 const pairedCount = Math.min(deletedRowIndexes.length, addedRowIndexes.length);
373 for (let pairIndex = 0; pairIndex < pairedCount; pairIndex += 1) {
374 const deletedRowIndex = deletedRowIndexes[pairIndex];
375 const addedRowIndex = addedRowIndexes[pairIndex];
376 if (deletedRowIndex === undefined || addedRowIndex === undefined) {
377 continue;
378 }
379 const deletedRow = nextRows[deletedRowIndex];
380 const addedRow = nextRows[addedRowIndex];
381 if (!deletedRow?.content || !addedRow?.content) {
382 continue;
383 }
384​
385 const ranges = computeWordAltDiffRanges({
386 deletionLine: deletedRow.content,
387 additionLine: addedRow.content,
388 });
389 const deletionRanges = trimWordDiffRanges(deletedRow.content, ranges.deletion);
390 const additionRanges = trimWordDiffRanges(addedRow.content, ranges.addition);
391​
392 if (shouldUseWordDiffRanges(deletedRow.content, deletionRanges)) {
393 nextRows[deletedRowIndex] = { ...deletedRow, wordDiffRanges: deletionRanges };
394 }
395 if (shouldUseWordDiffRanges(addedRow.content, additionRanges)) {
396 nextRows[addedRowIndex] = { ...addedRow, wordDiffRanges: additionRanges };
397 }
398 }
399​
400 if (deletedRowIndexes.length === 0 && addedRowIndexes.length === 0) {
401 index += 1;
402 }
403 }
404​
405 return nextRows;
407​
408function mapLineRow(
409 file: ReviewRenderableFile,
410 row: ReviewRenderableLineRow,
411 rowIndex: number,
412): NativeReviewDiffRow {
413 return {
414 kind: "line",
415 id: `${file.id}:line:${rowIndex}:${row.id}`,
416 fileId: file.id,
417 content: row.content,
418 change: row.change,
419 oldLineNumber: row.oldLineNumber,
420 newLineNumber: row.newLineNumber,
421 };
423​
424function prepareFileRows(file: ReviewRenderableFile): PreparedNativeReviewFileRows {
425 const cached = nativeReviewFileRowsCache.get(file);
426 if (cached) return cached;
427 const commentTargetsByRowId = new Map<string, NativeReviewDiffCommentTarget>();
428 const rowIdByCommentLineId = new Map<string, string>();
429 const rows: NativeReviewDiffRow[] = [
430 {
431 kind: "file",
432 id: `${file.id}:header`,
433 fileId: file.id,
434 filePath: file.path,
435 previousPath: file.previousPath,
436 changeType: mapChangeType(file),
437 additions: file.additions,
438 deletions: file.deletions,
439 },
440 ];
441​
442 const sourceRows =
443 file.rows.length > NATIVE_REVIEW_MAX_FILE_ROWS
444 ? file.rows.slice(0, NATIVE_REVIEW_MAX_FILE_ROWS)
445 : file.rows;
446 const lineRows = sourceRows.filter((row): row is ReviewRenderableLineRow => row.kind === "line");
447 let lineIndex = 0;
448 sourceRows.forEach((row, rowIndex) => {
449 if (row.kind === "hunk") {
450 rows.push({
451 kind: "hunk",
452 id: `${file.id}:hunk:${rowIndex}:${row.id}`,
453 fileId: file.id,
454 text: row.context ? `${row.header} ${row.context}` : row.header,
455 });
456 return;
457 }
458​
459 const nativeRow = mapLineRow(file, row, rowIndex);
460 rows.push(nativeRow);
461 rowIdByCommentLineId.set(row.id, nativeRow.id);
462 commentTargetsByRowId.set(nativeRow.id, {
463 filePath: file.path,
464 lines: lineRows,
465 lineIndex,
466 });
467 lineIndex += 1;
468 });
469​
470 if (sourceRows !== file.rows) {
471 rows.push(createNoticeRow(file.id, "truncated", TRUNCATED_FILE_NOTICE));
472 }
473 rows.push(...noticeRowsForFile(file));
474 const prepared: PreparedNativeReviewFileRows = {
475 fileId: file.id,
476 filePath: file.path,
477 lineCount: lineRows.length,
478 truncated: sourceRows !== file.rows,
479 // Comments must not split the source deletion/addition runs used for word matching.
480 rows: addNativeWordDiffRanges(rows),
481 commentTargetsByRowId,
482 rowIdByCommentLineId,
483 commentedRows: null,
484 };
485 nativeReviewFileRowsCache.set(file, prepared);
486 return prepared;
488​
489function insertFileComments(
490 file: PreparedNativeReviewFileRows,
491 comments: ReadonlyArray<ReviewInlineComment>,
492): ReadonlyArray<NativeReviewDiffRow> {
493 if (comments.length === 0) {
494 file.commentedRows = null;
495 return file.rows;
496 }
497 const commentsKey = buildReviewCommentsCacheKey(comments);
498 if (file.commentedRows?.commentsKey === commentsKey) {
499 return file.commentedRows.rows;
500 }
501​
502 const commentsByEndIndex = new Map<number, ReviewInlineComment[]>();
503 for (const comment of comments) {
504 if (file.truncated && comment.startIndex >= file.lineCount) continue;
505 const endIndex = Math.min(comment.endIndex, file.lineCount - 1);
506 if (endIndex < 0) continue;
507 const existing = commentsByEndIndex.get(endIndex);
508 if (existing) {
509 existing.push(comment);
510 } else {
511 commentsByEndIndex.set(endIndex, [comment]);
512 }
513 }
514 const rows: NativeReviewDiffRow[] = [];
515 let lineIndex = 0;
516 for (const row of file.rows) {
517 rows.push(row);
518 if (row.kind !== "line") continue;
519 for (const comment of commentsByEndIndex.get(lineIndex) ?? []) {
520 rows.push({
521 kind: "comment",
522 id: comment.id,
523 fileId: file.fileId,
524 filePath: file.filePath,
525 commentText: comment.text,
526 commentRangeLabel: comment.rangeLabel,
527 commentSectionTitle: comment.sectionTitle,
528 });
529 }
530 lineIndex += 1;
531 }
532 file.commentedRows = { commentsKey, rows };
533 return rows;
535​
536function prepareNativeReviewDiffData(parsedDiff: ReviewParsedDiff): PreparedNativeReviewDiffData {
537 if (parsedDiff.kind !== "files") {
538 return {
539 fileRows: [],
540 files: [],
541 commentTargetsByRowId: new Map(),
542 rowIdByCommentLineId: new Map(),
543 additions: 0,
544 deletions: 0,
545 };
546 }
547​
548 const files = parsedDiff.files.map<NativeReviewDiffFile>((file) => ({
549 id: file.id,
550 path: file.path,
551 language: getLanguageForPath(file.path, file.languageHint),
552 additions: file.additions,
553 deletions: file.deletions,
554 }));
555 const commentTargetsByRowId = new Map<string, NativeReviewDiffCommentTarget>();
556 const rowIdByCommentLineId = new Map<string, string>();
557 const fileRows = parsedDiff.files.map(prepareFileRows);
558 for (const file of fileRows) {
559 for (const [rowId, target] of file.commentTargetsByRowId) {
560 commentTargetsByRowId.set(rowId, target);
561 }
562 for (const [lineId, rowId] of file.rowIdByCommentLineId) {
563 rowIdByCommentLineId.set(lineId, rowId);
564 }
565 }
566​
567 return {
568 fileRows,
569 files,
570 commentTargetsByRowId,
571 rowIdByCommentLineId,
572 additions: parsedDiff.additions,
573 deletions: parsedDiff.deletions,
574 };
576​
577function buildCommentedNativeReviewDiffData(
578 prepared: PreparedNativeReviewDiffData,
579 comments: ReadonlyArray<ReviewInlineComment>,
580): NativeReviewDiffData {
581 const commentsByFilePath = new Map<string, ReviewInlineComment[]>();
582 for (const comment of comments) {
583 const existing = commentsByFilePath.get(comment.filePath);
584 if (existing) {
585 existing.push(comment);
586 } else {
587 commentsByFilePath.set(comment.filePath, [comment]);
588 }
589 }
590 return {
591 rows: Arr.flatMap(prepared.fileRows, (file) =>
592 insertFileComments(file, commentsByFilePath.get(file.filePath) ?? []),
593 ),
594 files: prepared.files,
595 commentTargetsByRowId: prepared.commentTargetsByRowId,
596 rowIdByCommentLineId: prepared.rowIdByCommentLineId,
597 additions: prepared.additions,
598 deletions: prepared.deletions,
599 };
601​
602export function buildNativeReviewDiffData(
603 input: BuildNativeReviewDiffDataInput,
604): NativeReviewDiffData;
605export function buildNativeReviewDiffData(parsedDiff: ReviewParsedDiff): NativeReviewDiffData;
606export function buildNativeReviewDiffData(
607 input: ReviewParsedDiff | BuildNativeReviewDiffDataInput,
608): NativeReviewDiffData {
609 const parsedDiff = "parsedDiff" in input ? input.parsedDiff : input;
610 const comments = "parsedDiff" in input ? (input.comments ?? []) : [];
611 return buildCommentedNativeReviewDiffData(prepareNativeReviewDiffData(parsedDiff), comments);
613​
614export function getCachedNativeReviewDiffData(
615 input: BuildNativeReviewDiffDataInput,
616): NativeReviewDiffData {
617 const comments = input.comments ?? [];
618 const commentsKey = buildReviewCommentsCacheKey(comments);
619 const cached = nativeReviewDiffDataCache.get(input.parsedDiff);
620 if (cached?.commentsKey === commentsKey) {
621 return cached.data;
622 }
623​
624 const prepared = cached?.prepared ?? prepareNativeReviewDiffData(input.parsedDiff);
625 const data = buildCommentedNativeReviewDiffData(prepared, comments);
626 nativeReviewDiffDataCache.set(input.parsedDiff, { prepared, commentsKey, data });
627 return data;