@codingame/monaco-vscode-chat-service-override 9.0.2 → 10.0.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.
- package/chat.js +8 -2
- package/package.json +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityHelp.js +24 -25
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClearActions.js +5 -7
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +100 -293
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContextActions.js +115 -26
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatDeveloperActions.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +6 -8
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.js +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.js +9 -7
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.js +448 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +58 -43
- package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.js +2 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +7 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/chatGettingStarted.js +131 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatParticipantContributions.js +88 -88
- package/vscode/src/vs/workbench/contrib/chat/browser/chatPasteProviders.js +26 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +4 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/chatResponseAccessibleView.js +6 -22
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +11 -17
- package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +21 -14
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorHover.js +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/editorHoverWrapper.js +7 -1
- package/vscode/src/vs/workbench/contrib/chat/common/chatCodeMapperService.js +27 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatProgressTypes/chatToolInvocation.js +52 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +25 -29
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceTelemetry.js +8 -1
- package/vscode/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.js +1 -2
- package/vscode/src/vs/workbench/contrib/chat/common/languageModelStats.js +7 -8
- package/vscode/src/vs/workbench/contrib/chat/common/languageModelToolsService.js +70 -20
- package/vscode/src/vs/workbench/contrib/chat/common/languageModels.js +172 -0
- package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsContribution.js +30 -12
- package/vscode/src/vs/workbench/contrib/chat/common/voiceChatService.js +1 -1
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +11 -15
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibilityHelp.js +1 -2
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibleView.js +5 -6
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatCurrentLine.js +5 -6
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl.js +5 -8
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatContextAttachments.js +0 -58
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputCompletions.js +0 -412
|
@@ -1,46 +1,37 @@
|
|
|
1
1
|
import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
|
|
2
2
|
import { Codicon } from 'vscode/vscode/vs/base/common/codicons';
|
|
3
|
-
import { KeyMod, KeyCode } from 'vscode/vscode/vs/base/common/keyCodes';
|
|
4
|
-
import { isEqual } from 'vscode/vscode/vs/base/common/resources';
|
|
5
|
-
import { isDiffEditor, isCodeEditor } from 'vscode/vscode/vs/editor/browser/editorBrowser';
|
|
6
|
-
import { ResourceTextEdit, IBulkEditService } from 'vscode/vscode/vs/editor/browser/services/bulkEditService';
|
|
7
3
|
import { ICodeEditorService } from 'vscode/vscode/vs/editor/browser/services/codeEditorService';
|
|
8
|
-
import { Range } from 'vscode/vscode/vs/editor/common/core/range';
|
|
9
4
|
import { EditorContextKeys } from 'vscode/vscode/vs/editor/common/editorContextKeys';
|
|
10
|
-
import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
|
|
11
|
-
import { ILanguageFeaturesService } from 'vscode/vscode/vs/editor/common/services/languageFeatures';
|
|
12
5
|
import { CopyAction } from 'vscode/vscode/vs/editor/contrib/clipboard/browser/clipboard';
|
|
13
|
-
import { localize2
|
|
6
|
+
import { localize2 } from 'vscode/vscode/vs/nls';
|
|
14
7
|
import { Action2, registerAction2, MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
|
|
15
8
|
import { IClipboardService } from 'vscode/vscode/vs/platform/clipboard/common/clipboardService.service';
|
|
16
9
|
import { ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
|
|
17
10
|
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
18
|
-
import { KeybindingWeight } from 'vscode/vscode/vs/platform/keybinding/common/keybindingsRegistry';
|
|
19
|
-
import 'vscode/vscode/vs/platform/notification/common/notification';
|
|
20
|
-
import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification.service';
|
|
21
|
-
import { ProgressLocation } from 'vscode/vscode/vs/platform/progress/common/progress';
|
|
22
|
-
import { IProgressService } from 'vscode/vscode/vs/platform/progress/common/progress.service';
|
|
23
11
|
import { TerminalLocation } from 'vscode/vscode/vs/platform/terminal/common/terminal';
|
|
12
|
+
import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService.service';
|
|
24
13
|
import { accessibleViewInCodeBlock } from 'vscode/vscode/vs/workbench/contrib/accessibility/browser/accessibilityConfiguration';
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import { DefaultChatTextEditor } from 'vscode/vscode/vs/workbench/contrib/chat/browser/codeBlockPart';
|
|
14
|
+
import { ITerminalService, ITerminalEditorService, ITerminalGroupService } from 'vscode/vscode/vs/workbench/contrib/terminal/browser/terminal.service';
|
|
15
|
+
import { ICodeMapperService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatCodeMapperService.service';
|
|
28
16
|
import { CONTEXT_CHAT_ENABLED, CONTEXT_IN_CHAT_SESSION, CONTEXT_IN_CHAT_INPUT, CONTEXT_CHAT_EDIT_APPLIED } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatContextKeys';
|
|
17
|
+
import { IChatEditingService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatEditingService.service';
|
|
29
18
|
import { ChatCopyKind } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatService';
|
|
30
19
|
import { IChatService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatService.service';
|
|
31
20
|
import { isResponseVM } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatViewModel';
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import { ITextFileService } from 'vscode/vscode/vs/workbench/services/textfile/common/textfiles.service';
|
|
37
|
-
import { splitLines } from 'vscode/vscode/vs/base/common/strings';
|
|
38
|
-
import { CharCode } from 'vscode/vscode/vs/base/common/charCode';
|
|
39
|
-
import { InlineChatController } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatController';
|
|
40
|
-
import { coalesce } from 'vscode/vscode/vs/base/common/arrays';
|
|
41
|
-
import { AsyncIterableObject } from 'vscode/vscode/vs/base/common/async';
|
|
42
|
-
import Severity$1 from 'vscode/vscode/vs/base/common/severity';
|
|
21
|
+
import { IChatWidgetService, IChatCodeBlockContextProviderService } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chat.service';
|
|
22
|
+
import { DefaultChatTextEditor } from 'vscode/vscode/vs/workbench/contrib/chat/browser/codeBlockPart';
|
|
23
|
+
import { CHAT_CATEGORY } from 'vscode/vscode/vs/workbench/contrib/chat/browser/actions/chatActions';
|
|
24
|
+
import { ApplyCodeBlockOperation, InsertCodeBlockOperation } from './codeBlockOperations.js';
|
|
43
25
|
|
|
26
|
+
const shellLangIds = [
|
|
27
|
+
'fish',
|
|
28
|
+
'ps1',
|
|
29
|
+
'pwsh',
|
|
30
|
+
'powershell',
|
|
31
|
+
'sh',
|
|
32
|
+
'shellscript',
|
|
33
|
+
'zsh'
|
|
34
|
+
];
|
|
44
35
|
function isCodeBlockActionContext(thing) {
|
|
45
36
|
return typeof thing === 'object' && thing !== null && 'code' in thing && 'element' in thing;
|
|
46
37
|
}
|
|
@@ -50,9 +41,6 @@ function isCodeCompareBlockActionContext(thing) {
|
|
|
50
41
|
function isResponseFiltered(context) {
|
|
51
42
|
return isResponseVM(context.element) && context.element.errorDetails?.responseIsFiltered;
|
|
52
43
|
}
|
|
53
|
-
function getUsedDocuments(context) {
|
|
54
|
-
return isResponseVM(context.element) ? context.element.usedContext?.documents : undefined;
|
|
55
|
-
}
|
|
56
44
|
class ChatCodeBlockAction extends Action2 {
|
|
57
45
|
run(accessor, ...args) {
|
|
58
46
|
let context = args[0];
|
|
@@ -70,188 +58,12 @@ class ChatCodeBlockAction extends Action2 {
|
|
|
70
58
|
return this.runWithContext(accessor, context);
|
|
71
59
|
}
|
|
72
60
|
}
|
|
73
|
-
class InsertCodeBlockAction extends ChatCodeBlockAction {
|
|
74
|
-
async runWithContext(accessor, context) {
|
|
75
|
-
const editorService = accessor.get(IEditorService);
|
|
76
|
-
const textFileService = accessor.get(ITextFileService);
|
|
77
|
-
if (isResponseFiltered(context)) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (editorService.activeEditorPane?.getId() === NOTEBOOK_EDITOR_ID) {
|
|
81
|
-
return this.handleNotebookEditor(accessor, editorService.activeEditorPane.getControl(), context);
|
|
82
|
-
}
|
|
83
|
-
let activeEditorControl = editorService.activeTextEditorControl;
|
|
84
|
-
if (isDiffEditor(activeEditorControl)) {
|
|
85
|
-
activeEditorControl = activeEditorControl.getOriginalEditor().hasTextFocus() ? activeEditorControl.getOriginalEditor() : activeEditorControl.getModifiedEditor();
|
|
86
|
-
}
|
|
87
|
-
if (!isCodeEditor(activeEditorControl)) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (!activeEditorControl.hasModel()) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const activeModelUri = activeEditorControl.getModel().uri;
|
|
94
|
-
const activeTextModel = textFileService.files.get(activeModelUri) ?? textFileService.untitled.get(activeModelUri);
|
|
95
|
-
if (!activeTextModel || activeTextModel.isReadonly()) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
await this.handleTextEditor(accessor, activeEditorControl, context);
|
|
99
|
-
}
|
|
100
|
-
async handleNotebookEditor(accessor, notebookEditor, context) {
|
|
101
|
-
if (!notebookEditor.hasModel()) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (notebookEditor.isReadOnly) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (notebookEditor.activeCodeEditor?.hasTextFocus()) {
|
|
108
|
-
const codeEditor = notebookEditor.activeCodeEditor;
|
|
109
|
-
if (codeEditor.hasModel()) {
|
|
110
|
-
return this.handleTextEditor(accessor, codeEditor, context);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const languageService = accessor.get(ILanguageService);
|
|
114
|
-
const chatService = accessor.get(IChatService);
|
|
115
|
-
const focusRange = notebookEditor.getFocus();
|
|
116
|
-
const next = Math.max(focusRange.end - 1, 0);
|
|
117
|
-
insertCell(languageService, notebookEditor, next, CellKind.Code, 'below', context.code, true);
|
|
118
|
-
this.notifyUserAction(chatService, context);
|
|
119
|
-
}
|
|
120
|
-
async computeEdits(accessor, codeEditor, codeBlockActionContext) {
|
|
121
|
-
const activeModel = codeEditor.getModel();
|
|
122
|
-
const range = codeEditor.getSelection() ?? ( (new Range(activeModel.getLineCount(), 1, activeModel.getLineCount(), 1)));
|
|
123
|
-
const text = reindent(codeBlockActionContext.code, activeModel, range.startLineNumber);
|
|
124
|
-
return { edits: [( (new ResourceTextEdit(activeModel.uri, { range, text })))] };
|
|
125
|
-
}
|
|
126
|
-
get showPreview() {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
async handleTextEditor(accessor, codeEditor, codeBlockActionContext) {
|
|
130
|
-
const bulkEditService = accessor.get(IBulkEditService);
|
|
131
|
-
const codeEditorService = accessor.get(ICodeEditorService);
|
|
132
|
-
const chatService = accessor.get(IChatService);
|
|
133
|
-
const result = await this.computeEdits(accessor, codeEditor, codeBlockActionContext);
|
|
134
|
-
this.notifyUserAction(chatService, codeBlockActionContext, result);
|
|
135
|
-
if (this.showPreview) {
|
|
136
|
-
const showWithPreview = await this.applyWithInlinePreview(codeEditorService, result.edits, codeEditor);
|
|
137
|
-
if (!showWithPreview) {
|
|
138
|
-
await bulkEditService.apply(result.edits, { showPreview: true });
|
|
139
|
-
const activeModel = codeEditor.getModel();
|
|
140
|
-
codeEditorService.listCodeEditors().find(editor => editor.getModel()?.uri.toString() === ( (activeModel.uri.toString())))?.focus();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
await bulkEditService.apply(result.edits);
|
|
145
|
-
const activeModel = codeEditor.getModel();
|
|
146
|
-
codeEditorService.listCodeEditors().find(editor => editor.getModel()?.uri.toString() === ( (activeModel.uri.toString())))?.focus();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
async applyWithInlinePreview(codeEditorService, edits, codeEditor) {
|
|
150
|
-
const firstEdit = edits[0];
|
|
151
|
-
if (!ResourceTextEdit.is(firstEdit)) {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
const resource = firstEdit.resource;
|
|
155
|
-
const textEdits = coalesce(( (edits.map(
|
|
156
|
-
edit => ResourceTextEdit.is(edit) && isEqual(resource, edit.resource) ? edit.textEdit : undefined
|
|
157
|
-
))));
|
|
158
|
-
if (textEdits.length !== edits.length) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
const editorToApply = await codeEditorService.openCodeEditor({ resource }, codeEditor);
|
|
162
|
-
if (editorToApply) {
|
|
163
|
-
const inlineChatController = InlineChatController.get(editorToApply);
|
|
164
|
-
if (inlineChatController) {
|
|
165
|
-
const cancellationTokenSource = ( (new CancellationTokenSource()));
|
|
166
|
-
try {
|
|
167
|
-
return await inlineChatController.reviewEdits(textEdits[0].range, AsyncIterableObject.fromArray(textEdits), cancellationTokenSource.token);
|
|
168
|
-
}
|
|
169
|
-
finally {
|
|
170
|
-
cancellationTokenSource.dispose();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
notifyUserAction(chatService, context, result) {
|
|
177
|
-
if (isResponseVM(context.element)) {
|
|
178
|
-
chatService.notifyUserAction({
|
|
179
|
-
agentId: context.element.agent?.id,
|
|
180
|
-
command: context.element.slashCommand?.name,
|
|
181
|
-
sessionId: context.element.sessionId,
|
|
182
|
-
requestId: context.element.requestId,
|
|
183
|
-
result: context.element.result,
|
|
184
|
-
action: {
|
|
185
|
-
kind: 'insert',
|
|
186
|
-
codeBlockIndex: context.codeBlockIndex,
|
|
187
|
-
totalCharacters: context.code.length,
|
|
188
|
-
userAction: this.desc.id,
|
|
189
|
-
codeMapper: result?.codeMapper,
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
function reindent(codeBlockContent, model, seletionStartLine) {
|
|
196
|
-
const newContent = splitLines(codeBlockContent);
|
|
197
|
-
if (newContent.length === 0) {
|
|
198
|
-
return codeBlockContent;
|
|
199
|
-
}
|
|
200
|
-
const formattingOptions = model.getFormattingOptions();
|
|
201
|
-
const codeIndentLevel = computeIndentation(model.getLineContent(seletionStartLine), formattingOptions.tabSize).level;
|
|
202
|
-
const indents = ( (newContent.map(line => computeIndentation(line, formattingOptions.tabSize))));
|
|
203
|
-
const newContentIndentLevel = indents.reduce((min, indent, index) => {
|
|
204
|
-
if (indent.length !== newContent[index].length) {
|
|
205
|
-
return Math.min(indent.level, min);
|
|
206
|
-
}
|
|
207
|
-
return min;
|
|
208
|
-
}, Number.MAX_VALUE);
|
|
209
|
-
if (newContentIndentLevel === Number.MAX_VALUE || newContentIndentLevel === codeIndentLevel) {
|
|
210
|
-
return codeBlockContent;
|
|
211
|
-
}
|
|
212
|
-
const newLines = [];
|
|
213
|
-
for (let i = 0; i < newContent.length; i++) {
|
|
214
|
-
const { level, length } = indents[i];
|
|
215
|
-
const newLevel = Math.max(0, codeIndentLevel + level - newContentIndentLevel);
|
|
216
|
-
const newIndentation = formattingOptions.insertSpaces ? ' '.repeat(formattingOptions.tabSize * newLevel) : '\t'.repeat(newLevel);
|
|
217
|
-
newLines.push(newIndentation + newContent[i].substring(length));
|
|
218
|
-
}
|
|
219
|
-
return newLines.join('\n');
|
|
220
|
-
}
|
|
221
|
-
function computeIndentation(line, tabSize) {
|
|
222
|
-
let nSpaces = 0;
|
|
223
|
-
let level = 0;
|
|
224
|
-
let i = 0;
|
|
225
|
-
let length = 0;
|
|
226
|
-
const len = line.length;
|
|
227
|
-
while (i < len) {
|
|
228
|
-
const chCode = line.charCodeAt(i);
|
|
229
|
-
if (chCode === CharCode.Space) {
|
|
230
|
-
nSpaces++;
|
|
231
|
-
if (nSpaces === tabSize) {
|
|
232
|
-
level++;
|
|
233
|
-
nSpaces = 0;
|
|
234
|
-
length = i + 1;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
else if (chCode === CharCode.Tab) {
|
|
238
|
-
level++;
|
|
239
|
-
nSpaces = 0;
|
|
240
|
-
length = i + 1;
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
i++;
|
|
246
|
-
}
|
|
247
|
-
return { level, length };
|
|
248
|
-
}
|
|
249
61
|
function registerChatCodeBlockActions() {
|
|
250
62
|
registerAction2(class CopyCodeBlockAction extends Action2 {
|
|
251
63
|
constructor() {
|
|
252
64
|
super({
|
|
253
65
|
id: 'workbench.action.chat.copyCodeBlock',
|
|
254
|
-
title: ( localize2(
|
|
66
|
+
title: ( localize2(7310, "Copy")),
|
|
255
67
|
f1: false,
|
|
256
68
|
category: CHAT_CATEGORY,
|
|
257
69
|
icon: Codicon.copy,
|
|
@@ -332,19 +144,21 @@ function registerChatCodeBlockActions() {
|
|
|
332
144
|
}
|
|
333
145
|
return false;
|
|
334
146
|
});
|
|
335
|
-
registerAction2(class SmartApplyInEditorAction extends
|
|
147
|
+
registerAction2(class SmartApplyInEditorAction extends ChatCodeBlockAction {
|
|
336
148
|
constructor() {
|
|
337
149
|
super({
|
|
338
150
|
id: 'workbench.action.chat.applyInEditor',
|
|
339
|
-
title: ( localize2(
|
|
151
|
+
title: ( localize2(7311, "Apply in Editor")),
|
|
340
152
|
precondition: CONTEXT_CHAT_ENABLED,
|
|
341
153
|
f1: true,
|
|
342
154
|
category: CHAT_CATEGORY,
|
|
343
|
-
icon: Codicon.
|
|
155
|
+
icon: Codicon.gitPullRequestGoToChanges,
|
|
344
156
|
menu: {
|
|
345
157
|
id: MenuId.ChatCodeBlock,
|
|
346
158
|
group: 'navigation',
|
|
347
|
-
when: CONTEXT_IN_CHAT_SESSION,
|
|
159
|
+
when: ( (ContextKeyExpr.and(CONTEXT_IN_CHAT_SESSION, ...( (shellLangIds.map(
|
|
160
|
+
e => ( (ContextKeyExpr.notEquals(EditorContextKeys.languageId.key, e)))
|
|
161
|
+
)))))),
|
|
348
162
|
order: 10
|
|
349
163
|
},
|
|
350
164
|
keybinding: {
|
|
@@ -352,69 +166,67 @@ function registerChatCodeBlockActions() {
|
|
|
352
166
|
(ContextKeyExpr.and(CONTEXT_IN_CHAT_SESSION, (CONTEXT_IN_CHAT_INPUT.negate()))),
|
|
353
167
|
accessibleViewInCodeBlock
|
|
354
168
|
))),
|
|
355
|
-
primary:
|
|
356
|
-
mac: { primary:
|
|
357
|
-
weight:
|
|
169
|
+
primary: 2048 | 3 ,
|
|
170
|
+
mac: { primary: 256 | 3 },
|
|
171
|
+
weight: 400 + 1
|
|
358
172
|
},
|
|
359
173
|
});
|
|
360
174
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const activeModel = codeEditor.getModel();
|
|
365
|
-
const mappedEditsProviders = accessor.get(ILanguageFeaturesService).mappedEditsProvider.ordered(activeModel);
|
|
366
|
-
if (mappedEditsProviders.length > 0) {
|
|
367
|
-
const docRefs = [];
|
|
368
|
-
const currentDocUri = activeModel.uri;
|
|
369
|
-
const currentDocVersion = activeModel.getVersionId();
|
|
370
|
-
const selections = codeEditor.getSelections();
|
|
371
|
-
if (selections.length > 0) {
|
|
372
|
-
docRefs.push([
|
|
373
|
-
{
|
|
374
|
-
uri: currentDocUri,
|
|
375
|
-
version: currentDocVersion,
|
|
376
|
-
ranges: selections,
|
|
377
|
-
}
|
|
378
|
-
]);
|
|
379
|
-
}
|
|
380
|
-
const usedDocuments = getUsedDocuments(codeBlockActionContext);
|
|
381
|
-
if (usedDocuments) {
|
|
382
|
-
docRefs.push(usedDocuments);
|
|
383
|
-
}
|
|
384
|
-
const cancellationTokenSource = ( (new CancellationTokenSource()));
|
|
385
|
-
try {
|
|
386
|
-
const edits = await progressService.withProgress({ location: ProgressLocation.Notification, delay: 500, sticky: true, cancellable: true }, async (progress) => {
|
|
387
|
-
for (const provider of mappedEditsProviders) {
|
|
388
|
-
progress.report({ message: ( localize(7100, "Applying code block using {0}...", provider.displayName)) });
|
|
389
|
-
const mappedEdits = await provider.provideMappedEdits(activeModel, [codeBlockActionContext.code], { documents: docRefs }, cancellationTokenSource.token);
|
|
390
|
-
if (mappedEdits) {
|
|
391
|
-
return { edits: mappedEdits.edits, codeMapper: provider.displayName };
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return undefined;
|
|
395
|
-
}, () => cancellationTokenSource.cancel());
|
|
396
|
-
if (edits) {
|
|
397
|
-
return edits;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
catch (e) {
|
|
401
|
-
notificationService.notify({ severity: Severity$1.Error, message: ( localize(7101, "Failed to apply code block: {0}", e.message)) });
|
|
402
|
-
}
|
|
403
|
-
finally {
|
|
404
|
-
cancellationTokenSource.dispose();
|
|
405
|
-
}
|
|
175
|
+
runWithContext(accessor, context) {
|
|
176
|
+
if (!this.operation) {
|
|
177
|
+
this.operation = accessor.get(IInstantiationService).createInstance(ApplyCodeBlockOperation);
|
|
406
178
|
}
|
|
407
|
-
return
|
|
179
|
+
return this.operation.run(context);
|
|
408
180
|
}
|
|
409
|
-
|
|
410
|
-
|
|
181
|
+
});
|
|
182
|
+
registerAction2(class ApplyAllAction extends Action2 {
|
|
183
|
+
constructor() {
|
|
184
|
+
super({
|
|
185
|
+
id: 'workbench.action.chat.applyAll',
|
|
186
|
+
title: ( localize2(7312, "Apply All Edits")),
|
|
187
|
+
precondition: CONTEXT_CHAT_ENABLED,
|
|
188
|
+
f1: true,
|
|
189
|
+
category: CHAT_CATEGORY,
|
|
190
|
+
icon: Codicon.edit
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
async run(accessor, ...args) {
|
|
194
|
+
const chatWidgetService = accessor.get(IChatWidgetService);
|
|
195
|
+
const codemapperService = accessor.get(ICodeMapperService);
|
|
196
|
+
const chatEditingService = accessor.get(IChatEditingService);
|
|
197
|
+
const widget = chatWidgetService.lastFocusedWidget;
|
|
198
|
+
if (!widget) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const items = widget.viewModel?.getItems() ?? [];
|
|
202
|
+
const item = widget.getFocus() ?? items[items.length - 1];
|
|
203
|
+
if (!isResponseVM(item)) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const codeblocks = widget.getCodeBlockInfosForResponse(item);
|
|
207
|
+
const request = [];
|
|
208
|
+
for (const codeblock of codeblocks) {
|
|
209
|
+
if (codeblock.codemapperUri && codeblock.uri) {
|
|
210
|
+
const code = codeblock.getContent();
|
|
211
|
+
request.push({ resource: codeblock.codemapperUri, code });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
await chatEditingService.startOrContinueEditingSession(item.sessionId, async (stream) => {
|
|
215
|
+
const response = {
|
|
216
|
+
textEdit: (resource, textEdits) => {
|
|
217
|
+
stream.textEdits(resource, textEdits);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
const tokenSource = ( (new CancellationTokenSource()));
|
|
221
|
+
await codemapperService.mapCode({ codeBlocks: request, conversation: [] }, response, tokenSource.token);
|
|
222
|
+
}, { silent: true });
|
|
411
223
|
}
|
|
412
224
|
});
|
|
413
|
-
registerAction2(class SmartApplyInEditorAction extends
|
|
225
|
+
registerAction2(class SmartApplyInEditorAction extends ChatCodeBlockAction {
|
|
414
226
|
constructor() {
|
|
415
227
|
super({
|
|
416
228
|
id: 'workbench.action.chat.insertCodeBlock',
|
|
417
|
-
title: ( localize2(
|
|
229
|
+
title: ( localize2(7313, "Insert At Cursor")),
|
|
418
230
|
precondition: CONTEXT_CHAT_ENABLED,
|
|
419
231
|
f1: true,
|
|
420
232
|
category: CHAT_CATEGORY,
|
|
@@ -430,18 +242,22 @@ function registerChatCodeBlockActions() {
|
|
|
430
242
|
(ContextKeyExpr.and(CONTEXT_IN_CHAT_SESSION, (CONTEXT_IN_CHAT_INPUT.negate()))),
|
|
431
243
|
accessibleViewInCodeBlock
|
|
432
244
|
))),
|
|
433
|
-
primary:
|
|
434
|
-
mac: { primary:
|
|
435
|
-
weight:
|
|
245
|
+
primary: 2048 | 3 ,
|
|
246
|
+
mac: { primary: 256 | 3 },
|
|
247
|
+
weight: 400 + 1
|
|
436
248
|
},
|
|
437
249
|
});
|
|
438
250
|
}
|
|
251
|
+
runWithContext(accessor, context) {
|
|
252
|
+
const operation = accessor.get(IInstantiationService).createInstance(InsertCodeBlockOperation);
|
|
253
|
+
return operation.run(context);
|
|
254
|
+
}
|
|
439
255
|
});
|
|
440
256
|
registerAction2(class InsertIntoNewFileAction extends ChatCodeBlockAction {
|
|
441
257
|
constructor() {
|
|
442
258
|
super({
|
|
443
259
|
id: 'workbench.action.chat.insertIntoNewFile',
|
|
444
|
-
title: ( localize2(
|
|
260
|
+
title: ( localize2(7314, "Insert into New File")),
|
|
445
261
|
precondition: CONTEXT_CHAT_ENABLED,
|
|
446
262
|
f1: true,
|
|
447
263
|
category: CHAT_CATEGORY,
|
|
@@ -472,27 +288,17 @@ function registerChatCodeBlockActions() {
|
|
|
472
288
|
kind: 'insert',
|
|
473
289
|
codeBlockIndex: context.codeBlockIndex,
|
|
474
290
|
totalCharacters: context.code.length,
|
|
475
|
-
newFile: true
|
|
476
|
-
userAction: this.desc.id,
|
|
291
|
+
newFile: true
|
|
477
292
|
}
|
|
478
293
|
});
|
|
479
294
|
}
|
|
480
295
|
}
|
|
481
296
|
});
|
|
482
|
-
const shellLangIds = [
|
|
483
|
-
'fish',
|
|
484
|
-
'ps1',
|
|
485
|
-
'pwsh',
|
|
486
|
-
'powershell',
|
|
487
|
-
'sh',
|
|
488
|
-
'shellscript',
|
|
489
|
-
'zsh'
|
|
490
|
-
];
|
|
491
297
|
registerAction2(class RunInTerminalAction extends ChatCodeBlockAction {
|
|
492
298
|
constructor() {
|
|
493
299
|
super({
|
|
494
300
|
id: 'workbench.action.chat.runInTerminal',
|
|
495
|
-
title: ( localize2(
|
|
301
|
+
title: ( localize2(7315, "Insert into Terminal")),
|
|
496
302
|
precondition: CONTEXT_CHAT_ENABLED,
|
|
497
303
|
f1: true,
|
|
498
304
|
category: CHAT_CATEGORY,
|
|
@@ -516,11 +322,11 @@ function registerChatCodeBlockActions() {
|
|
|
516
322
|
))))))
|
|
517
323
|
}],
|
|
518
324
|
keybinding: [{
|
|
519
|
-
primary:
|
|
325
|
+
primary: 2048 | 512 | 3 ,
|
|
520
326
|
mac: {
|
|
521
|
-
primary:
|
|
327
|
+
primary: 256 | 512 | 3
|
|
522
328
|
},
|
|
523
|
-
weight:
|
|
329
|
+
weight: 100 ,
|
|
524
330
|
when: ( (ContextKeyExpr.or(CONTEXT_IN_CHAT_SESSION, accessibleViewInCodeBlock))),
|
|
525
331
|
}]
|
|
526
332
|
});
|
|
@@ -592,11 +398,11 @@ function registerChatCodeBlockActions() {
|
|
|
592
398
|
constructor() {
|
|
593
399
|
super({
|
|
594
400
|
id: 'workbench.action.chat.nextCodeBlock',
|
|
595
|
-
title: ( localize2(
|
|
401
|
+
title: ( localize2(7316, "Next Code Block")),
|
|
596
402
|
keybinding: {
|
|
597
|
-
primary:
|
|
598
|
-
mac: { primary:
|
|
599
|
-
weight:
|
|
403
|
+
primary: 2048 | 512 | 12 ,
|
|
404
|
+
mac: { primary: 2048 | 512 | 12 , },
|
|
405
|
+
weight: 200 ,
|
|
600
406
|
when: CONTEXT_IN_CHAT_SESSION,
|
|
601
407
|
},
|
|
602
408
|
precondition: CONTEXT_CHAT_ENABLED,
|
|
@@ -612,11 +418,11 @@ function registerChatCodeBlockActions() {
|
|
|
612
418
|
constructor() {
|
|
613
419
|
super({
|
|
614
420
|
id: 'workbench.action.chat.previousCodeBlock',
|
|
615
|
-
title: ( localize2(
|
|
421
|
+
title: ( localize2(7317, "Previous Code Block")),
|
|
616
422
|
keybinding: {
|
|
617
|
-
primary:
|
|
618
|
-
mac: { primary:
|
|
619
|
-
weight:
|
|
423
|
+
primary: 2048 | 512 | 11 ,
|
|
424
|
+
mac: { primary: 2048 | 512 | 11 , },
|
|
425
|
+
weight: 200 ,
|
|
620
426
|
when: CONTEXT_IN_CHAT_SESSION,
|
|
621
427
|
},
|
|
622
428
|
precondition: CONTEXT_CHAT_ENABLED,
|
|
@@ -652,6 +458,7 @@ function getContextFromEditor(editor, accessor) {
|
|
|
652
458
|
codeBlockIndex: codeBlockInfo.codeBlockIndex,
|
|
653
459
|
code: editor.getValue(),
|
|
654
460
|
languageId: editor.getModel().getLanguageId(),
|
|
461
|
+
codemapperUri: codeBlockInfo.codemapperUri
|
|
655
462
|
};
|
|
656
463
|
}
|
|
657
464
|
function registerChatCodeCompareBlockActions() {
|
|
@@ -668,7 +475,7 @@ function registerChatCodeCompareBlockActions() {
|
|
|
668
475
|
constructor() {
|
|
669
476
|
super({
|
|
670
477
|
id: 'workbench.action.chat.applyCompareEdits',
|
|
671
|
-
title: ( localize2(
|
|
478
|
+
title: ( localize2(7318, "Apply Edits")),
|
|
672
479
|
f1: false,
|
|
673
480
|
category: CHAT_CATEGORY,
|
|
674
481
|
icon: Codicon.check,
|
|
@@ -698,7 +505,7 @@ function registerChatCodeCompareBlockActions() {
|
|
|
698
505
|
constructor() {
|
|
699
506
|
super({
|
|
700
507
|
id: 'workbench.action.chat.discardCompareEdits',
|
|
701
|
-
title: ( localize2(
|
|
508
|
+
title: ( localize2(7319, "Discard Edits")),
|
|
702
509
|
f1: false,
|
|
703
510
|
category: CHAT_CATEGORY,
|
|
704
511
|
icon: Codicon.trash,
|