The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { FileDiffContentsLoader, FileDiffMetadata } from "@pierre/diffs"; |
| 2 | import { |
| 3 | excerptExpansionOldContents, |
| 4 | type DiffRow, |
| 5 | } from "@t3tools/client-runtime/review-guide-tour"; |
| 6 | import type { PullRequestReviewGuideExcerpt } from "@t3tools/contracts"; |
| 7 | |
| 8 | // Other hunks shift old-side context; expand against an excerpt-matching old side. |
| 9 | // Loads with the source file's diff, which the loaded contents must reproduce. |
| 10 | export function excerptLoader( |
| 11 | excerpt: PullRequestReviewGuideExcerpt, |
| 12 | file: FileDiffMetadata, |
| 13 | sliceRows: ReadonlyArray<DiffRow>, |
| 14 | loadDiffFiles: FileDiffContentsLoader, |
| 15 | ): FileDiffContentsLoader | null { |
| 16 | // An added or deleted file has no unchanged context to expand. |
| 17 | if ( |
| 18 | file.type === "new" || |
| 19 | file.type === "deleted" || |
| 20 | sliceRows.some((row) => row.hunk !== sliceRows[0]?.hunk) |
| 21 | ) { |
| 22 | return null; |
| 23 | } |
| 24 | return async () => { |
| 25 | const loaded = await loadDiffFiles(file); |
| 26 | const oldContents = excerptExpansionOldContents(loaded.newFile.contents, sliceRows); |
| 27 | if (oldContents === null) return loaded; |
| 28 | return { |
| 29 | newFile: loaded.newFile, |
| 30 | oldFile: { |
| 31 | name: loaded.oldFile?.name ?? loaded.newFile.name, |
| 32 | contents: oldContents, |
| 33 | cacheKey: `${loaded.newFile.cacheKey ?? loaded.newFile.name}:excerpt:${excerpt.side}:${excerpt.start}-${excerpt.end}`, |
| 34 | }, |
| 35 | }; |
| 36 | }; |
| 37 | } |