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

Allow attaching variable ids to chat open command args #233108

Merged
merged 1 commit into from
Nov 5, 2024
Merged
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
22 changes: 22 additions & 0 deletions src/vs/workbench/contrib/chat/browser/actions/chatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
Loading