refactor: Refactors the VS Code file completion system to use fuzzy search#2437
refactor: Refactors the VS Code file completion system to use fuzzy search#2437qqqys merged 6 commits intoQwenLM:mainfrom
Conversation
…dling - Removed client-side filtering for search queries; fuzzy search is now handled by the backend. - Enhanced file search initialization and caching mechanisms in FileMessageHandler. - Added file watchers for cache invalidation on file system changes. - Updated completion trigger logic to prioritize '@' over '/' for path-like queries. - Reset last query on file selection to ensure fresh search results. This refactor improves search efficiency and maintains accurate file references in the application.
📋 Review SummaryThis PR refactors the VS Code file completion system to use backend fuzzy search ( 🔍 General Feedback
🎯 Specific Feedback🔴 Critical
🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
| // Priority: @ trigger takes precedence over / trigger | ||
| // This allows path-like queries (e.g., "src/components/Button") in @ mentions | ||
| // But skip if the trigger is inside a file tag | ||
| if (lastAtMatch >= 0) { |
There was a problem hiding this comment.
Nice improvement here for supporting path-like queries inside @ mentions. One thing I think may still regress, though: this now gives @ priority whenever an @ appears anywhere before the cursor, which can swallow a later / trigger on the same line.
For example, with input like @src/foo.ts /fix, once the cursor is after /fix, this still picks the earlier @ and builds the query from there, so slash-command completion never opens.
Would it make sense to prefer the nearest valid trigger before the cursor, rather than always preferring @ globally? That should preserve the path-query behavior while still allowing / completion to work after a file mention.
There was a problem hiding this comment.
You're right. Normally @ and / shouldn't interfere with each other's triggers. A good expected behavior would be:
| Input | Cursor position | Result |
|---|---|---|
| @src/foo.ts /fix | After /fix | / triggers (closer to cursor) |
| @src/components | After components | @ triggers |
| /explain @file.ts | After file.ts | @ triggers (closer to cursor) |
| @src/foo/bar | After bar | @ triggers (inner / not at word boundary) |
| const rootPath = folder.uri.fsPath; | ||
| this.invalidateFileSearchCache(rootPath); | ||
| } | ||
| for (const folder of e.added) { |
There was a problem hiding this comment.
Really like the direction here with cache invalidation on workspace changes. I think there is one lifecycle gap to watch out for: when a new workspace folder is added, we invalidate its cache entry, but we do not register a new file watcher for that folder.
That means searches in the newly added root can build a FileSearch index once, but later file create/change/delete events in that root will not invalidate it, so results can become stale until the provider is recreated.
It may be worth creating and tracking a watcher for each newly added folder inside onDidChangeWorkspaceFolders, so the invalidation behavior stays consistent for roots added after initialization too.
There was a problem hiding this comment.
You're right. I should create a watcher for each folder. The ideal behavior would be:
| Event | Before | After |
|---|---|---|
| Init with folders A, B | Watchers for A, B | Watchers for A, B |
| Add folder C | Cache invalidated, no watcher | Cache invalidated, watcher created for C |
| Remove folder B | Cache invalidated, watcher leaks | Cache invalidated, watcher disposed |
| Dispose all | All disposed | All disposed |
…suggestions by prioritizing '@' over '/' and refining context checks
TLDR
Refactors the VS Code file completion system to use backend fuzzy search instead of client-side substring matching, providing better search results and improved performance for large workspaces.
Dive Deeper
This PR addresses several issues with the file completion feature in the VS Code IDE companion:
1. Backend Fuzzy Search Integration
includes()filtering with the existingFileSearchFactoryfrom@qwen-code/qwen-code-core2. File Watcher Implementation
3. Trigger Character Logic Fixes
@and/completion triggerssrc/components/Button) within@mentions4. Improved State Management
Reviewer Test Plan
@in the chat input and verify file completions appearsrc/comp/butto matchsrc/components/Button.tsx/slash commands still work correctly@mentionsTesting Matrix
Linked issues / bugs
Resolves #2325