@@ -512,7 +512,6 @@ func chunkBySize(content string, config *ChunkConfig) ([]ReviewChunk, error) {
512
512
currentLines = append (currentLines , line )
513
513
currentTokens += lineTokens
514
514
currentBytes += lineBytes
515
- currentTokens += lineTokens
516
515
}
517
516
518
517
// Handle the final chunk if there's remaining content
@@ -576,8 +575,12 @@ func addContextAndOverlap(chunks []ReviewChunk, fullContent string, config *Chun
576
575
// Add overlap with previous chunk if needed
577
576
if i > 0 && config .OverlapLines > 0 {
578
577
overlapStart := max (chunks [i - 1 ].endline - config .OverlapLines , chunks [i - 1 ].startline )
579
- overlapEnd := chunks [i - 1 ].endline
580
- overlap := strings .Join (lines [overlapStart - 1 :overlapEnd ], "\n " )
578
+ var overlap string
579
+ if overlapStart > 1 {
580
+ overlap = strings .Join (lines [overlapStart - 1 :chunks [i - 1 ].endline ], "\n " )
581
+ } else {
582
+ overlap = strings .Join (lines [0 :chunks [i - 1 ].endline ], "\n " )
583
+ }
581
584
chunks [i ].content = overlap + "\n " + chunks [i ].content
582
585
chunks [i ].startline = overlapStart
583
586
}
@@ -595,19 +598,12 @@ func createCompleteChunk(
595
598
estimatedTotalChunks int ,
596
599
changes string ,
597
600
) ReviewChunk {
598
- // Calculate context boundaries
599
- contextStart := max (0 , startLine - config .ContextLines )
600
- contextEnd := min (strings .Count (fullContent , "\n " )+ 1 , endLine + config .ContextLines )
601
-
602
- // Split full content into lines for context extraction
603
- lines := strings .Split (fullContent , "\n " )
604
-
605
601
chunk := ReviewChunk {
606
602
content : content ,
607
603
startline : startLine ,
608
604
endline : endLine ,
609
- leadingcontext : strings . Join ( lines [ contextStart : startLine - 1 ], " \n " ),
610
- trailingcontext : strings . Join ( lines [ endLine : contextEnd ], " \n " ),
605
+ leadingcontext : "" , // Context will be added in addContextAndOverlap
606
+ trailingcontext : "" , // Context will be added in addContextAndOverlap
611
607
changes : ExtractRelevantChanges (changes , startLine , endLine ),
612
608
filePath : filePath ,
613
609
totalChunks : estimatedTotalChunks ,
0 commit comments