1- import {
2- hydratePartialDiff ,
3- parseDiffFromFile ,
4- parsePatchFiles ,
5- type FileDiffMetadata ,
6- } from "@pierre/diffs" ;
1+ import { processFile , parsePatchFiles } from "@pierre/diffs/utils/parsePatchFiles" ;
2+ import type { FileDiffMetadata } from "@pierre/diffs/types" ;
3+ import { parseReviewDiffFromFiles } from "./reviewDiffMetadata.ts" ;
74import * as Hash from "effect/Hash" ;
85
96export const UNKNOWN_REVIEW_LINE = "\u0000unknown:" ;
@@ -15,7 +12,7 @@ export function projectReviewDiffContext(
1512 previous : FileDiffMetadata ,
1613 anchorSide : "additions" | "deletions" ,
1714) : FileDiffMetadata {
18- const generated = parseDiffFromFile (
15+ const generated = parseReviewDiffFromFiles (
1916 { name : previous . name , contents : before . join ( "" ) } ,
2017 { name : previous . name , contents : after . join ( "" ) } ,
2118 { context : Infinity } ,
@@ -90,7 +87,7 @@ export function projectReviewDiffContext(
9087 const oldPath = JSON . stringify ( `a/${ previous . name } ` ) ;
9188 const newPath = JSON . stringify ( `b/${ previous . name } ` ) ;
9289 const header = `diff --git ${ oldPath } ${ newPath } \n--- ${ oldPath } \n+++ ${ newPath } \n` ;
93- const file = parsePatchFiles ( header + hunks . join ( "" ) ) [ 0 ] ?. files [ 0 ] ;
90+ let file = parsePatchFiles ( header + hunks . join ( "" ) ) [ 0 ] ?. files [ 0 ] ;
9491 if ( ! file ) return { ...previous , hunks : [ ] , splitLineCount : 0 , unifiedLineCount : 0 } ;
9592 // Full contents let the renderer retain its existing expansion map. The hunks still
9693 // describe the original open regions, including ones that now contain only context.
@@ -101,10 +98,12 @@ export function projectReviewDiffContext(
10198 if ( complete ) {
10299 // Complete metadata uses document coordinates, including collapsed gaps and trailing
103100 // context, for virtualized expansion. Compact offsets are only valid for partial patches.
104- hydratePartialDiff ( "merge" , file , {
105- oldFile : { name : previous . name , contents : before . join ( "" ) } ,
106- newFile : { name : previous . name , contents : after . join ( "" ) } ,
107- } ) ;
101+ file =
102+ processFile ( header + hunks . join ( "" ) , {
103+ oldFile : { name : previous . name , contents : before . join ( "" ) } ,
104+ newFile : { name : previous . name , contents : after . join ( "" ) } ,
105+ throwOnError : true ,
106+ } ) ?? file ;
108107 } else {
109108 let splitStart = 0 ;
110109 let unifiedStart = 0 ;
0 commit comments