Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add folder action support #242454

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ import { ATTACH_PROMPT_ACTION_ID, AttachPromptAction, IChatAttachPromptActionOpt
export function registerChatContextActions() {
registerAction2(AttachContextAction);
registerAction2(AttachFileToChatAction);
registerAction2(AttachFolderToChatAction);
registerAction2(AttachSelectionToChatAction);
registerAction2(AttachFileToEditingSessionAction);
registerAction2(AttachFolderToEditingSessionAction);
registerAction2(AttachSelectionToEditingSessionAction);
}

Expand Down Expand Up @@ -253,8 +255,8 @@ interface IReusablePromptQuickPickItem extends IQuickPickItem {
keybinding?: ResolvedKeybinding;
}

abstract class AttachFileAction extends Action2 {
getFiles(accessor: ServicesAccessor, ...args: any[]): URI[] {
abstract class AttachResourceAction extends Action2 {
getResources(accessor: ServicesAccessor, ...args: any[]): URI[] {
const editorService = accessor.get(IEditorService);

const contexts = Array.isArray(args[1]) ? args[1] : [args[0]];
Expand All @@ -280,7 +282,7 @@ abstract class AttachFileAction extends Action2 {
}
}

class AttachFileToChatAction extends AttachFileAction {
class AttachFileToChatAction extends AttachResourceAction {

static readonly ID = 'workbench.action.chat.attachFile';

Expand All @@ -301,7 +303,7 @@ class AttachFileToChatAction extends AttachFileAction {

override async run(accessor: ServicesAccessor, ...args: any[]): Promise<void> {
const variablesService = accessor.get(IChatVariablesService);
const files = this.getFiles(accessor, ...args);
const files = this.getResources(accessor, ...args);

if (files.length) {
(await showChatView(accessor.get(IViewsService)))?.focusInput();
Expand All @@ -312,6 +314,32 @@ class AttachFileToChatAction extends AttachFileAction {
}
}

class AttachFolderToChatAction extends AttachResourceAction {

static readonly ID = 'workbench.action.chat.attachFolder';

constructor() {
super({
id: AttachFolderToChatAction.ID,
title: localize2('workbench.action.chat.attachFolder.label', "Add Folder to Chat"),
category: CHAT_CATEGORY,
f1: false,
});
}

override async run(accessor: ServicesAccessor, ...args: any[]): Promise<void> {
const variablesService = accessor.get(IChatVariablesService);
const folders = this.getResources(accessor, ...args);

if (folders.length) {
(await showChatView(accessor.get(IViewsService)))?.focusInput();
for (const folder of folders) {
variablesService.attachContext('folder', folder, ChatAgentLocation.Panel);
}
}
}
}

class AttachSelectionToChatAction extends Action2 {

static readonly ID = 'workbench.action.chat.attachSelection';
Expand Down Expand Up @@ -373,7 +401,7 @@ class AttachSelectionToChatAction extends Action2 {
}
}

class AttachFileToEditingSessionAction extends AttachFileAction {
class AttachFileToEditingSessionAction extends AttachResourceAction {

static readonly ID = 'workbench.action.edits.attachFile';

Expand All @@ -394,7 +422,7 @@ class AttachFileToEditingSessionAction extends AttachFileAction {

override async run(accessor: ServicesAccessor, ...args: any[]): Promise<void> {
const variablesService = accessor.get(IChatVariablesService);
const files = this.getFiles(accessor, ...args);
const files = this.getResources(accessor, ...args);

if (files.length) {
(await showEditsView(accessor.get(IViewsService)))?.focusInput();
Expand All @@ -405,6 +433,32 @@ class AttachFileToEditingSessionAction extends AttachFileAction {
}
}

class AttachFolderToEditingSessionAction extends AttachResourceAction {

static readonly ID = 'workbench.action.edits.attachFolder';

constructor() {
super({
id: AttachFolderToEditingSessionAction.ID,
title: localize2('workbench.action.edits.attachFolder.label', "Add Folder to {0}", 'Copilot Edits'),
category: CHAT_CATEGORY,
f1: false,
});
}

override async run(accessor: ServicesAccessor, ...args: any[]): Promise<void> {
const variablesService = accessor.get(IChatVariablesService);
const folders = this.getResources(accessor, ...args);

if (folders.length) {
(await showEditsView(accessor.get(IViewsService)))?.focusInput();
for (const folder of folders) {
variablesService.attachContext('folder', folder, ChatAgentLocation.EditingSession);
}
}
}
}

class AttachSelectionToEditingSessionAction extends Action2 {

static readonly ID = 'workbench.action.edits.attachSelection';
Expand Down
10 changes: 10 additions & 0 deletions src/vs/workbench/contrib/chat/browser/chatAttachmentModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ export class ChatAttachmentModel extends Disposable {
this.addContext(this.asVariableEntry(uri, range));
}

addFolder(uri: URI) {
this.addContext({
value: uri,
id: uri.toString(),
name: basename(uri),
isFile: false,
isDirectory: true,
});
}

asVariableEntry(uri: URI, range?: IRange, isMarkedReadonly?: boolean): IChatRequestVariableEntry {
return {
value: range ? { uri, range } : uri,
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/contrib/chat/browser/chatVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,10 @@ export class ChatVariablesService implements IChatVariablesService {
widget.attachmentModel.addFile(uri, range);
return;
}

if (key === 'folder' && URI.isUri(value)) {
widget.attachmentModel.addFolder(value);
return;
}
}
}
Loading