Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Codicon } from '../../../../../base/common/codicons.js';
7
import { KeyCode, KeyMod } from '../../../../../base/common/keyCodes.js';
8
import { Selection } from '../../../../../editor/common/core/selection.js';
9
import { localize, localize2 } from '../../../../../nls.js';
10
import { Action2, MenuId, registerAction2 } from '../../../../../platform/actions/common/actions.js';
11
import { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
12
import { KeybindingWeight } from '../../../../../platform/keybinding/common/keybindingsRegistry.js';
13
import { CHAT_CATEGORY } from './chatActions.js';
14
import { IQuickChatOpenOptions, IQuickChatService } from '../chat.js';
15
import { ChatContextKeys } from '../../common/chatContextKeys.js';
16
17
export const ASK_QUICK_QUESTION_ACTION_ID = 'workbench.action.quickchat.toggle';
18
export function registerQuickChatActions() {
19
registerAction2(QuickChatGlobalAction);
20
registerAction2(AskQuickChatAction);
21
22
registerAction2(class OpenInChatViewAction extends Action2 {
23
constructor() {
24
super({
25
id: 'workbench.action.quickchat.openInChatView',
26
title: localize2('chat.openInChatView.label', "Open in Chat View"),
27
f1: false,
28
category: CHAT_CATEGORY,
29
icon: Codicon.chatSparkle,
30
menu: {
31
id: MenuId.ChatInputSide,
32
group: 'navigation',
33
order: 10
34
}
35
});
36
}
37
38
run(accessor: ServicesAccessor) {
39
const quickChatService = accessor.get(IQuickChatService);
40
quickChatService.openInChatView();
41
}
42
});
43
44
registerAction2(class CloseQuickChatAction extends Action2 {
45
constructor() {
46
super({
47
id: 'workbench.action.quickchat.close',
48
title: localize2('chat.closeQuickChat.label', "Close Quick Chat"),
49
f1: false,
50
category: CHAT_CATEGORY,
51
icon: Codicon.close,
52
menu: {
53
id: MenuId.ChatInputSide,
54
group: 'navigation',
55
order: 20
56
}
57
});
58
}
59
60
run(accessor: ServicesAccessor) {
61
const quickChatService = accessor.get(IQuickChatService);
62
quickChatService.close();
63
}
64
});
65
66
}
67
68
class QuickChatGlobalAction extends Action2 {
69
constructor() {
70
super({
71
id: ASK_QUICK_QUESTION_ACTION_ID,
72
title: localize2('quickChat', 'Open Quick Chat'),
73
precondition: ChatContextKeys.enabled,
74
icon: Codicon.chatSparkle,
75
f1: false,
76
category: CHAT_CATEGORY,
77
keybinding: {
78
weight: KeybindingWeight.WorkbenchContrib,
79
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyMod.Alt | KeyCode.KeyL,
80
},
81
menu: {
82
id: MenuId.ChatTitleBarMenu,
83
group: 'a_open',
84
order: 4
85
},
86
metadata: {
87
description: localize('toggle.desc', 'Toggle the quick chat'),
88
args: [{
89
name: 'args',
90
schema: {
91
anyOf: [
92
{
93
type: 'object',
94
required: ['query'],
95
properties: {
96
query: {
97
description: localize('toggle.query', "The query to open the quick chat with"),
98
type: 'string'
99
},
100
isPartialQuery: {
101
description: localize('toggle.isPartialQuery', "Whether the query is partial; it will wait for more user input"),
102
type: 'boolean'
103
}
104
},
105
},
106
{
107
type: 'string',
108
description: localize('toggle.query', "The query to open the quick chat with")
109
}
110
]
111
}
112
}]
113
},
114
});
115
}
116
117
override run(accessor: ServicesAccessor, query?: string | Omit<IQuickChatOpenOptions, 'selection'>): void {
118
const quickChatService = accessor.get(IQuickChatService);
119
let options: IQuickChatOpenOptions | undefined;
120
switch (typeof query) {
121
case 'string': options = { query }; break;
122
case 'object': options = query; break;
123
}
124
if (options?.query) {
125
options.selection = new Selection(1, options.query.length + 1, 1, options.query.length + 1);
126
}
127
quickChatService.toggle(options);
128
}
129
}
130
131
class AskQuickChatAction extends Action2 {
132
constructor() {
133
super({
134
id: `workbench.action.openQuickChat`,
135
category: CHAT_CATEGORY,
136
title: localize2('interactiveSession.open', "Open Quick Chat"),
137
precondition: ChatContextKeys.enabled,
138
f1: true
139
});
140
}
141
142
override run(accessor: ServicesAccessor, query?: string): void {
143
const quickChatService = accessor.get(IQuickChatService);
144
quickChatService.toggle(query ? {
145
query,
146
selection: new Selection(1, query.length + 1, 1, query.length + 1)
147
} : undefined);
148
}
149
}
150
151