diff options
| author | DevMassive <[email protected]> | 2025-08-07 08:41:04 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-06 23:41:04 +0000 |
| commit | 9ac3e8b79ecc584805c27d3602612c30f2adee80 (patch) | |
| tree | ea7f1e12a183b4cf22af83fd7a2730a12ef492ac /packages/core/src/utils/filesearch/fileSearch.ts | |
| parent | 4782113cebc990b54353e095db1eb6c5e654bdef (diff) | |
feat: Improve @-command file path completion with fzf integration (#5650)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/core/src/utils/filesearch/fileSearch.ts')
| -rw-r--r-- | packages/core/src/utils/filesearch/fileSearch.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/packages/core/src/utils/filesearch/fileSearch.ts b/packages/core/src/utils/filesearch/fileSearch.ts index db14bc65..76a099f7 100644 --- a/packages/core/src/utils/filesearch/fileSearch.ts +++ b/packages/core/src/utils/filesearch/fileSearch.ts @@ -11,6 +11,7 @@ import picomatch from 'picomatch'; import { Ignore } from './ignore.js'; import { ResultCache } from './result-cache.js'; import * as cache from './crawlCache.js'; +import { Fzf, FzfResultItem } from 'fzf'; export type FileSearchOptions = { projectRoot: string; @@ -77,6 +78,18 @@ export async function filter( return results; } +/** + * Filters a list of paths based on a given pattern using fzf. + * @param allPaths The list of all paths to filter. + * @param pattern The fzf pattern to filter by. + * @returns The filtered and sorted list of paths. + */ +function filterByFzf(allPaths: string[], pattern: string) { + return new Fzf(allPaths) + .find(pattern) + .map((entry: FzfResultItem) => entry.item); +} + export type SearchOptions = { signal?: AbortSignal; maxResults?: number; @@ -137,7 +150,9 @@ export class FileSearch { filteredCandidates = candidates; } else { // Apply the user's picomatch pattern filter - filteredCandidates = await filter(candidates, pattern, options.signal); + filteredCandidates = pattern.includes('*') + ? await filter(candidates, pattern, options.signal) + : filterByFzf(this.allFiles, pattern); this.resultCache!.set(pattern, filteredCandidates); } |
