Bläddra i källkod

fix: prevent negative line index when maxReadFileLine is zero (#1915)

When maxReadFileLine setting was set to zero, the code would attempt to read lines with a negative end index
(maxReadFileLine - 1 = -1), causing the readLines function to reject the request.

This change:
- Checks if maxReadFileLine is greater than zero before calling readLines
- Returns an empty string when maxReadFileLine is zero
- Ensures content is only formatted with line numbers when it's not empty

Signed-off-by: Eric Wheeler <[email protected]>
Co-authored-by: Eric Wheeler <[email protected]>
Matt Rubens 1 år sedan
förälder
incheckning
b41dd739f3
1 ändrade filer med 2 tillägg och 2 borttagningar
  1. 2 2
      src/core/Cline.ts

+ 2 - 2
src/core/Cline.ts

@@ -2341,11 +2341,11 @@ export class Cline extends EventEmitter<ClineEvents> {
 									isFileTruncated = true
 
 									const res = await Promise.all([
-										readLines(absolutePath, maxReadFileLine - 1, 0),
+										maxReadFileLine > 0 ? readLines(absolutePath, maxReadFileLine - 1, 0) : "",
 										parseSourceCodeDefinitionsForFile(absolutePath, this.rooIgnoreController),
 									])
 
-									content = addLineNumbers(res[0])
+									content = res[0].length > 0 ? addLineNumbers(res[0]) : ""
 									const result = res[1]
 									if (result) {
 										sourceCodeDef = `\n\n${result}`