chat: enhance slash command completions and add tests for active file boosting#308742
Open
zuizuihao wants to merge 2 commits intomicrosoft:mainfrom
Open
chat: enhance slash command completions and add tests for active file boosting#308742zuizuihao wants to merge 2 commits intomicrosoft:mainfrom
zuizuihao wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves chat input file reference completions by correctly identifying/boosting the active file and ensuring completion filtering behaves consistently with the typed leader (#/@). It also adds a focused browser test suite to prevent regressions in these behaviors.
Changes:
- Update active-editor detection to ignore chat input editors and fall back to visible file editors.
- Fix file completion
filterTextso the typed leader is kept at the front. - Add new tests covering active-file boosting,
filterTextleader placement, and “active editor is chat input” scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/vs/workbench/contrib/chat/browser/widget/input/editor/chatInputCompletions.ts |
Adjusts active editor detection and file completion metadata (boosting + filterText) to improve correctness of chat file completions. |
src/vs/workbench/contrib/chat/test/browser/chatInputCompletions.test.ts |
Adds new browser tests validating active file boosting and filterText behavior for chat file completions. |
src/vs/workbench/contrib/chat/test/browser/chatInputCompletions.test.ts
Outdated
Show resolved
Hide resolved
834fd32 to
69e3dec
Compare
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: #307605
Overview
When typing
#in Copilot Chat (Agent mode), the currently active file appears near the bottom ofthe suggestion list instead of at the top. The user has to scroll past unrelated files to find the
file they are already editing.
Where does this code live?
Although the GitHub issue was auto-tagged
chat-ext-issue(a triage routing label), the actualcode responsible lives in the
microsoft/vscoderepo — not in a separate Copilot Chatextension repo. Chat input completions were internalized into VS Code core:
That is why the fix goes here.
How to reproduce
foo.tsandbar.ts).the most-recently-activated editor, pushing your code files down the MRU list).
Ctrl+1(or click) to switch back to a code file — e.g.bar.ts— so it is now theactive editor.
#.bar.tsis not at the top of the file suggestions; it may appear second, third,or not boosted at all.
bar.tsshould appear first, labeled "Active file".The Chat panel interaction in step 2 is important: it inserts a
vscode-chat-editor://entry atposition 0 of the MRU history. Because that scheme is filtered out in the completion loop, the
boost intended for the active file never fires.
Original root cause
File:
src/vs/workbench/contrib/chat/browser/widget/input/editor/chatInputCompletions.tsClass:
BuiltinDynamicCompletions· Method:addFileAndFolderEntriesThe method builds
#file suggestions from editor MRU history. To boost the active file to thetop, it originally checked whether the history entry was at raw array index 0:
IHistoryService.getHistory()returns the MRU editor history — not "the currently active editor."Index 0 is just whichever editor was activated most recently, which is often the Chat panel itself.
The loop also filters out unsupported schemes (e.g.
vscode-chat-editor://) before pushingsuggestions, so the boosted slot can be skipped entirely while a regular code file further down
the list gets no boost.
In short: the code used history array position as a proxy for active-editor identity, and that
proxy breaks the moment the Chat panel is focused.
Root cause
Bug 1 —
i === 0uses the raw history array index, not the filtered indexicomes fromthis.historyService.getHistory().entries(). WhengetHistory()[0]is avscode-chat-editor://URI, it gets skipped by theisSupportedChatFileSchemefilter — butiis still0only for that skipped entry. The first valid file getsi === 1, so it isnever boosted.
Bug 2 —
findActiveCodeEditor()returns the chat input editorWhen the user clicks into the chat input,
codeEditorService.getActiveCodeEditor()returns thechat input editor (scheme
vscode-chat-input). The method checks forvscodeNotebookCellbutnot for
vscodeChatInput, so it reports the chat input as the "active code editor" instead ofthe file the user was editing.
Bug 3 — file filterText puts the
#leader mid-string, so tools often outscore filesVS Code's suggest widget sorts by match score first, then falls back to initial ordering. In
practice, this means
sortTextonly helps after the suggest model has already grouped items byscore. When
#is typed:filterText: "#toolName"→#matches at position 0 (prefix match, high score).filterText: "b.txt #b.txt /path"→#matches at position 6(middle-of-string match, low score).
Because tools consistently scored higher, they tended to appear above files even when the active
file had
sortText: ' '. The active-file boost still matters for ordering among similarly scoredfile entries, but it cannot compensate for a worse filter match.
How these bugs were introduced
i === 0heuristic to fix #256737. AssumedgetHistory()[0]is always the active file.a2cf16dfac7e(Oct 2025)isSupportedChatFileSchemefiltering in the same loop. Did not update the boost logic — nowgetHistory()[0]can be filtered out, leaving no file boosted.6dffc1fcfae9(Feb 2026)filterTextto include basename and path for better fuzzy matching, but moved the#leader away from the front of the string.41d219f6c3da(Jan 2026)Fix
The current patch keeps the fix scoped to the active-file ranking problem while preserving the
broader file-matching improvements from February 2026:
findActiveCodeEditor()— skipvscodeChatInputscheme (same as the existingvscodeNotebookCellskip), so the method falls back to the first visible file editor.addFileAndFolderEntries()— resolveactiveResourcefromfindActiveCodeEditor()beforethe loop. Inside the loop, compare each history entry to
activeResourceviaisEqual()andboost the match.
filterText— keep the#leader at the start of the string while still includingbasename and relative path, e.g.
#b.txt b.txt /path, so files remain easy to fuzzy-match byname/path without losing the prefix-score advantage when the user has typed only
#.Before Fix:


after Fix: