Skip to content

Sessions: Add #file context completions to new-chat input#308095

Merged
osortega merged 4 commits intomainfrom
osortega/sessions-hash-completions
Apr 7, 2026
Merged

Sessions: Add #file context completions to new-chat input#308095
osortega merged 4 commits intomainfrom
osortega/sessions-hash-completions

Conversation

@osortega
Copy link
Copy Markdown
Contributor

@osortega osortega commented Apr 6, 2026

Fixes: #299057
Adds # completions to the sessions NewChatViewPane input editor, scoped to the workspace selected in the dropdown picker.

Changes

New file: variableCompletions.ts

  • VariableCompletionHandler registers a completion provider on the sessions-chat URI scheme (same pattern as SlashCommandHandler)
  • Typing # immediately shows files from the selected workspace
  • For file:// and vscodeRemote schemes: uses ISearchService.fileSearch()
  • For virtual schemes (e.g. github-remote-file://): walks the file tree via IFileService.resolve()
  • Recent workspace-scoped files from editor history (IHistoryService) are always shown
  • Accepted completions insert #file:<name> text with slash-command-style decorations (colored background/foreground via chatSlashCommandForeground/chatSlashCommandBackground, rounded corners)
  • Files are also added as attachment pills via NewChatContextAttachments

Modified: newChatContextAttachments.ts

  • Added public addAttachments() method (wraps private _addAttachments())

Modified: newChatViewPane.ts

  • Imported and instantiated VariableCompletionHandler alongside SlashCommandHandler
  • Passes the editor, context attachments, and workspace URI getter

Design decisions

  • No @ completions — only # for file context, matching what makes sense for the sessions pre-chat state
  • No #sym:, #selection, #session — symbols require open editors/language servers (unavailable pre-session), selection/session don't apply in the sessions app
  • Workspace-scoped — all results filtered to the workspace selected in the dropdown, matching the "Add Context..." button behavior
  • No core dependencies added — all code lives in vs/sessions/, imports only from allowed layers

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
Copilot AI review requested due to automatic review settings April 6, 2026 22:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 VariableCompletionHandler to 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 NewChatViewPane alongside 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

  • _addFileAndFolderEntries always calls into _addEntriesViaSearch / _addEntriesViaFileService, even when the user has only typed # and pattern is empty. That means ISearchService.fileSearch can run a workspace-wide search with an empty filePattern, 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 when pattern is 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:// and vscodeRemote workspaces, _addEntriesViaSearch only adds FileKind.FILE suggestions, 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 though NewChatContextAttachments supports kind: '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

Comment thread src/vs/sessions/contrib/chat/browser/variableCompletions.ts Outdated
Comment thread src/vs/sessions/contrib/chat/browser/newChatViewPane.ts Outdated
@osortega osortega marked this pull request as ready for review April 6, 2026 23:50
@osortega osortega enabled auto-merge (squash) April 6, 2026 23:50
@osortega osortega merged commit 910529e into main Apr 7, 2026
29 of 30 checks passed
@osortega osortega deleted the osortega/sessions-hash-completions branch April 7, 2026 00:27
@vs-code-engineering vs-code-engineering bot added this to the 1.116.0 milestone Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New session input should support # to attach context via prompt

3 participants