Skip to content

Commit 8098a78

Browse files
authored
Clean up chat submit actions (microsoft#209578)
* Align submit/send actions in chat * Clean up chat submit actions
1 parent 0da22a2 commit 8098a78

File tree

3 files changed

+68
-90
lines changed

3 files changed

+68
-90
lines changed

src/vs/workbench/contrib/chat/browser/actions/chatActions.ts

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ import { IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat';
2525
import { IChatEditorOptions } from 'vs/workbench/contrib/chat/browser/chatEditor';
2626
import { ChatEditorInput } from 'vs/workbench/contrib/chat/browser/chatEditorInput';
2727
import { ChatViewPane } from 'vs/workbench/contrib/chat/browser/chatViewPane';
28-
import { ChatAgentLocation, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
29-
import { CONTEXT_CHAT_INPUT_CURSOR_AT_TOP, CONTEXT_CHAT_INPUT_HAS_AGENT, CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_CHAT_LOCATION, CONTEXT_CHAT_REQUEST_IN_PROGRESS, CONTEXT_IN_CHAT_INPUT, CONTEXT_IN_CHAT_SESSION, CONTEXT_PROVIDER_EXISTS, CONTEXT_REQUEST, CONTEXT_RESPONSE } from 'vs/workbench/contrib/chat/common/chatContextKeys';
28+
import { ChatAgentLocation } from 'vs/workbench/contrib/chat/common/chatAgents';
29+
import { CONTEXT_CHAT_INPUT_CURSOR_AT_TOP, CONTEXT_CHAT_LOCATION, CONTEXT_IN_CHAT_INPUT, CONTEXT_IN_CHAT_SESSION, CONTEXT_PROVIDER_EXISTS, CONTEXT_REQUEST, CONTEXT_RESPONSE } from 'vs/workbench/contrib/chat/common/chatContextKeys';
3030
import { IChatContributionService } from 'vs/workbench/contrib/chat/common/chatContributionService';
31-
import { chatAgentLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
3231
import { IChatDetail, IChatService } from 'vs/workbench/contrib/chat/common/chatService';
3332
import { IChatWidgetHistoryService } from 'vs/workbench/contrib/chat/common/chatWidgetHistoryService';
3433
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
@@ -93,86 +92,8 @@ class OpenChatGlobalAction extends Action2 {
9392
}
9493
}
9594

96-
export class ChatSubmitSecondaryAgentEditorAction extends EditorAction2 {
97-
static readonly ID = 'workbench.action.chat.submitSecondaryAgent';
98-
99-
constructor() {
100-
super({
101-
id: ChatSubmitSecondaryAgentEditorAction.ID,
102-
title: localize2({ key: 'actions.chat.submitSecondaryAgent', comment: ['Send input from the chat input box to the secondary agent'] }, "Submit to Secondary Agent"),
103-
precondition: ContextKeyExpr.and(CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_CHAT_INPUT_HAS_AGENT.negate(), CONTEXT_CHAT_REQUEST_IN_PROGRESS.negate()),
104-
keybinding: {
105-
when: CONTEXT_IN_CHAT_INPUT,
106-
primary: KeyMod.CtrlCmd | KeyCode.Enter,
107-
weight: KeybindingWeight.EditorContrib
108-
},
109-
menu: {
110-
id: MenuId.ChatExecuteSecondary,
111-
group: 'group_1',
112-
when: CONTEXT_CHAT_INPUT_HAS_AGENT.negate(),
113-
}
114-
});
115-
}
116-
117-
runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor): void | Promise<void> {
118-
const editorUri = editor.getModel()?.uri;
119-
if (editorUri) {
120-
const agentService = accessor.get(IChatAgentService);
121-
const secondaryAgent = agentService.getSecondaryAgent();
122-
if (!secondaryAgent) {
123-
return;
124-
}
125-
126-
const widgetService = accessor.get(IChatWidgetService);
127-
const widget = widgetService.getWidgetByInputUri(editorUri);
128-
if (!widget) {
129-
return;
130-
}
131-
132-
if (widget.getInput().match(/^\s*@/)) {
133-
widget.acceptInput();
134-
} else {
135-
widget.acceptInputWithPrefix(`${chatAgentLeader}${secondaryAgent.name}`);
136-
}
137-
}
138-
}
139-
}
140-
141-
export class ChatSubmitEditorAction extends EditorAction2 {
142-
static readonly ID = 'workbench.action.chat.acceptInput';
143-
144-
constructor() {
145-
super({
146-
id: ChatSubmitEditorAction.ID,
147-
title: localize2({ key: 'actions.chat.submit', comment: ['Apply input from the chat input box'] }, "Submit"),
148-
precondition: CONTEXT_CHAT_INPUT_HAS_TEXT,
149-
keybinding: {
150-
when: CONTEXT_IN_CHAT_INPUT,
151-
primary: KeyCode.Enter,
152-
weight: KeybindingWeight.EditorContrib
153-
},
154-
menu: {
155-
id: MenuId.ChatExecuteSecondary,
156-
when: CONTEXT_CHAT_REQUEST_IN_PROGRESS.negate(),
157-
group: 'group_1',
158-
},
159-
});
160-
}
161-
162-
runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor): void | Promise<void> {
163-
const editorUri = editor.getModel()?.uri;
164-
if (editorUri) {
165-
const widgetService = accessor.get(IChatWidgetService);
166-
widgetService.getWidgetByInputUri(editorUri)?.acceptInput();
167-
}
168-
}
169-
}
170-
17195
export function registerChatActions() {
17296
registerAction2(OpenChatGlobalAction);
173-
registerAction2(ChatSubmitEditorAction);
174-
175-
registerAction2(ChatSubmitSecondaryAgentEditorAction);
17697

17798
registerAction2(class ClearChatInputHistoryAction extends Action2 {
17899
constructor() {

src/vs/workbench/contrib/chat/browser/actions/chatExecuteActions.ts

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1212
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
1313
import { CHAT_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
1414
import { IChatWidget, IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat';
15-
import { CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_CHAT_REQUEST_IN_PROGRESS, CONTEXT_IN_CHAT_INPUT } from 'vs/workbench/contrib/chat/common/chatContextKeys';
15+
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
16+
import { CONTEXT_CHAT_INPUT_HAS_AGENT, CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_CHAT_REQUEST_IN_PROGRESS, CONTEXT_IN_CHAT_INPUT } from 'vs/workbench/contrib/chat/common/chatContextKeys';
17+
import { chatAgentLeader, extractAgentAndCommand } from 'vs/workbench/contrib/chat/common/chatParserTypes';
1618
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService';
1719

1820
export interface IVoiceChatExecuteActionContext {
@@ -31,16 +33,27 @@ export class SubmitAction extends Action2 {
3133
constructor() {
3234
super({
3335
id: SubmitAction.ID,
34-
title: localize2('interactive.submit.label', "Submit"),
36+
title: localize2('interactive.submit.label', "Send"),
3537
f1: false,
3638
category: CHAT_CATEGORY,
3739
icon: Codicon.send,
3840
precondition: ContextKeyExpr.and(CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_CHAT_REQUEST_IN_PROGRESS.negate()),
39-
menu: {
40-
id: MenuId.ChatExecute,
41-
when: CONTEXT_CHAT_REQUEST_IN_PROGRESS.negate(),
42-
group: 'navigation',
41+
keybinding: {
42+
when: CONTEXT_IN_CHAT_INPUT,
43+
primary: KeyCode.Enter,
44+
weight: KeybindingWeight.EditorContrib
4345
},
46+
menu: [
47+
{
48+
id: MenuId.ChatExecuteSecondary,
49+
group: 'group_1',
50+
},
51+
{
52+
id: MenuId.ChatExecute,
53+
when: CONTEXT_CHAT_REQUEST_IN_PROGRESS.negate(),
54+
group: 'navigation',
55+
},
56+
]
4457
});
4558
}
4659

@@ -53,6 +66,50 @@ export class SubmitAction extends Action2 {
5366
}
5467
}
5568

69+
70+
export class ChatSubmitSecondaryAgentAction extends Action2 {
71+
static readonly ID = 'workbench.action.chat.submitSecondaryAgent';
72+
73+
constructor() {
74+
super({
75+
id: ChatSubmitSecondaryAgentAction.ID,
76+
title: localize2({ key: 'actions.chat.submitSecondaryAgent', comment: ['Send input from the chat input box to the secondary agent'] }, "Submit to Secondary Agent"),
77+
precondition: ContextKeyExpr.and(CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_CHAT_INPUT_HAS_AGENT.negate(), CONTEXT_CHAT_REQUEST_IN_PROGRESS.negate()),
78+
keybinding: {
79+
when: CONTEXT_IN_CHAT_INPUT,
80+
primary: KeyMod.CtrlCmd | KeyCode.Enter,
81+
weight: KeybindingWeight.EditorContrib
82+
},
83+
menu: {
84+
id: MenuId.ChatExecuteSecondary,
85+
group: 'group_1'
86+
}
87+
});
88+
}
89+
90+
run(accessor: ServicesAccessor, ...args: any[]) {
91+
const context: IChatExecuteActionContext | undefined = args[0];
92+
const agentService = accessor.get(IChatAgentService);
93+
const secondaryAgent = agentService.getSecondaryAgent();
94+
if (!secondaryAgent) {
95+
return;
96+
}
97+
98+
const widgetService = accessor.get(IChatWidgetService);
99+
const widget = context?.widget ?? widgetService.lastFocusedWidget;
100+
if (!widget) {
101+
return;
102+
}
103+
104+
if (extractAgentAndCommand(widget.parsedInput).agentPart) {
105+
widget.acceptInput();
106+
} else {
107+
widget.lastSelectedAgent = secondaryAgent;
108+
widget.acceptInputWithPrefix(`${chatAgentLeader}${secondaryAgent.name}`);
109+
}
110+
}
111+
}
112+
56113
class SendToNewChatAction extends Action2 {
57114
constructor() {
58115
super({
@@ -121,4 +178,5 @@ export function registerChatExecuteActions() {
121178
registerAction2(SubmitAction);
122179
registerAction2(CancelAction);
123180
registerAction2(SendToNewChatAction);
181+
registerAction2(ChatSubmitSecondaryAgentAction);
124182
}

src/vs/workbench/contrib/chat/browser/chatInputPart.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ import { asCssVariableWithDefault, checkboxBorder, inputBackground } from 'vs/pl
4242
import { IThemeService } from 'vs/platform/theme/common/themeService';
4343
import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityConfiguration';
4444
import { AccessibilityCommandId } from 'vs/workbench/contrib/accessibility/common/accessibilityCommands';
45-
import { ChatSubmitSecondaryAgentEditorAction } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
46-
import { CancelAction, IChatExecuteActionContext, SubmitAction } from 'vs/workbench/contrib/chat/browser/actions/chatExecuteActions';
45+
import { CancelAction, ChatSubmitSecondaryAgentAction, IChatExecuteActionContext, SubmitAction } from 'vs/workbench/contrib/chat/browser/actions/chatExecuteActions';
4746
import { IChatWidget } from 'vs/workbench/contrib/chat/browser/chat';
4847
import { ChatFollowups } from 'vs/workbench/contrib/chat/browser/chatFollowups';
4948
import { ChatAgentLocation, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
@@ -540,7 +539,7 @@ class ChatSubmitDropdownActionItem extends DropdownWithPrimaryActionViewItem {
540539
const secondaryAgent = chatAgentService.getSecondaryAgent();
541540
if (secondaryAgent) {
542541
secondary.forEach(a => {
543-
if (a.id === ChatSubmitSecondaryAgentEditorAction.ID) {
542+
if (a.id === ChatSubmitSecondaryAgentAction.ID) {
544543
a.label = localize('chat.submitToSecondaryAgent', "Send to @{0}", secondaryAgent.name);
545544
}
546545

0 commit comments

Comments
 (0)