authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 01:50:46-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 01:50:46-07:00
logd524eb96936090bd2b8a96449784155ad4af9591
tree2b9c74f3cbdacd775df3f03c639aa9ed5f614b28
parent80f775a42c448290c102e572fc889e4e4a1dd546
signature Signed by PGP key B5690EEEBB952194

refactor(mobile): remove obsolete native diff token stream (#10062)


2 files changed, 1 insertions(+), 106 deletions(-)

apps/mobile/src/features/diffs/nativeReviewDiffHighlighter.test.ts+1-22
......@@ -2,11 +2,7 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
22
33import type { NativeReviewDiffRow } from "./nativeReviewDiffSurface";
44import type { NativeReviewDiffFile } from "./nativeReviewDiffTypes";
5import {
6 highlightNativeReviewDiffVisibleRows,
7 streamNativeReviewDiffTokens,
8 type NativeReviewDiffTokenChunk,
9} from "./nativeReviewDiffHighlighter";
5import { highlightNativeReviewDiffVisibleRows } from "./nativeReviewDiffHighlighter";
106
117const tokenization = vi.hoisted(() => ({
128 calls: [] as string[],
......@@ -340,21 +336,4 @@ describe.each(["native", "javascript"] as const)("%s highlighting budgets", (eng
340336 expect(result.rowCount).toBe(0);
341337 expect(result.tokensByRowId).toEqual({});
342338 });
343
344 it("applies the same long-line guard to streamed token chunks", async () => {
345 const content = "x".repeat(10_000);
346 const chunks: NativeReviewDiffTokenChunk[] = [];
347
348 await streamNativeReviewDiffTokens({
349 rows: [line(1, content)],
350 files: [TYPESCRIPT_FILE],
351 scheme: "dark",
352 engine,
353 onChunk: (chunk) => chunks.push(chunk),
354 });
355
356 expect(chunks).toHaveLength(1);
357 expect(chunks[0]?.tokensByRowId["line-1"]).toEqual([{ content, color: null, fontStyle: null }]);
358 expect(tokenization.calls).toHaveLength(0);
359 });
360339});
apps/mobile/src/features/diffs/nativeReviewDiffHighlighter.ts-84
......@@ -65,26 +65,6 @@ interface IndexedNativeReviewDiffLineRow {
6565 readonly rowIndex: number;
6666}
6767
68export interface NativeReviewDiffTokenChunk {
69 readonly chunkIndex: number;
70 readonly fileId: string;
71 readonly filePath: string;
72 readonly language: NativeReviewDiffLanguage;
73 readonly lineCount: number;
74 readonly durationMs: number;
75 readonly tokensByRowId: Record<string, ReadonlyArray<NativeReviewDiffToken>>;
76}
77
78export interface StreamNativeReviewDiffTokenInput {
79 readonly rows: ReadonlyArray<NativeReviewDiffRow>;
80 readonly files: ReadonlyArray<NativeReviewDiffFile>;
81 readonly scheme: NativeReviewDiffHighlightScheme;
82 readonly engine?: NativeReviewDiffHighlightEngine;
83 readonly chunkSize?: number;
84 readonly signal?: AbortSignal;
85 readonly onChunk: (chunk: NativeReviewDiffTokenChunk) => void;
86}
87
8868export interface HighlightNativeReviewDiffVisibleRowsInput {
8969 readonly rows: ReadonlyArray<NativeReviewDiffRow>;
9070 readonly files: ReadonlyArray<NativeReviewDiffFile>;
......@@ -98,7 +78,6 @@ export interface HighlightNativeReviewDiffVisibleRowsInput {
9878 readonly signal?: AbortSignal;
9979}
10080
101const NATIVE_REVIEW_DIFF_HIGHLIGHT_CHUNK_SIZE = 500;
10281const NATIVE_REVIEW_DIFF_VISIBLE_OVERSCAN_ROWS = 160;
10382const NATIVE_REVIEW_DIFF_VISIBLE_MAX_ROWS = 360;
10483const NATIVE_REVIEW_DIFF_TOKENIZE_MAX_LINE_LENGTH = 1_000;
......@@ -423,20 +402,6 @@ function canShareGrammarContext(
423402 );
424403}
425404
426function groupLineRowsByFileId(rows: ReadonlyArray<NativeReviewDiffRow>) {
427 const rowsByFileId = new Map<string, NativeReviewDiffLineRow[]>();
428 for (const row of rows) {
429 if (!isHighlightableLineRow(row)) {
430 continue;
431 }
432
433 const fileRows = rowsByFileId.get(row.fileId) ?? [];
434 fileRows.push(row);
435 rowsByFileId.set(row.fileId, fileRows);
436 }
437 return rowsByFileId;
438}
439
440405function createFileMap(files: ReadonlyArray<NativeReviewDiffFile>) {
441406 return new Map(files.map((file) => [file.id, file]));
442407}
......@@ -561,52 +526,3 @@ export async function highlightNativeReviewDiffVisibleRows(
561526 durationMs: Math.round(performance.now() - startedAt),
562527 };
563528}
564
565export async function streamNativeReviewDiffTokens(
566 input: StreamNativeReviewDiffTokenInput,
567): Promise<NativeReviewDiffHighlightEngine> {
568 const highlighter = await getNativeReviewDiffHighlighter(input.engine ?? "native");
569 const rowsByFileId = groupLineRowsByFileId(input.rows);
570 const theme = NATIVE_REVIEW_DIFF_THEME_NAME_BY_SCHEME[input.scheme];
571 const chunkSize = input.chunkSize ?? NATIVE_REVIEW_DIFF_HIGHLIGHT_CHUNK_SIZE;
572 let chunkIndex = 0;
573
574 for (const file of input.files) {
575 const fileRows = rowsByFileId.get(file.id) ?? [];
576 for (let startIndex = 0; startIndex < fileRows.length; startIndex += chunkSize) {
577 if (input.signal?.aborted) {
578 return highlighter.engine;
579 }
580
581 const startedAt = performance.now();
582 const chunkRows = fileRows.slice(startIndex, startIndex + chunkSize);
583 const code = chunkRows.map((row) => row.content).join("\n");
584 const tokenLines = await highlighter.tokenize(code, {
585 lang: file.language,
586 theme,
587 signal: input.signal,
588 });
589 if (input.signal?.aborted) return highlighter.engine;
590 const tokensByRowId: Record<string, ReadonlyArray<NativeReviewDiffToken>> = {};
591
592 chunkRows.forEach((row, rowIndex) => {
593 tokensByRowId[row.id] = tokenLines[rowIndex] ?? makePlainTokenFallback(row);
594 });
595
596 input.onChunk({
597 chunkIndex,
598 fileId: file.id,
599 filePath: file.path,
600 language: file.language,
601 lineCount: chunkRows.length,
602 durationMs: Math.round(performance.now() - startedAt),
603 tokensByRowId,
604 });
605
606 chunkIndex += 1;
607 await waitForNextFrame();
608 }
609 }
610
611 return highlighter.engine;
612}