Skip to content

Commit 61b2104

Browse files
committed
Fix bug where start/end line not passed to diff
1 parent c2b4b05 commit 61b2104

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/core/Cline.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,12 @@ export class Cline {
12381238
const originalContent = await fs.readFile(absolutePath, "utf-8")
12391239

12401240
// Apply the diff to the original content
1241-
const diffResult = this.diffStrategy?.applyDiff(originalContent, diffContent) ?? {
1241+
const diffResult = this.diffStrategy?.applyDiff(
1242+
originalContent,
1243+
diffContent,
1244+
parseInt(block.params.start_line ?? ''),
1245+
parseInt(block.params.end_line ?? '')
1246+
) ?? {
12421247
success: false,
12431248
error: "No diff strategy available"
12441249
}

src/core/assistant-message/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export const toolParamNames = [
4444
"question",
4545
"result",
4646
"diff",
47+
"start_line",
48+
"end_line",
4749
] as const
4850

4951
export type ToolParamName = (typeof toolParamNames)[number]

src/core/diff/strategies/search-replace.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ Your search/replace content here
162162
let bestMatchScore = 0;
163163
let bestMatchContent = "";
164164

165-
if (startLine !== undefined && endLine !== undefined) {
165+
if (startLine && endLine) {
166166
// Convert to 0-based index
167167
const exactStartIndex = startLine - 1;
168168
const exactEndIndex = endLine - 1;
169169

170-
if (exactStartIndex < 0 || exactEndIndex >= originalLines.length) {
170+
if (exactStartIndex < 0 || exactEndIndex >= originalLines.length || exactStartIndex > exactEndIndex) {
171171
const debugInfo = this.debugEnabled ? `\n\nDebug Info:\n- Requested Range: lines ${startLine}-${endLine}\n- File Bounds: lines 1-${originalLines.length}` : '';
172172

173173
return {
@@ -193,13 +193,12 @@ Your search/replace content here
193193
let searchStartIndex = 0;
194194
let searchEndIndex = originalLines.length;
195195

196-
if (startLine !== undefined || endLine !== undefined) {
196+
if (startLine || endLine) {
197197
// Convert to 0-based index and add buffer
198-
const BUFFER_LINES = 5;
199-
if (startLine !== undefined) {
198+
if (startLine) {
200199
searchStartIndex = Math.max(0, startLine - (BUFFER_LINES + 1));
201200
}
202-
if (endLine !== undefined) {
201+
if (endLine) {
203202
searchEndIndex = Math.min(originalLines.length, endLine + BUFFER_LINES);
204203
}
205204
}
@@ -236,10 +235,10 @@ Your search/replace content here
236235
? `\n\nBest Match Found:\n${addLineNumbers(bestMatchContent, matchIndex + 1)}`
237236
: `\n\nBest Match Found:\n(no match)`;
238237

239-
const debugInfo = this.debugEnabled ? `\n\nDebug Info:\n- Similarity Score: ${Math.floor(bestMatchScore * 100)}%\n- Required Threshold: ${Math.floor(this.fuzzyThreshold * 100)}%\n- Line Range: lines ${startLine}-${endLine}\n\nSearch Content:\n${searchChunk}${bestMatchSection}${originalContentSection}` : '';
238+
const debugInfo = this.debugEnabled ? `\n\nDebug Info:\n- Similarity Score: ${Math.floor(bestMatchScore * 100)}%\n- Required Threshold: ${Math.floor(this.fuzzyThreshold * 100)}%\n- Search Range: ${startLine && endLine ? `lines ${startLine}-${endLine}` : 'start to end'}\n\nSearch Content:\n${searchChunk}${bestMatchSection}${originalContentSection}` : '';
240239

241-
const lineRange = startLine !== undefined || endLine !== undefined ?
242-
` at ${startLine !== undefined ? `start: ${startLine}` : 'start'} to ${endLine !== undefined ? `end: ${endLine}` : 'end'}` : '';
240+
const lineRange = startLine || endLine ?
241+
` at ${startLine ? `start: ${startLine}` : 'start'} to ${endLine ? `end: ${endLine}` : 'end'}` : '';
243242
return {
244243
success: false,
245244
error: `No sufficiently similar match found${lineRange} (${Math.floor(bestMatchScore * 100)}% similar, needs ${Math.floor(this.fuzzyThreshold * 100)}%)${debugInfo}`

0 commit comments

Comments
 (0)