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