Skip to content

Commit 73fc8e4

Browse files
update chunk
1 parent c0c0d51 commit 73fc8e4

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

chunk.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ func chunkBySize(content string, config *ChunkConfig) ([]ReviewChunk, error) {
512512
currentLines = append(currentLines, line)
513513
currentTokens += lineTokens
514514
currentBytes += lineBytes
515-
currentTokens += lineTokens
516515
}
517516

518517
// Handle the final chunk if there's remaining content
@@ -576,8 +575,12 @@ func addContextAndOverlap(chunks []ReviewChunk, fullContent string, config *Chun
576575
// Add overlap with previous chunk if needed
577576
if i > 0 && config.OverlapLines > 0 {
578577
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+
}
581584
chunks[i].content = overlap + "\n" + chunks[i].content
582585
chunks[i].startline = overlapStart
583586
}
@@ -595,19 +598,12 @@ func createCompleteChunk(
595598
estimatedTotalChunks int,
596599
changes string,
597600
) 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-
605601
chunk := ReviewChunk{
606602
content: content,
607603
startline: startLine,
608604
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
611607
changes: ExtractRelevantChanges(changes, startLine, endLine),
612608
filePath: filePath,
613609
totalChunks: estimatedTotalChunks,

0 commit comments

Comments
 (0)