mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix: convert recursive directory scanning to iterative approach to prevent stack overflow
- Replace recursive scanDirectory function with iterative implementation using a queue - Prevents "Maximum call stack size exceeded" error when indexing large codebases (200k+ blocks) - Maintains all existing functionality and directory filtering logic - All existing tests pass without modification Fixes #7588
This commit is contained in:
parent
2e59347a9d
commit
dbcb52cda8
1 changed files with 16 additions and 5 deletions
|
|
@ -401,7 +401,20 @@ async function listFilteredDirectories(
|
|||
ignoreInstance,
|
||||
}
|
||||
|
||||
async function scanDirectory(currentPath: string, context: ScanContext): Promise<void> {
|
||||
// Use iterative approach with a queue to avoid stack overflow on deep directory structures
|
||||
interface QueueItem {
|
||||
path: string
|
||||
context: ScanContext
|
||||
}
|
||||
|
||||
const queue: QueueItem[] = [{ path: absolutePath, context: initialContext }]
|
||||
|
||||
while (queue.length > 0) {
|
||||
const item = queue.shift()
|
||||
if (!item) continue
|
||||
|
||||
const { path: currentPath, context } = item
|
||||
|
||||
try {
|
||||
// List all entries in the current directory
|
||||
const entries = await fs.promises.readdir(currentPath, { withFileTypes: true })
|
||||
|
|
@ -461,7 +474,8 @@ async function listFilteredDirectories(
|
|||
isTargetDir: false,
|
||||
insideExplicitHiddenTarget: newInsideExplicitHiddenTarget,
|
||||
}
|
||||
await scanDirectory(fullDirPath, newContext)
|
||||
// Add to queue instead of recursive call
|
||||
queue.push({ path: fullDirPath, context: newContext })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -471,9 +485,6 @@ async function listFilteredDirectories(
|
|||
}
|
||||
}
|
||||
|
||||
// Start scanning from the root directory
|
||||
await scanDirectory(absolutePath, initialContext)
|
||||
|
||||
return directories
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue