Skip to content

supportFileAttachment in new coding agent editor#7744

Merged
joshspicer merged 3 commits intomainfrom
joshspicer/file-context
Sep 3, 2025
Merged

supportFileAttachment in new coding agent editor#7744
joshspicer merged 3 commits intomainfrom
joshspicer/file-context

Conversation

@joshspicer
Copy link
Copy Markdown
Member

@joshspicer joshspicer commented Sep 3, 2025

Initial support for file attachments. Attaches the relative name of the file.

similar to microsoft/vscode#264740 but this is in the chat session editor

@joshspicer joshspicer enabled auto-merge (squash) September 3, 2025 00:41
@vs-code-engineering vs-code-engineering Bot added this to the August 2025 milestone Sep 3, 2025
@joshspicer joshspicer merged commit 4543d29 into main Sep 3, 2025
3 checks passed
@joshspicer joshspicer deleted the joshspicer/file-context branch September 3, 2025 01:42

cleanPrompt(prompt: string): string {
// Remove #file:xxxx from the prompt
return prompt.replace(/#file:\S+/g, '').trim();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We want to keep the file name (or relative file path) in the prompt, for example, user might write add tests to #file:x.ts, if we replace it completely and include multiple files as relevant files, the prompt itself might be ambiguous as it reads as add tests to.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

public async provideNewChatSessionItem(options: { prompt?: string; history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>; metadata?: any; }, token: vscode.CancellationToken): Promise<ChatSessionWithPR | ChatSessionFromSummarizedChat> {
const { prompt, history } = options;
if (!prompt) {
extractFileReferences(references: readonly ChatPromptReference[] | undefined): string | undefined {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be private

Comment on lines +762 to +766
const workspaceFolder = vscode.workspace.getWorkspaceFolder(ref.value);
if (workspaceFolder) {
const relativePath = pathLib.relative(workspaceFolder.uri.fsPath, ref.value.fsPath);
parts.push(` - ${relativePath}`);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will be relative to the workspace folder, not the git repo. Instead, you should use getRepositoryForFile:

export function getRepositoryForFile(gitAPI: GitApiImpl, file: vscode.Uri): Repository | undefined {
const foundRepos: Repository[] = [];

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.

4 participants