@codingame/monaco-vscode-chat-service-override 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/chat.js +9 -9
  2. package/package.json +2 -2
  3. package/external/tslib/tslib.es6.js +0 -11
  4. package/external/vscode-marked/lib/marked.esm.js +0 -2200
  5. package/override/vs/platform/dialogs/common/dialogs.js +0 -10
  6. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClear.js +0 -17
  7. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClearActions.js +0 -115
  8. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +0 -503
  9. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +0 -82
  10. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +0 -77
  11. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.js +0 -110
  12. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.js +0 -171
  13. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatTitleActions.js +0 -271
  14. package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +0 -317
  15. package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.js +0 -60
  16. package/vscode/src/vs/workbench/contrib/chat/browser/chatContributionServiceImpl.js +0 -423
  17. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +0 -98
  18. package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +0 -285
  19. package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +0 -90
  20. package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +0 -185
  21. package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatHistoryVariables.js +0 -26
  22. package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +0 -618
  23. package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +0 -600
  24. package/vscode/src/vs/workbench/contrib/chat/common/voiceChat.js +0 -141
  25. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +0 -40
  26. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibleView.js +0 -41
  27. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatNotebook.js +0 -72
  28. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl.js +0 -236
  29. package/vscode/src/vs/workbench/contrib/inlineChat/common/inlineChatServiceImpl.js +0 -33
@@ -1,10 +0,0 @@
1
- export { AbstractDialogHandler, IDialogService, IFileDialogService, getFileNamesMessage } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
2
-
3
- var ConfirmResult;
4
- ( (function(ConfirmResult) {
5
- ConfirmResult[ConfirmResult["SAVE"] = 0] = "SAVE";
6
- ConfirmResult[ConfirmResult["DONT_SAVE"] = 1] = "DONT_SAVE";
7
- ConfirmResult[ConfirmResult["CANCEL"] = 2] = "CANCEL";
8
- })(ConfirmResult || (ConfirmResult = {})));
9
-
10
- export { ConfirmResult };
@@ -1,17 +0,0 @@
1
- import { ChatEditorInput } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chatEditorInput';
2
- import { IEditorGroupsService } from 'vscode/vscode/vs/workbench/services/editor/common/editorGroupsService';
3
- import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
4
-
5
- async function clearChatEditor(accessor) {
6
- const editorService = accessor.get(IEditorService);
7
- const editorGroupsService = accessor.get(IEditorGroupsService);
8
- const chatEditorInput = editorService.activeEditor;
9
- if (chatEditorInput instanceof ChatEditorInput && chatEditorInput.providerId) {
10
- await editorService.replaceEditors([{
11
- editor: chatEditorInput,
12
- replacement: { resource: ChatEditorInput.getNewEditorUri(), options: { target: { providerId: chatEditorInput.providerId, pinned: true } } }
13
- }], editorGroupsService.activeGroup);
14
- }
15
- }
16
-
17
- export { clearChatEditor };
@@ -1,115 +0,0 @@
1
- import { Codicon } from 'vscode/vscode/vs/base/common/codicons';
2
- import { localize2WithPath } from 'vscode/vscode/vs/nls';
3
- import { registerAction2, Action2, MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
4
- import { IAccessibilitySignalService, AccessibilitySignal } from 'vscode/vscode/vs/platform/accessibilitySignal/browser/accessibilitySignalService';
5
- import { ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
6
- import { ViewAction } from 'vscode/vscode/vs/workbench/browser/parts/views/viewPane';
7
- import { ActiveEditorContext } from 'vscode/vscode/vs/workbench/common/contextkeys';
8
- import { CHAT_CATEGORY } from 'vscode/vscode/vs/workbench/contrib/chat/browser/actions/chatActions';
9
- import { clearChatEditor } from './chatClear.js';
10
- import { IChatWidgetService } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chat';
11
- import { ChatEditorInput } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chatEditorInput';
12
- import { CONTEXT_PROVIDER_EXISTS, CONTEXT_IN_CHAT_SESSION } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatContextKeys';
13
-
14
- const ACTION_ID_NEW_CHAT = `workbench.action.chat.newChat`;
15
- function registerNewChatActions() {
16
- registerAction2(class NewChatEditorAction extends Action2 {
17
- constructor() {
18
- super({
19
- id: 'workbench.action.chatEditor.newChat',
20
- title: ( localize2WithPath(
21
- 'vs/workbench/contrib/chat/browser/actions/chatClearActions',
22
- 'chat.newChat.label',
23
- "New Chat"
24
- )),
25
- icon: Codicon.plus,
26
- f1: false,
27
- precondition: CONTEXT_PROVIDER_EXISTS,
28
- menu: [{
29
- id: MenuId.EditorTitle,
30
- group: 'navigation',
31
- order: 0,
32
- when: ( ActiveEditorContext.isEqualTo(ChatEditorInput.EditorID)),
33
- }]
34
- });
35
- }
36
- async run(accessor, ...args) {
37
- announceChatCleared(accessor);
38
- await clearChatEditor(accessor);
39
- }
40
- });
41
- registerAction2(class GlobalClearChatAction extends Action2 {
42
- constructor() {
43
- super({
44
- id: ACTION_ID_NEW_CHAT,
45
- title: ( localize2WithPath(
46
- 'vs/workbench/contrib/chat/browser/actions/chatClearActions',
47
- 'chat.newChat.label',
48
- "New Chat"
49
- )),
50
- category: CHAT_CATEGORY,
51
- icon: Codicon.plus,
52
- precondition: CONTEXT_PROVIDER_EXISTS,
53
- f1: true,
54
- keybinding: {
55
- weight: 200 ,
56
- primary: 2048 | 42 ,
57
- mac: {
58
- primary: 256 | 42
59
- },
60
- when: CONTEXT_IN_CHAT_SESSION
61
- },
62
- menu: {
63
- id: MenuId.ChatContext,
64
- group: 'z_clear'
65
- }
66
- });
67
- }
68
- run(accessor, ...args) {
69
- const widgetService = accessor.get(IChatWidgetService);
70
- const widget = widgetService.lastFocusedWidget;
71
- if (!widget) {
72
- return;
73
- }
74
- announceChatCleared(accessor);
75
- widget.clear();
76
- widget.focusInput();
77
- }
78
- });
79
- }
80
- const getNewChatActionDescriptorForViewTitle = (viewId, providerId) => ({
81
- viewId,
82
- id: `workbench.action.chat.${providerId}.newChat`,
83
- title: ( localize2WithPath(
84
- 'vs/workbench/contrib/chat/browser/actions/chatClearActions',
85
- 'chat.newChat.label',
86
- "New Chat"
87
- )),
88
- menu: {
89
- id: MenuId.ViewTitle,
90
- when: ( ContextKeyExpr.equals('view', viewId)),
91
- group: 'navigation',
92
- order: -1
93
- },
94
- precondition: CONTEXT_PROVIDER_EXISTS,
95
- category: CHAT_CATEGORY,
96
- icon: Codicon.plus,
97
- f1: false
98
- });
99
- function getNewChatAction(viewId, providerId) {
100
- return class NewChatAction extends ViewAction {
101
- constructor() {
102
- super(getNewChatActionDescriptorForViewTitle(viewId, providerId));
103
- }
104
- async runInView(accessor, view) {
105
- announceChatCleared(accessor);
106
- await view.clear();
107
- view.widget.focusInput();
108
- }
109
- };
110
- }
111
- function announceChatCleared(accessor) {
112
- accessor.get(IAccessibilitySignalService).playSignal(AccessibilitySignal.clear);
113
- }
114
-
115
- export { ACTION_ID_NEW_CHAT, getNewChatAction, registerNewChatActions };
@@ -1,503 +0,0 @@
1
- import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
2
- import { Codicon } from 'vscode/vscode/vs/base/common/codicons';
3
- import { isDiffEditor, isCodeEditor } from 'vscode/vscode/vs/editor/browser/editorBrowser';
4
- import { IBulkEditService, ResourceTextEdit } from 'vscode/vscode/vs/editor/browser/services/bulkEditService';
5
- import { ICodeEditorService } from 'vscode/vscode/vs/editor/browser/services/codeEditorService';
6
- import { Range } from 'vscode/vscode/vs/editor/common/core/range';
7
- import { EditorContextKeys } from 'vscode/vscode/vs/editor/common/editorContextKeys';
8
- import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
9
- import { ILanguageFeaturesService } from 'vscode/vscode/vs/editor/common/services/languageFeatures';
10
- import { CopyAction } from 'vscode/vscode/vs/editor/contrib/clipboard/browser/clipboard';
11
- import { localize2WithPath } from 'vscode/vscode/vs/nls';
12
- import { registerAction2, Action2, MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
13
- import { IClipboardService } from 'vscode/vscode/vs/platform/clipboard/common/clipboardService';
14
- import { ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
15
- import { TerminalLocation } from 'vscode/vscode/vs/platform/terminal/common/terminal';
16
- import { accessibleViewInCodeBlock } from 'vscode/vscode/vs/workbench/contrib/accessibility/browser/accessibilityConfiguration';
17
- import { CHAT_CATEGORY } from 'vscode/vscode/vs/workbench/contrib/chat/browser/actions/chatActions';
18
- import { IChatWidgetService, IChatCodeBlockContextProviderService } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chat';
19
- import { CONTEXT_PROVIDER_EXISTS, CONTEXT_IN_CHAT_SESSION, CONTEXT_IN_CHAT_INPUT } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatContextKeys';
20
- import { IChatService, ChatCopyKind } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatService';
21
- import { isResponseVM } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatViewModel';
22
- import { insertCell } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/controller/cellOperations';
23
- import { NOTEBOOK_EDITOR_ID, CellKind } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
24
- import { ITerminalService, ITerminalEditorService, ITerminalGroupService } from 'vscode/vscode/vs/workbench/contrib/terminal/browser/terminal';
25
- import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
26
- import { ITextFileService } from 'vscode/vscode/vs/workbench/services/textfile/common/textfiles';
27
-
28
- function isCodeBlockActionContext(thing) {
29
- return typeof thing === 'object' && thing !== null && 'code' in thing && 'element' in thing;
30
- }
31
- function isResponseFiltered(context) {
32
- return isResponseVM(context.element) && context.element.errorDetails?.responseIsFiltered;
33
- }
34
- function getUsedDocuments(context) {
35
- return isResponseVM(context.element) ? context.element.usedContext?.documents : undefined;
36
- }
37
- class ChatCodeBlockAction extends Action2 {
38
- run(accessor, ...args) {
39
- let context = args[0];
40
- if (!isCodeBlockActionContext(context)) {
41
- const codeEditorService = accessor.get(ICodeEditorService);
42
- const editor = codeEditorService.getFocusedCodeEditor() || codeEditorService.getActiveCodeEditor();
43
- if (!editor) {
44
- return;
45
- }
46
- context = getContextFromEditor(editor, accessor);
47
- if (!isCodeBlockActionContext(context)) {
48
- return;
49
- }
50
- }
51
- return this.runWithContext(accessor, context);
52
- }
53
- }
54
- function registerChatCodeBlockActions() {
55
- registerAction2(class CopyCodeBlockAction extends Action2 {
56
- constructor() {
57
- super({
58
- id: 'workbench.action.chat.copyCodeBlock',
59
- title: ( localize2WithPath(
60
- 'vs/workbench/contrib/chat/browser/actions/chatCodeblockActions',
61
- 'interactive.copyCodeBlock.label',
62
- "Copy"
63
- )),
64
- f1: false,
65
- category: CHAT_CATEGORY,
66
- icon: Codicon.copy,
67
- menu: {
68
- id: MenuId.ChatCodeBlock,
69
- group: 'navigation'
70
- }
71
- });
72
- }
73
- run(accessor, ...args) {
74
- const context = args[0];
75
- if (!isCodeBlockActionContext(context) || isResponseFiltered(context)) {
76
- return;
77
- }
78
- const clipboardService = accessor.get(IClipboardService);
79
- clipboardService.writeText(context.code);
80
- if (isResponseVM(context.element)) {
81
- const chatService = accessor.get(IChatService);
82
- chatService.notifyUserAction({
83
- providerId: context.element.providerId,
84
- agentId: context.element.agent?.id,
85
- sessionId: context.element.sessionId,
86
- requestId: context.element.requestId,
87
- result: context.element.result,
88
- action: {
89
- kind: 'copy',
90
- codeBlockIndex: context.codeBlockIndex,
91
- copyKind: ChatCopyKind.Toolbar,
92
- copiedCharacters: context.code.length,
93
- totalCharacters: context.code.length,
94
- copiedText: context.code,
95
- }
96
- });
97
- }
98
- }
99
- });
100
- CopyAction?.addImplementation(50000, 'chat-codeblock', (accessor) => {
101
- const editor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
102
- if (!editor) {
103
- return false;
104
- }
105
- const editorModel = editor.getModel();
106
- if (!editorModel) {
107
- return false;
108
- }
109
- const context = getContextFromEditor(editor, accessor);
110
- if (!context) {
111
- return false;
112
- }
113
- const noSelection = editor.getSelections()?.length === 1 && editor.getSelection()?.isEmpty();
114
- const copiedText = noSelection ?
115
- editorModel.getValue() :
116
- editor.getSelections()?.reduce((acc, selection) => acc + editorModel.getValueInRange(selection), '') ?? '';
117
- const totalCharacters = editorModel.getValueLength();
118
- const chatService = accessor.get(IChatService);
119
- const element = context.element;
120
- if (element) {
121
- chatService.notifyUserAction({
122
- providerId: element.providerId,
123
- agentId: element.agent?.id,
124
- sessionId: element.sessionId,
125
- requestId: element.requestId,
126
- result: element.result,
127
- action: {
128
- kind: 'copy',
129
- codeBlockIndex: context.codeBlockIndex,
130
- copyKind: ChatCopyKind.Action,
131
- copiedText,
132
- copiedCharacters: copiedText.length,
133
- totalCharacters,
134
- }
135
- });
136
- }
137
- if (noSelection) {
138
- accessor.get(IClipboardService).writeText(context.code);
139
- return true;
140
- }
141
- return false;
142
- });
143
- registerAction2(class InsertCodeBlockAction extends ChatCodeBlockAction {
144
- constructor() {
145
- super({
146
- id: 'workbench.action.chat.insertCodeBlock',
147
- title: ( localize2WithPath(
148
- 'vs/workbench/contrib/chat/browser/actions/chatCodeblockActions',
149
- 'interactive.insertCodeBlock.label',
150
- "Insert at Cursor"
151
- )),
152
- precondition: CONTEXT_PROVIDER_EXISTS,
153
- f1: true,
154
- category: CHAT_CATEGORY,
155
- icon: Codicon.insert,
156
- menu: {
157
- id: MenuId.ChatCodeBlock,
158
- group: 'navigation',
159
- when: CONTEXT_IN_CHAT_SESSION
160
- },
161
- keybinding: {
162
- when: ( ContextKeyExpr.or(( ContextKeyExpr.and(CONTEXT_IN_CHAT_SESSION, ( CONTEXT_IN_CHAT_INPUT.negate()))), accessibleViewInCodeBlock)),
163
- primary: 2048 | 3 ,
164
- mac: { primary: 256 | 3 },
165
- weight: 400 + 1
166
- },
167
- });
168
- }
169
- async runWithContext(accessor, context) {
170
- const editorService = accessor.get(IEditorService);
171
- const textFileService = accessor.get(ITextFileService);
172
- if (isResponseFiltered(context)) {
173
- return;
174
- }
175
- if (editorService.activeEditorPane?.getId() === NOTEBOOK_EDITOR_ID) {
176
- return this.handleNotebookEditor(accessor, editorService.activeEditorPane.getControl(), context);
177
- }
178
- let activeEditorControl = editorService.activeTextEditorControl;
179
- if (isDiffEditor(activeEditorControl)) {
180
- activeEditorControl = activeEditorControl.getOriginalEditor().hasTextFocus() ? activeEditorControl.getOriginalEditor() : activeEditorControl.getModifiedEditor();
181
- }
182
- if (!isCodeEditor(activeEditorControl)) {
183
- return;
184
- }
185
- const activeModel = activeEditorControl.getModel();
186
- if (!activeModel) {
187
- return;
188
- }
189
- const activeTextModel = textFileService.files.get(activeModel.uri) ?? textFileService.untitled.get(activeModel.uri);
190
- if (!activeTextModel || activeTextModel.isReadonly()) {
191
- return;
192
- }
193
- await this.handleTextEditor(accessor, activeEditorControl, activeModel, context);
194
- }
195
- async handleNotebookEditor(accessor, notebookEditor, context) {
196
- if (!notebookEditor.hasModel()) {
197
- return;
198
- }
199
- if (notebookEditor.isReadOnly) {
200
- return;
201
- }
202
- if (notebookEditor.activeCodeEditor?.hasTextFocus()) {
203
- const codeEditor = notebookEditor.activeCodeEditor;
204
- const textModel = codeEditor.getModel();
205
- if (textModel) {
206
- return this.handleTextEditor(accessor, codeEditor, textModel, context);
207
- }
208
- }
209
- const languageService = accessor.get(ILanguageService);
210
- const focusRange = notebookEditor.getFocus();
211
- const next = Math.max(focusRange.end - 1, 0);
212
- insertCell(languageService, notebookEditor, next, CellKind.Code, 'below', context.code, true);
213
- this.notifyUserAction(accessor, context);
214
- }
215
- async handleTextEditor(accessor, codeEditor, activeModel, codeBlockActionContext) {
216
- this.notifyUserAction(accessor, codeBlockActionContext);
217
- const bulkEditService = accessor.get(IBulkEditService);
218
- const codeEditorService = accessor.get(ICodeEditorService);
219
- const mappedEditsProviders = accessor.get(ILanguageFeaturesService).mappedEditsProvider.ordered(activeModel);
220
- let mappedEdits = null;
221
- if (mappedEditsProviders.length > 0) {
222
- const mostRelevantProvider = mappedEditsProviders[0];
223
- const docRefs = [];
224
- if (codeEditor.hasModel()) {
225
- const model = codeEditor.getModel();
226
- const currentDocUri = model.uri;
227
- const currentDocVersion = model.getVersionId();
228
- const selections = codeEditor.getSelections();
229
- if (selections.length > 0) {
230
- docRefs.push([
231
- {
232
- uri: currentDocUri,
233
- version: currentDocVersion,
234
- ranges: selections,
235
- }
236
- ]);
237
- }
238
- }
239
- const usedDocuments = getUsedDocuments(codeBlockActionContext);
240
- if (usedDocuments) {
241
- docRefs.push(usedDocuments);
242
- }
243
- const cancellationTokenSource = ( new CancellationTokenSource());
244
- mappedEdits = await mostRelevantProvider.provideMappedEdits(activeModel, [codeBlockActionContext.code], { documents: docRefs }, cancellationTokenSource.token);
245
- }
246
- if (mappedEdits) {
247
- await bulkEditService.apply(mappedEdits);
248
- }
249
- else {
250
- const activeSelection = codeEditor.getSelection() ?? ( new Range(activeModel.getLineCount(), 1, activeModel.getLineCount(), 1));
251
- await bulkEditService.apply([
252
- ( new ResourceTextEdit(activeModel.uri, {
253
- range: activeSelection,
254
- text: codeBlockActionContext.code,
255
- })),
256
- ]);
257
- }
258
- codeEditorService.listCodeEditors().find(editor => editor.getModel()?.uri.toString() === ( activeModel.uri.toString()))?.focus();
259
- }
260
- notifyUserAction(accessor, context) {
261
- if (isResponseVM(context.element)) {
262
- const chatService = accessor.get(IChatService);
263
- chatService.notifyUserAction({
264
- providerId: context.element.providerId,
265
- agentId: context.element.agent?.id,
266
- sessionId: context.element.sessionId,
267
- requestId: context.element.requestId,
268
- result: context.element.result,
269
- action: {
270
- kind: 'insert',
271
- codeBlockIndex: context.codeBlockIndex,
272
- totalCharacters: context.code.length,
273
- }
274
- });
275
- }
276
- }
277
- });
278
- registerAction2(class InsertIntoNewFileAction extends ChatCodeBlockAction {
279
- constructor() {
280
- super({
281
- id: 'workbench.action.chat.insertIntoNewFile',
282
- title: ( localize2WithPath(
283
- 'vs/workbench/contrib/chat/browser/actions/chatCodeblockActions',
284
- 'interactive.insertIntoNewFile.label',
285
- "Insert into New File"
286
- )),
287
- precondition: CONTEXT_PROVIDER_EXISTS,
288
- f1: true,
289
- category: CHAT_CATEGORY,
290
- icon: Codicon.newFile,
291
- menu: {
292
- id: MenuId.ChatCodeBlock,
293
- group: 'navigation',
294
- isHiddenByDefault: true
295
- }
296
- });
297
- }
298
- async runWithContext(accessor, context) {
299
- if (isResponseFiltered(context)) {
300
- return;
301
- }
302
- const editorService = accessor.get(IEditorService);
303
- const chatService = accessor.get(IChatService);
304
- editorService.openEditor({ contents: context.code, languageId: context.languageId, resource: undefined });
305
- if (isResponseVM(context.element)) {
306
- chatService.notifyUserAction({
307
- providerId: context.element.providerId,
308
- agentId: context.element.agent?.id,
309
- sessionId: context.element.sessionId,
310
- requestId: context.element.requestId,
311
- result: context.element.result,
312
- action: {
313
- kind: 'insert',
314
- codeBlockIndex: context.codeBlockIndex,
315
- totalCharacters: context.code.length,
316
- newFile: true
317
- }
318
- });
319
- }
320
- }
321
- });
322
- const shellLangIds = [
323
- 'fish',
324
- 'ps1',
325
- 'pwsh',
326
- 'powershell',
327
- 'sh',
328
- 'shellscript',
329
- 'zsh'
330
- ];
331
- registerAction2(class RunInTerminalAction extends ChatCodeBlockAction {
332
- constructor() {
333
- super({
334
- id: 'workbench.action.chat.runInTerminal',
335
- title: ( localize2WithPath(
336
- 'vs/workbench/contrib/chat/browser/actions/chatCodeblockActions',
337
- 'interactive.runInTerminal.label',
338
- "Insert into Terminal"
339
- )),
340
- precondition: CONTEXT_PROVIDER_EXISTS,
341
- f1: true,
342
- category: CHAT_CATEGORY,
343
- icon: Codicon.terminal,
344
- menu: [{
345
- id: MenuId.ChatCodeBlock,
346
- group: 'navigation',
347
- when: ( ContextKeyExpr.and(CONTEXT_IN_CHAT_SESSION, ( ContextKeyExpr.or(...( shellLangIds.map(e => ( ContextKeyExpr.equals(EditorContextKeys.languageId.key, e)))))))),
348
- },
349
- {
350
- id: MenuId.ChatCodeBlock,
351
- group: 'navigation',
352
- isHiddenByDefault: true,
353
- when: ( ContextKeyExpr.and(CONTEXT_IN_CHAT_SESSION, ...( shellLangIds.map(e => ( ContextKeyExpr.notEquals(EditorContextKeys.languageId.key, e))))))
354
- }],
355
- keybinding: [{
356
- primary: 2048 | 512 | 3 ,
357
- mac: {
358
- primary: 256 | 512 | 3
359
- },
360
- weight: 100 ,
361
- when: ( ContextKeyExpr.or(CONTEXT_IN_CHAT_SESSION, accessibleViewInCodeBlock)),
362
- }]
363
- });
364
- }
365
- async runWithContext(accessor, context) {
366
- if (isResponseFiltered(context)) {
367
- return;
368
- }
369
- const chatService = accessor.get(IChatService);
370
- const terminalService = accessor.get(ITerminalService);
371
- const editorService = accessor.get(IEditorService);
372
- const terminalEditorService = accessor.get(ITerminalEditorService);
373
- const terminalGroupService = accessor.get(ITerminalGroupService);
374
- let terminal = await terminalService.getActiveOrCreateInstance();
375
- const unusableTerminal = terminal.xterm?.isStdinDisabled || terminal.shellLaunchConfig.isFeatureTerminal;
376
- terminal = unusableTerminal ? await terminalService.createTerminal() : terminal;
377
- terminalService.setActiveInstance(terminal);
378
- await terminal.focusWhenReady(true);
379
- if (terminal.target === TerminalLocation.Editor) {
380
- const existingEditors = editorService.findEditors(terminal.resource);
381
- terminalEditorService.openEditor(terminal, { viewColumn: existingEditors?.[0].groupId });
382
- }
383
- else {
384
- terminalGroupService.showPanel(true);
385
- }
386
- terminal.runCommand(context.code, false);
387
- if (isResponseVM(context.element)) {
388
- chatService.notifyUserAction({
389
- providerId: context.element.providerId,
390
- agentId: context.element.agent?.id,
391
- sessionId: context.element.sessionId,
392
- requestId: context.element.requestId,
393
- result: context.element.result,
394
- action: {
395
- kind: 'runInTerminal',
396
- codeBlockIndex: context.codeBlockIndex,
397
- languageId: context.languageId,
398
- }
399
- });
400
- }
401
- }
402
- });
403
- function navigateCodeBlocks(accessor, reverse) {
404
- const codeEditorService = accessor.get(ICodeEditorService);
405
- const chatWidgetService = accessor.get(IChatWidgetService);
406
- const widget = chatWidgetService.lastFocusedWidget;
407
- if (!widget) {
408
- return;
409
- }
410
- const editor = codeEditorService.getFocusedCodeEditor();
411
- const editorUri = editor?.getModel()?.uri;
412
- const curCodeBlockInfo = editorUri ? widget.getCodeBlockInfoForEditor(editorUri) : undefined;
413
- const focused = !widget.inputEditor.hasWidgetFocus() && widget.getFocus();
414
- const focusedResponse = isResponseVM(focused) ? focused : undefined;
415
- const currentResponse = curCodeBlockInfo ?
416
- curCodeBlockInfo.element :
417
- (focusedResponse ?? widget.viewModel?.getItems().reverse().find((item) => isResponseVM(item)));
418
- if (!currentResponse) {
419
- return;
420
- }
421
- widget.reveal(currentResponse);
422
- const responseCodeblocks = widget.getCodeBlockInfosForResponse(currentResponse);
423
- const focusIdx = curCodeBlockInfo ?
424
- (curCodeBlockInfo.codeBlockIndex + (reverse ? -1 : 1) + responseCodeblocks.length) % responseCodeblocks.length :
425
- reverse ? responseCodeblocks.length - 1 : 0;
426
- responseCodeblocks[focusIdx]?.focus();
427
- }
428
- registerAction2(class NextCodeBlockAction extends Action2 {
429
- constructor() {
430
- super({
431
- id: 'workbench.action.chat.nextCodeBlock',
432
- title: ( localize2WithPath(
433
- 'vs/workbench/contrib/chat/browser/actions/chatCodeblockActions',
434
- 'interactive.nextCodeBlock.label',
435
- "Next Code Block"
436
- )),
437
- keybinding: {
438
- primary: 2048 | 512 | 12 ,
439
- mac: { primary: 2048 | 512 | 12 , },
440
- weight: 200 ,
441
- when: CONTEXT_IN_CHAT_SESSION,
442
- },
443
- precondition: CONTEXT_PROVIDER_EXISTS,
444
- f1: true,
445
- category: CHAT_CATEGORY,
446
- });
447
- }
448
- run(accessor, ...args) {
449
- navigateCodeBlocks(accessor);
450
- }
451
- });
452
- registerAction2(class PreviousCodeBlockAction extends Action2 {
453
- constructor() {
454
- super({
455
- id: 'workbench.action.chat.previousCodeBlock',
456
- title: ( localize2WithPath(
457
- 'vs/workbench/contrib/chat/browser/actions/chatCodeblockActions',
458
- 'interactive.previousCodeBlock.label',
459
- "Previous Code Block"
460
- )),
461
- keybinding: {
462
- primary: 2048 | 512 | 11 ,
463
- mac: { primary: 2048 | 512 | 11 , },
464
- weight: 200 ,
465
- when: CONTEXT_IN_CHAT_SESSION,
466
- },
467
- precondition: CONTEXT_PROVIDER_EXISTS,
468
- f1: true,
469
- category: CHAT_CATEGORY,
470
- });
471
- }
472
- run(accessor, ...args) {
473
- navigateCodeBlocks(accessor, true);
474
- }
475
- });
476
- }
477
- function getContextFromEditor(editor, accessor) {
478
- const chatWidgetService = accessor.get(IChatWidgetService);
479
- const chatCodeBlockContextProviderService = accessor.get(IChatCodeBlockContextProviderService);
480
- const model = editor.getModel();
481
- if (!model) {
482
- return;
483
- }
484
- const widget = chatWidgetService.lastFocusedWidget;
485
- const codeBlockInfo = widget?.getCodeBlockInfoForEditor(model.uri);
486
- if (!codeBlockInfo) {
487
- for (const provider of chatCodeBlockContextProviderService.providers) {
488
- const context = provider.getCodeBlockContext(editor);
489
- if (context) {
490
- return context;
491
- }
492
- }
493
- return;
494
- }
495
- return {
496
- element: codeBlockInfo.element,
497
- codeBlockIndex: codeBlockInfo.codeBlockIndex,
498
- code: editor.getValue(),
499
- languageId: editor.getModel().getLanguageId(),
500
- };
501
- }
502
-
503
- export { isCodeBlockActionContext, registerChatCodeBlockActions };