From fb9e8607f2efabac64e32e0d200acb25e19d4273 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 5 Nov 2024 08:19:38 -0800 Subject: [PATCH] Allow attaching variable ids to chat open command args Part of microsoft/vscode-copilot#10125 --- .../chat/browser/actions/chatActions.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts b/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts index 1ff71973a1a5f..303f34cbc2624 100644 --- a/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts +++ b/src/vs/workbench/contrib/chat/browser/actions/chatActions.ts @@ -49,6 +49,7 @@ import { URI } from '../../../../../base/common/uri.js'; import { IHostService } from '../../../../services/host/browser/host.js'; import { isCancellationError } from '../../../../../base/common/errors.js'; import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js'; +import { IChatVariablesService } from '../../common/chatVariables.js'; export const CHAT_CATEGORY = localize2('chat.category', 'Chat'); export const CHAT_OPEN_ACTION_ID = 'workbench.action.chat.open'; @@ -62,6 +63,10 @@ export interface IChatViewOpenOptions { * Whether the query is partial and will await more input from the user. */ isPartialQuery?: boolean; + /** + * A list of simple variables that will be resolved and attached if they exist. + */ + variableIds?: string[]; /** * Any previous chat requests and responses that should be shown in the chat view. */ @@ -117,8 +122,10 @@ class OpenChatGlobalAction extends Action2 { opts = typeof opts === 'string' ? { query: opts } : opts; const chatService = accessor.get(IChatService); + const chatVariablesService = accessor.get(IChatVariablesService); const viewsService = accessor.get(IViewsService); const hostService = accessor.get(IHostService); + const chatWidget = await showChatView(viewsService); if (!chatWidget) { return; @@ -141,6 +148,21 @@ class OpenChatGlobalAction extends Action2 { chatWidget.acceptInput(opts.query); } } + if (opts?.variableIds && opts.variableIds.length > 0) { + const actualVariables = chatVariablesService.getVariables(ChatAgentLocation.Panel); + for (const actualVariable of actualVariables) { + if (opts.variableIds.includes(actualVariable.id)) { + chatWidget.attachmentModel.addContext({ + range: undefined, + id: actualVariable.id ?? '', + value: undefined, + fullName: actualVariable.fullName, + name: actualVariable.name, + icon: actualVariable.icon + }); + } + } + } chatWidget.focusInput(); }