Sessions: Add #file context completions to new-chat input#308095
Merged
Sessions: Add #file context completions to new-chat input#308095
Conversation
Adds # completions to the sessions NewChatViewPane input editor, scoped to the workspace selected in the dropdown picker. - New VariableCompletionHandler registers a completion provider on the sessions-chat URI scheme (same pattern as SlashCommandHandler) - Typing # shows files from the selected workspace via ISearchService (local/remote) or IFileService tree walk (virtual filesystems) - Recent workspace-scoped files from editor history are always shown - Accepted completions insert #file:<name> text with slash-command-style decorations (colored background/foreground, rounded corners) - Files are also added as attachment pills via NewChatContextAttachments - Added public addAttachments() method to NewChatContextAttachments
Contributor
There was a problem hiding this comment.
Pull request overview
Adds #-triggered file-context completions to the Sessions “new chat” input (scheme sessions-chat), scoped to the workspace chosen in the picker, and wires accepted items into context attachment pills.
Changes:
- Introduces
VariableCompletionHandlerto provide#file:suggestions from editor history + workspace search / filesystem walk, and decorates inserted#file:tokens. - Exposes
NewChatContextAttachments.addAttachments()for programmatic addition of context pills. - Instantiates the new completion handler in
NewChatViewPanealongside the existing slash command handler.
Show a summary per file
| File | Description |
|---|---|
| src/vs/sessions/contrib/chat/browser/variableCompletions.ts | New # completion provider + decorations + command to add selected resources as attachments. |
| src/vs/sessions/contrib/chat/browser/newChatContextAttachments.ts | Adds a public wrapper to add attachments from completion acceptance. |
| src/vs/sessions/contrib/chat/browser/newChatViewPane.ts | Wires VariableCompletionHandler into the new-chat editor lifecycle. |
Copilot's findings
Comments suppressed due to low confidence (2)
src/vs/sessions/contrib/chat/browser/variableCompletions.ts:238
_addFileAndFolderEntriesalways calls into_addEntriesViaSearch/_addEntriesViaFileService, even when the user has only typed#andpatternis empty. That meansISearchService.fileSearchcan run a workspace-wide search with an emptyfilePattern, which can be expensive on large repos. Consider gating the search/tree-walk behind a non-empty pattern (and relying on the history suggestions for the initial#list), similar to how workbench chat variable completions only search whenpatternis truthy.
// SEARCH — always run to populate initial results (empty pattern returns scored files)
if (workspaceUri.scheme === Schemas.file || workspaceUri.scheme === Schemas.vscodeRemote) {
await this._addEntriesViaSearch(workspaceUri, pattern, seen, makeItem, result, token);
} else {
await this._addEntriesViaFileService(workspaceUri, pattern, seen, makeItem, result, token);
}
src/vs/sessions/contrib/chat/browser/variableCompletions.ts:272
- For
file://andvscodeRemoteworkspaces,_addEntriesViaSearchonly addsFileKind.FILEsuggestions, so directories can never be suggested/attached via#completions. For non-searchable schemes you do add directories via the file-service walk, so behavior differs by scheme even thoughNewChatContextAttachmentssupportskind: 'directory'. Either add directory suggestions for local/remote too (e.g. via a lightweight fileService resolve for top levels / limited depth) or update the UX/docs to clarify that#completions only attach files on searchable workspaces.
/**
* Uses the search service to find files/folders — works for `file://` and `vscodeRemote` schemes.
*/
private async _addEntriesViaSearch(
workspaceUri: URI,
pattern: string | undefined,
seen: ResourceSet,
makeItem: (resource: URI, kind: FileKind, description?: string, boostPriority?: boolean) => CompletionItem,
result: CompletionList,
token: CancellationToken,
): Promise<void> {
const excludePattern = getExcludes(this.configurationService.getValue<ISearchConfiguration>({ resource: workspaceUri }));
try {
const searchResult = await this.searchService.fileSearch({
folderQueries: [{
folder: workspaceUri,
disregardIgnoreFiles: false,
}],
type: QueryType.File,
filePattern: pattern || '',
excludePattern,
sortByScore: true,
maxResults: 100,
}, token);
for (const match of searchResult.results) {
if (!seen.has(match.resource)) {
seen.add(match.resource);
result.suggestions.push(makeItem(match.resource, FileKind.FILE));
}
}
- Files reviewed: 3/3 changed files
- Comments generated: 2
joshspicer
approved these changes
Apr 6, 2026
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.
Fixes: #299057
Adds
#completions to the sessionsNewChatViewPaneinput editor, scoped to the workspace selected in the dropdown picker.Changes
New file:
variableCompletions.tsVariableCompletionHandlerregisters a completion provider on thesessions-chatURI scheme (same pattern asSlashCommandHandler)#immediately shows files from the selected workspacefile://andvscodeRemoteschemes: usesISearchService.fileSearch()github-remote-file://): walks the file tree viaIFileService.resolve()IHistoryService) are always shown#file:<name>text with slash-command-style decorations (colored background/foreground viachatSlashCommandForeground/chatSlashCommandBackground, rounded corners)NewChatContextAttachmentsModified:
newChatContextAttachments.tsaddAttachments()method (wraps private_addAttachments())Modified:
newChatViewPane.tsVariableCompletionHandleralongsideSlashCommandHandlerDesign decisions
@completions — only#for file context, matching what makes sense for the sessions pre-chat state#sym:,#selection,#session— symbols require open editors/language servers (unavailable pre-session), selection/session don't apply in the sessions appvs/sessions/, imports only from allowed layers