| ... | @@ -65,26 +65,6 @@ interface IndexedNativeReviewDiffLineRow { | ... | @@ -65,26 +65,6 @@ interface IndexedNativeReviewDiffLineRow { |
| 65 | readonly rowIndex: number; | 65 | readonly rowIndex: number; |
| 66 | } | 66 | } |
| 67 | | 67 | |
| 68 | export 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 | | | |
| 78 | export 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 | | | |
| 88 | export interface HighlightNativeReviewDiffVisibleRowsInput { | 68 | export interface HighlightNativeReviewDiffVisibleRowsInput { |
| 89 | readonly rows: ReadonlyArray<NativeReviewDiffRow>; | 69 | readonly rows: ReadonlyArray<NativeReviewDiffRow>; |
| 90 | readonly files: ReadonlyArray<NativeReviewDiffFile>; | 70 | readonly files: ReadonlyArray<NativeReviewDiffFile>; |
| ... | @@ -98,7 +78,6 @@ export interface HighlightNativeReviewDiffVisibleRowsInput { | ... | @@ -98,7 +78,6 @@ export interface HighlightNativeReviewDiffVisibleRowsInput { |
| 98 | readonly signal?: AbortSignal; | 78 | readonly signal?: AbortSignal; |
| 99 | } | 79 | } |
| 100 | | 80 | |
| 101 | const NATIVE_REVIEW_DIFF_HIGHLIGHT_CHUNK_SIZE = 500; | | |
| 102 | const NATIVE_REVIEW_DIFF_VISIBLE_OVERSCAN_ROWS = 160; | 81 | const NATIVE_REVIEW_DIFF_VISIBLE_OVERSCAN_ROWS = 160; |
| 103 | const NATIVE_REVIEW_DIFF_VISIBLE_MAX_ROWS = 360; | 82 | const NATIVE_REVIEW_DIFF_VISIBLE_MAX_ROWS = 360; |
| 104 | const NATIVE_REVIEW_DIFF_TOKENIZE_MAX_LINE_LENGTH = 1_000; | 83 | const NATIVE_REVIEW_DIFF_TOKENIZE_MAX_LINE_LENGTH = 1_000; |
| ... | @@ -423,20 +402,6 @@ function canShareGrammarContext( | ... | @@ -423,20 +402,6 @@ function canShareGrammarContext( |
| 423 | ); | 402 | ); |
| 424 | } | 403 | } |
| 425 | | 404 | |
| 426 | function 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 | | | |
| 440 | function createFileMap(files: ReadonlyArray<NativeReviewDiffFile>) { | 405 | function createFileMap(files: ReadonlyArray<NativeReviewDiffFile>) { |
| 441 | return new Map(files.map((file) => [file.id, file])); | 406 | return new Map(files.map((file) => [file.id, file])); |
| 442 | } | 407 | } |
| ... | @@ -561,52 +526,3 @@ export async function highlightNativeReviewDiffVisibleRows( | ... | @@ -561,52 +526,3 @@ export async function highlightNativeReviewDiffVisibleRows( |
| 561 | durationMs: Math.round(performance.now() - startedAt), | 526 | durationMs: Math.round(performance.now() - startedAt), |
| 562 | }; | 527 | }; |
| 563 | } | 528 | } |
| 564 | | | |
| 565 | export 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 | } | | |