mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-11 22:51:26 +00:00
Respect the setting to always read the full file (#2514)
This commit is contained in:
parent
e453690e7f
commit
624691abb0
3 changed files with 50 additions and 6 deletions
5
.changeset/tough-coats-hear.md
Normal file
5
.changeset/tough-coats-hear.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"roo-cline": patch
|
||||
---
|
||||
|
||||
Respect the setting to always read the full file
|
||||
|
|
@ -186,7 +186,6 @@ describe("read_file tool with maxReadFileLine setting", () => {
|
|||
|
||||
return toolResult
|
||||
}
|
||||
|
||||
describe("when maxReadFileLine is negative", () => {
|
||||
it("should read the entire file using extractTextFromFile", async () => {
|
||||
// Setup - use default mockInputContent
|
||||
|
|
@ -201,6 +200,43 @@ describe("read_file tool with maxReadFileLine setting", () => {
|
|||
expect(mockedParseSourceCodeDefinitionsForFile).not.toHaveBeenCalled()
|
||||
expect(result).toBe(expectedFullFileXml)
|
||||
})
|
||||
|
||||
it("should ignore range parameters and read entire file when maxReadFileLine is -1", async () => {
|
||||
// Setup - use default mockInputContent
|
||||
mockInputContent = fileContent
|
||||
|
||||
// Execute with range parameters
|
||||
const result = await executeReadFileTool(
|
||||
{
|
||||
start_line: "2",
|
||||
end_line: "4",
|
||||
},
|
||||
{ maxReadFileLine: -1 },
|
||||
)
|
||||
|
||||
// Verify that extractTextFromFile is still used (not readLines)
|
||||
expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath)
|
||||
expect(mockedReadLines).not.toHaveBeenCalled()
|
||||
expect(mockedParseSourceCodeDefinitionsForFile).not.toHaveBeenCalled()
|
||||
expect(result).toBe(expectedFullFileXml)
|
||||
})
|
||||
|
||||
it("should not show line snippet in approval message when maxReadFileLine is -1", async () => {
|
||||
// This test verifies the line snippet behavior for the approval message
|
||||
// Setup - use default mockInputContent
|
||||
mockInputContent = fileContent
|
||||
|
||||
// Execute - we'll reuse executeReadFileTool to run the tool
|
||||
await executeReadFileTool({}, { maxReadFileLine: -1 })
|
||||
|
||||
// Verify the empty line snippet for full read was passed to the approval message
|
||||
// Look at the parameters passed to the 'ask' method in the approval message
|
||||
const askCall = mockCline.ask.mock.calls[0]
|
||||
const completeMessage = JSON.parse(askCall[1])
|
||||
|
||||
// Verify the reason (lineSnippet) is empty or undefined for full read
|
||||
expect(completeMessage.reason).toBeFalsy()
|
||||
})
|
||||
})
|
||||
|
||||
describe("when maxReadFileLine is 0", () => {
|
||||
|
|
|
|||
|
|
@ -51,13 +51,16 @@ export async function readFileTool(
|
|||
return
|
||||
}
|
||||
|
||||
const { maxReadFileLine = 500 } = (await cline.providerRef.deref()?.getState()) ?? {}
|
||||
const isFullRead = maxReadFileLine === -1
|
||||
|
||||
// Check if we're doing a line range read
|
||||
let isRangeRead = false
|
||||
let startLine: number | undefined = undefined
|
||||
let endLine: number | undefined = undefined
|
||||
|
||||
// Check if we have either range parameter
|
||||
if (startLineStr || endLineStr) {
|
||||
// Check if we have either range parameter and we're not doing a full read
|
||||
if (!isFullRead && (startLineStr || endLineStr)) {
|
||||
isRangeRead = true
|
||||
}
|
||||
|
||||
|
|
@ -98,11 +101,11 @@ export async function readFileTool(
|
|||
return
|
||||
}
|
||||
|
||||
const { maxReadFileLine = 500 } = (await cline.providerRef.deref()?.getState()) ?? {}
|
||||
|
||||
// Create line snippet description for approval message
|
||||
let lineSnippet = ""
|
||||
if (startLine !== undefined && endLine !== undefined) {
|
||||
if (isFullRead) {
|
||||
// No snippet for full read
|
||||
} else if (startLine !== undefined && endLine !== undefined) {
|
||||
lineSnippet = t("tools:readFile.linesRange", { start: startLine + 1, end: endLine + 1 })
|
||||
} else if (startLine !== undefined) {
|
||||
lineSnippet = t("tools:readFile.linesFromToEnd", { start: startLine + 1 })
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue