diff options
| author | DeWitt Clinton <[email protected]> | 2025-06-12 07:09:38 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-12 07:09:38 -0700 |
| commit | f2ab6d08c4cd0ca9a5b3900a6bb66a083c0577ee (patch) | |
| tree | db2083848fc070f0de6ac4fe385f59e71a04fc46 /packages/cli/src/ui/hooks/useCompletion.ts | |
| parent | 9072a4e5ee5d6a8b524be40b0465b66e5d3dceba (diff) | |
Improve the performance of filename completion over large repositories. (#938)
Diffstat (limited to 'packages/cli/src/ui/hooks/useCompletion.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/useCompletion.ts | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/packages/cli/src/ui/hooks/useCompletion.ts b/packages/cli/src/ui/hooks/useCompletion.ts index 66457aac..810c6de0 100644 --- a/packages/cli/src/ui/hooks/useCompletion.ts +++ b/packages/cli/src/ui/hooks/useCompletion.ts @@ -13,6 +13,7 @@ import { unescapePath, getErrorMessage, Config, + FileDiscoveryService, } from '@gemini-cli/core'; import { MAX_SUGGESTIONS_TO_SHOW, @@ -251,21 +252,53 @@ export function useCompletion( return foundSuggestions.slice(0, maxResults); }; + const findFilesWithGlob = async ( + searchPrefix: string, + fileDiscoveryService: FileDiscoveryService, + maxResults = 50, + ): Promise<Suggestion[]> => { + const globPattern = `**/${searchPrefix}*`; + const files = await fileDiscoveryService.glob(globPattern, { + cwd, + dot: true, + }); + + const suggestions: Suggestion[] = files + .map((file: string) => { + const relativePath = path.relative(cwd, file); + return { + label: relativePath, + value: escapePath(relativePath), + }; + }) + .slice(0, maxResults); + + return suggestions; + }; + const fetchSuggestions = async () => { setIsLoadingSuggestions(true); let fetchedSuggestions: Suggestion[] = []; - // Get centralized file discovery service if config is available - const fileDiscovery = config ? await config.getFileService() : null; + const fileDiscoveryService = config + ? await config.getFileService() + : null; try { // If there's no slash, or it's the root, do a recursive search from cwd if (partialPath.indexOf('/') === -1 && prefix) { - fetchedSuggestions = await findFilesRecursively( - cwd, - prefix, - fileDiscovery, - ); + if (fileDiscoveryService) { + fetchedSuggestions = await findFilesWithGlob( + prefix, + fileDiscoveryService, + ); + } else { + fetchedSuggestions = await findFilesRecursively( + cwd, + prefix, + fileDiscoveryService, + ); + } } else { // Original behavior: list files in the specific directory const lowerPrefix = prefix.toLowerCase(); @@ -282,7 +315,10 @@ export function useCompletion( cwd, path.join(baseDirAbsolute, entry.name), ); - if (fileDiscovery && fileDiscovery.shouldIgnoreFile(relativePath)) { + if ( + fileDiscoveryService && + fileDiscoveryService.shouldIgnoreFile(relativePath) + ) { continue; } |
