TypeScript
refactor(mobile): remove obsolete native diff token stream (#10062)
Julius Marminged524eb969360
diff --git a/apps/mobile/src/features/diffs/nativeReviewDiffHighlighter.test.ts b/apps/mobile/src/features/diffs/nativeReviewDiffHighlighter.test.tsindex e7e75a4faa1..24b18edd5db 100644--- a/apps/mobile/src/features/diffs/nativeReviewDiffHighlighter.test.ts+++ b/apps/mobile/src/features/diffs/nativeReviewDiffHighlighter.test.ts@@ -2,11 +2,7 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test";import type { NativeReviewDiffRow } from "./nativeReviewDiffSurface";import type { NativeReviewDiffFile } from "./nativeReviewDiffTypes";-import {- highlightNativeReviewDiffVisibleRows,- streamNativeReviewDiffTokens,- type NativeReviewDiffTokenChunk,-} from "./nativeReviewDiffHighlighter";+import { highlightNativeReviewDiffVisibleRows } from "./nativeReviewDiffHighlighter";const tokenization = vi.hoisted(() => ({calls: [] as string[],@@ -340,21 +336,4 @@ describe.each(["native", "javascript"] as const)("%s highlighting budgets", (engexpect(result.rowCount).toBe(0);expect(result.tokensByRowId).toEqual({});});-- it("applies the same long-line guard to streamed token chunks", async () => {- const content = "x".repeat(10_000);- const chunks: NativeReviewDiffTokenChunk[] = [];-- await streamNativeReviewDiffTokens({- rows: [line(1, content)],- files: [TYPESCRIPT_FILE],- scheme: "dark",- engine,- onChunk: (chunk) => chunks.push(chunk),- });-- expect(chunks).toHaveLength(1);- expect(chunks[0]?.tokensByRowId["line-1"]).toEqual([{ content, color: null, fontStyle: null }]);- expect(tokenization.calls).toHaveLength(0);- });});diff --git a/apps/mobile/src/features/diffs/nativeReviewDiffHighlighter.ts b/apps/mobile/src/features/diffs/nativeReviewDiffHighlighter.tsindex 0ea8c100dc1..e924ff1aa64 100644--- a/apps/mobile/src/features/diffs/nativeReviewDiffHighlighter.ts+++ b/apps/mobile/src/features/diffs/nativeReviewDiffHighlighter.ts@@ -65,26 +65,6 @@ interface IndexedNativeReviewDiffLineRow {readonly rowIndex: number;}-export interface NativeReviewDiffTokenChunk {- readonly chunkIndex: number;- readonly fileId: string;- readonly filePath: string;- readonly language: NativeReviewDiffLanguage;- readonly lineCount: number;- readonly durationMs: number;- readonly tokensByRowId: Record<string, ReadonlyArray<NativeReviewDiffToken>>;-}--export interface StreamNativeReviewDiffTokenInput {- readonly rows: ReadonlyArray<NativeReviewDiffRow>;- readonly files: ReadonlyArray<NativeReviewDiffFile>;- readonly scheme: NativeReviewDiffHighlightScheme;- readonly engine?: NativeReviewDiffHighlightEngine;- readonly chunkSize?: number;- readonly signal?: AbortSignal;- readonly onChunk: (chunk: NativeReviewDiffTokenChunk) => void;-}-export interface HighlightNativeReviewDiffVisibleRowsInput {readonly rows: ReadonlyArray<NativeReviewDiffRow>;readonly files: ReadonlyArray<NativeReviewDiffFile>;@@ -98,7 +78,6 @@ export interface HighlightNativeReviewDiffVisibleRowsInput {readonly signal?: AbortSignal;}-const NATIVE_REVIEW_DIFF_HIGHLIGHT_CHUNK_SIZE = 500;const NATIVE_REVIEW_DIFF_VISIBLE_OVERSCAN_ROWS = 160;const NATIVE_REVIEW_DIFF_VISIBLE_MAX_ROWS = 360;const NATIVE_REVIEW_DIFF_TOKENIZE_MAX_LINE_LENGTH = 1_000;@@ -423,20 +402,6 @@ function canShareGrammarContext();}-function groupLineRowsByFileId(rows: ReadonlyArray<NativeReviewDiffRow>) {- const rowsByFileId = new Map<string, NativeReviewDiffLineRow[]>();- for (const row of rows) {- if (!isHighlightableLineRow(row)) {- continue;- }-- const fileRows = rowsByFileId.get(row.fileId) ?? [];- fileRows.push(row);- rowsByFileId.set(row.fileId, fileRows);- }- return rowsByFileId;-}-function createFileMap(files: ReadonlyArray<NativeReviewDiffFile>) {return new Map(files.map((file) => [file.id, file]));}@@ -561,52 +526,3 @@ export async function highlightNativeReviewDiffVisibleRows(durationMs: Math.round(performance.now() - startedAt),};}--export async function streamNativeReviewDiffTokens(- input: StreamNativeReviewDiffTokenInput,-): Promise<NativeReviewDiffHighlightEngine> {- const highlighter = await getNativeReviewDiffHighlighter(input.engine ?? "native");- const rowsByFileId = groupLineRowsByFileId(input.rows);- const theme = NATIVE_REVIEW_DIFF_THEME_NAME_BY_SCHEME[input.scheme];- const chunkSize = input.chunkSize ?? NATIVE_REVIEW_DIFF_HIGHLIGHT_CHUNK_SIZE;- let chunkIndex = 0;-- for (const file of input.files) {- const fileRows = rowsByFileId.get(file.id) ?? [];- for (let startIndex = 0; startIndex < fileRows.length; startIndex += chunkSize) {- if (input.signal?.aborted) {- return highlighter.engine;- }-- const startedAt = performance.now();- const chunkRows = fileRows.slice(startIndex, startIndex + chunkSize);- const code = chunkRows.map((row) => row.content).join("\n");- const tokenLines = await highlighter.tokenize(code, {- lang: file.language,- theme,- signal: input.signal,- });- if (input.signal?.aborted) return highlighter.engine;- const tokensByRowId: Record<string, ReadonlyArray<NativeReviewDiffToken>> = {};-- chunkRows.forEach((row, rowIndex) => {- tokensByRowId[row.id] = tokenLines[rowIndex] ?? makePlainTokenFallback(row);- });-- input.onChunk({- chunkIndex,- fileId: file.id,- filePath: file.path,- language: file.language,- lineCount: chunkRows.length,- durationMs: Math.round(performance.now() - startedAt),- tokensByRowId,- });-- chunkIndex += 1;- await waitForNextFrame();- }- }-- return highlighter.engine;-}