diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 969b45fb..04145318 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -532,6 +532,7 @@ export async function loadCliConfig( respectGeminiIgnore: settings.fileFiltering?.respectGeminiIgnore, enableRecursiveFileSearch: settings.fileFiltering?.enableRecursiveFileSearch, + disableFuzzySearch: settings.fileFiltering?.disableFuzzySearch, }, checkpointing: argv.checkpointing || settings.checkpointing?.enabled, proxy: diff --git a/packages/core/src/utils/filesearch/fileSearch.ts b/packages/core/src/utils/filesearch/fileSearch.ts index 661c5f6d..046e73cf 100644 --- a/packages/core/src/utils/filesearch/fileSearch.ts +++ b/packages/core/src/utils/filesearch/fileSearch.ts @@ -101,6 +101,7 @@ class RecursiveFileSearch implements FileSearch { async initialize(): Promise { this.ignore = loadIgnoreRules(this.options); + this.allFiles = await crawl({ crawlDirectory: this.options.projectRoot, cwd: this.options.projectRoot, @@ -116,7 +117,11 @@ class RecursiveFileSearch implements FileSearch { pattern: string, options: SearchOptions = {}, ): Promise { - if (!this.resultCache || !this.fzf || !this.ignore) { + if ( + !this.resultCache || + (!this.fzf && !this.options.disableFuzzySearch) || + !this.ignore + ) { throw new Error('Engine not initialized. Call initialize() first.'); } @@ -131,7 +136,7 @@ class RecursiveFileSearch implements FileSearch { filteredCandidates = candidates; } else { let shouldCache = true; - if (pattern.includes('*') || this.options.disableFuzzySearch) { + if (pattern.includes('*') || !this.fzf) { filteredCandidates = await filter(candidates, pattern, options.signal); } else { filteredCandidates = await this.fzf @@ -175,12 +180,14 @@ class RecursiveFileSearch implements FileSearch { private buildResultCache(): void { this.resultCache = new ResultCache(this.allFiles); - // The v1 algorithm is much faster since it only looks at the first - // occurence of the pattern. We use it for search spaces that have >20k - // files, because the v2 algorithm is just too slow in those cases. - this.fzf = new AsyncFzf(this.allFiles, { - fuzzy: this.allFiles.length > 20000 ? 'v1' : 'v2', - }); + if (!this.options.disableFuzzySearch) { + // The v1 algorithm is much faster since it only looks at the first + // occurence of the pattern. We use it for search spaces that have >20k + // files, because the v2 algorithm is just too slow in those cases. + this.fzf = new AsyncFzf(this.allFiles, { + fuzzy: this.allFiles.length > 20000 ? 'v1' : 'v2', + }); + } } }