@codingame/monaco-vscode-chat-service-override 13.1.7 → 14.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/index.js +9 -9
- package/package.json +20 -20
- package/vscode/src/vs/base/common/objectCache.d.ts +13 -0
- package/vscode/src/vs/base/common/objectCache.js +39 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityHelp.d.ts +12 -5
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityHelp.js +95 -23
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.d.ts +10 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +81 -19
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContextActions.js +144 -66
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +4 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatDeveloperActions.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +4 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatGettingStarted.d.ts +6 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatGettingStarted.js +17 -11
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.js +6 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.js +8 -7
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.js +10 -10
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.d.ts +11 -8
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.js +168 -167
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +116 -54
- package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatContentParts/chatMarkdownAnchorService.d.ts +11 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatContentParts/chatMarkdownAnchorService.js +34 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingService.d.ts +11 -11
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingService.js +105 -70
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.d.ts +17 -16
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.js +154 -83
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.d.ts +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +5 -5
- package/vscode/src/vs/workbench/contrib/chat/browser/chatParticipant.contribution.d.ts +0 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/chatParticipant.contribution.js +150 -130
- package/vscode/src/vs/workbench/contrib/chat/browser/chatPasteProviders.js +13 -7
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatResponseAccessibleView.d.ts +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/chatResponseAccessibleView.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup.d.ts +11 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup.js +449 -229
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.d.ts +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +7 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/codeBlockContextProviderService.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorHover.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputRelatedFilesContrib.js +11 -9
- package/vscode/src/vs/workbench/contrib/chat/browser/languageModelToolsService.d.ts +7 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/languageModelToolsService.js +76 -13
- package/vscode/src/vs/workbench/contrib/chat/browser/media/chatViewSetup.css.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/viewsWelcome/chatViewsWelcomeHandler.js +5 -5
- package/vscode/src/vs/workbench/contrib/chat/common/chatCodeMapperService.d.ts +5 -18
- package/vscode/src/vs/workbench/contrib/chat/common/chatCodeMapperService.js +4 -122
- package/vscode/src/vs/workbench/contrib/chat/common/chatProgressTypes/chatToolInvocation.d.ts +3 -1
- package/vscode/src/vs/workbench/contrib/chat/common/chatProgressTypes/chatToolInvocation.js +5 -4
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.d.ts +6 -3
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +42 -11
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/contentProviders/textModelContentsProvider.d.ts +13 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/contentProviders/textModelContentsProvider.js +49 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptLinkProvider.d.ts +14 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptLinkProvider.js +69 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/textModelPromptParser.d.ts +10 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/textModelPromptParser.js +24 -0
- package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsContribution.js +73 -17
- package/vscode/src/vs/workbench/contrib/chat/common/tools/tools.d.ts +11 -0
- package/vscode/src/vs/workbench/contrib/chat/common/tools/tools.js +22 -0
- package/vscode/src/vs/workbench/contrib/chat/common/voiceChatService.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/common/voiceChatService.js +2 -2
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +9 -6
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibilityHelp.d.ts +2 -2
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibleView.d.ts +2 -2
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatController2.d.ts +39 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatController2.js +314 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatCurrentLine.js +34 -19
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClearActions.d.ts +0 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClearActions.js +0 -334
- package/vscode/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.d.ts +0 -31
- package/vscode/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.js +0 -46
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl.d.ts +0 -29
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl.js +0 -168
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
|
|
2
2
|
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
|
-
import { coalesce } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
|
|
4
3
|
import { AsyncIterableObject } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
|
|
5
4
|
import { VSBuffer } from '@codingame/monaco-vscode-api/vscode/vs/base/common/buffer';
|
|
6
5
|
import { CancellationTokenSource } from '@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation';
|
|
@@ -8,12 +7,12 @@ import { CharCode } from '@codingame/monaco-vscode-api/vscode/vs/base/common/cha
|
|
|
8
7
|
import { isCancellationError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
|
|
9
8
|
import { isEqual } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
|
|
10
9
|
import { splitLines } from '@codingame/monaco-vscode-api/vscode/vs/base/common/strings';
|
|
11
|
-
import {
|
|
10
|
+
import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
|
|
11
|
+
import { getCodeEditor } from '@codingame/monaco-vscode-api/vscode/vs/editor/browser/editorBrowser';
|
|
12
12
|
import { ResourceTextEdit, IBulkEditService } from '@codingame/monaco-vscode-api/vscode/vs/editor/browser/services/bulkEditService';
|
|
13
13
|
import { ICodeEditorService } from '@codingame/monaco-vscode-api/vscode/vs/editor/browser/services/codeEditorService';
|
|
14
14
|
import { Range } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range';
|
|
15
15
|
import { ILanguageService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/languages/language';
|
|
16
|
-
import { ILanguageFeaturesService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/languageFeatures';
|
|
17
16
|
import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
|
|
18
17
|
import { IDialogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/dialogs/common/dialogs.service';
|
|
19
18
|
import { IFileService } from '@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files.service';
|
|
@@ -25,9 +24,11 @@ import { ITextFileService } from '@codingame/monaco-vscode-api/vscode/vs/workben
|
|
|
25
24
|
import { InlineChatController } from '@codingame/monaco-vscode-c465110a-57c0-59d7-a6b2-be0a4db7e517-common/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatController';
|
|
26
25
|
import { insertCell } from '@codingame/monaco-vscode-e28ac690-06d5-5ee9-92d1-02df70296354-common/vscode/vs/workbench/contrib/notebook/browser/controller/cellOperations';
|
|
27
26
|
import { CellKind, NOTEBOOK_EDITOR_ID } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
|
|
28
|
-
import {
|
|
27
|
+
import { ICodeMapperService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatCodeMapperService.service';
|
|
29
28
|
import { IChatService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatService.service';
|
|
30
|
-
import { isResponseVM
|
|
29
|
+
import { isResponseVM } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatViewModel';
|
|
30
|
+
import { IQuickInputService } from '@codingame/monaco-vscode-api/vscode/vs/platform/quickinput/common/quickInput.service';
|
|
31
|
+
import { ILabelService } from '@codingame/monaco-vscode-api/vscode/vs/platform/label/common/label.service';
|
|
31
32
|
|
|
32
33
|
let InsertCodeBlockOperation = class InsertCodeBlockOperation {
|
|
33
34
|
constructor(editorService, textFileService, bulkEditService, codeEditorService, chatService, languageService, dialogService) {
|
|
@@ -51,7 +52,7 @@ let InsertCodeBlockOperation = class InsertCodeBlockOperation {
|
|
|
51
52
|
}
|
|
52
53
|
else {
|
|
53
54
|
this.notify(( localize(
|
|
54
|
-
|
|
55
|
+
4359,
|
|
55
56
|
"To insert the code block, open a code editor or notebook editor and set the cursor at the location where to insert the code block."
|
|
56
57
|
)));
|
|
57
58
|
}
|
|
@@ -64,7 +65,7 @@ let InsertCodeBlockOperation = class InsertCodeBlockOperation {
|
|
|
64
65
|
}
|
|
65
66
|
async handleNotebookEditor(notebookEditor, codeBlockContext) {
|
|
66
67
|
if (notebookEditor.isReadOnly) {
|
|
67
|
-
this.notify(( localize(
|
|
68
|
+
this.notify(( localize(4360, "Cannot insert the code block to read-only notebook editor.")));
|
|
68
69
|
return false;
|
|
69
70
|
}
|
|
70
71
|
const focusRange = notebookEditor.getFocus();
|
|
@@ -75,7 +76,7 @@ let InsertCodeBlockOperation = class InsertCodeBlockOperation {
|
|
|
75
76
|
async handleTextEditor(codeEditor, codeBlockContext) {
|
|
76
77
|
const activeModel = codeEditor.getModel();
|
|
77
78
|
if (isReadOnly(activeModel, this.textFileService)) {
|
|
78
|
-
this.notify(( localize(
|
|
79
|
+
this.notify(( localize(4361, "Cannot insert the code block to read-only code editor.")));
|
|
79
80
|
return false;
|
|
80
81
|
}
|
|
81
82
|
const range = codeEditor.getSelection() ?? ( new Range(activeModel.getLineCount(), 1, activeModel.getLineCount(), 1));
|
|
@@ -99,54 +100,54 @@ InsertCodeBlockOperation = ( __decorate([
|
|
|
99
100
|
( __param(6, IDialogService))
|
|
100
101
|
], InsertCodeBlockOperation));
|
|
101
102
|
let ApplyCodeBlockOperation = class ApplyCodeBlockOperation {
|
|
102
|
-
constructor(editorService, textFileService,
|
|
103
|
+
constructor(editorService, textFileService, chatService, languageService, fileService, dialogService, logService, codeMapperService, progressService, quickInputService, labelService) {
|
|
103
104
|
this.editorService = editorService;
|
|
104
105
|
this.textFileService = textFileService;
|
|
105
|
-
this.bulkEditService = bulkEditService;
|
|
106
|
-
this.codeEditorService = codeEditorService;
|
|
107
106
|
this.chatService = chatService;
|
|
108
|
-
this.languageFeaturesService = languageFeaturesService;
|
|
109
|
-
this.progressService = progressService;
|
|
110
107
|
this.languageService = languageService;
|
|
111
108
|
this.fileService = fileService;
|
|
112
109
|
this.dialogService = dialogService;
|
|
113
110
|
this.logService = logService;
|
|
111
|
+
this.codeMapperService = codeMapperService;
|
|
112
|
+
this.progressService = progressService;
|
|
113
|
+
this.quickInputService = quickInputService;
|
|
114
|
+
this.labelService = labelService;
|
|
114
115
|
}
|
|
115
116
|
async run(context) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
"Another code change is being previewed. Please apply or discard the pending changes first."
|
|
120
|
-
)));
|
|
117
|
+
let activeEditorControl = getEditableActiveCodeEditor(this.editorService);
|
|
118
|
+
const codemapperUri = await this.evaluateURIToUse(context.codemapperUri, activeEditorControl);
|
|
119
|
+
if (!codemapperUri) {
|
|
121
120
|
return;
|
|
122
121
|
}
|
|
123
|
-
|
|
124
|
-
if (context.codemapperUri && !isEqual(activeEditorControl?.getModel().uri, context.codemapperUri)) {
|
|
122
|
+
if (codemapperUri && !isEqual(activeEditorControl?.getModel().uri, codemapperUri)) {
|
|
125
123
|
try {
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
const editorPane = await this.editorService.openEditor({ resource: codemapperUri });
|
|
125
|
+
const codeEditor = getCodeEditor(editorPane?.getControl());
|
|
126
|
+
if (codeEditor && codeEditor.hasModel()) {
|
|
127
|
+
this.tryToRevealCodeBlock(codeEditor, context.code);
|
|
128
|
+
activeEditorControl = codeEditor;
|
|
128
129
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.tryToRevealCodeBlock(activeEditorControl, context.code);
|
|
130
|
+
else {
|
|
131
|
+
this.notify(( localize(4362, "Failed to open {0} in a code editor.", (codemapperUri.toString()))));
|
|
132
|
+
return;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
catch (e) {
|
|
136
|
-
this.logService.info('[ApplyCodeBlockOperation] error opening code mapper file',
|
|
136
|
+
this.logService.info('[ApplyCodeBlockOperation] error opening code mapper file', codemapperUri, e);
|
|
137
|
+
return;
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
let result = undefined;
|
|
140
141
|
if (activeEditorControl) {
|
|
141
|
-
await this.handleTextEditor(activeEditorControl, context);
|
|
142
|
+
result = await this.handleTextEditor(activeEditorControl, context.code);
|
|
142
143
|
}
|
|
143
144
|
else {
|
|
144
145
|
const activeNotebookEditor = getActiveNotebookEditor(this.editorService);
|
|
145
146
|
if (activeNotebookEditor) {
|
|
146
|
-
result = await this.handleNotebookEditor(activeNotebookEditor, context);
|
|
147
|
+
result = await this.handleNotebookEditor(activeNotebookEditor, context.code);
|
|
147
148
|
}
|
|
148
149
|
else {
|
|
149
|
-
this.notify(( localize(
|
|
150
|
+
this.notify(( localize(4363, "To apply this code block, open a code or notebook editor.")));
|
|
150
151
|
}
|
|
151
152
|
}
|
|
152
153
|
notifyUserAction(this.chatService, context, {
|
|
@@ -154,107 +155,143 @@ let ApplyCodeBlockOperation = class ApplyCodeBlockOperation {
|
|
|
154
155
|
codeBlockIndex: context.codeBlockIndex,
|
|
155
156
|
totalCharacters: context.code.length,
|
|
156
157
|
codeMapper: result?.codeMapper,
|
|
157
|
-
editsProposed: !!result?.
|
|
158
|
+
editsProposed: !!result?.editsProposed
|
|
158
159
|
});
|
|
159
160
|
}
|
|
160
|
-
async
|
|
161
|
+
async evaluateURIToUse(resource, activeEditorControl) {
|
|
162
|
+
if (resource && (await this.fileService.exists(resource))) {
|
|
163
|
+
return resource;
|
|
164
|
+
}
|
|
165
|
+
const activeEditorOption = activeEditorControl?.getModel().uri ? { label: ( localize(
|
|
166
|
+
4364,
|
|
167
|
+
"Active editor '{0}'",
|
|
168
|
+
this.labelService.getUriLabel(activeEditorControl.getModel().uri, { relative: true })
|
|
169
|
+
)), id: 'activeEditor' } : undefined;
|
|
170
|
+
const untitledEditorOption = { label: ( localize(4365, "New untitled editor")), id: 'newUntitledFile' };
|
|
171
|
+
const options = [];
|
|
172
|
+
if (resource) {
|
|
173
|
+
options.push({ label: ( localize(
|
|
174
|
+
4366,
|
|
175
|
+
"New file '{0}'",
|
|
176
|
+
this.labelService.getUriLabel(resource, { relative: true })
|
|
177
|
+
)), id: 'createFile' });
|
|
178
|
+
options.push(untitledEditorOption);
|
|
179
|
+
if (activeEditorOption) {
|
|
180
|
+
options.push(activeEditorOption);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
if (activeEditorOption) {
|
|
185
|
+
options.push(activeEditorOption);
|
|
186
|
+
}
|
|
187
|
+
options.push(untitledEditorOption);
|
|
188
|
+
}
|
|
189
|
+
const selected = options.length > 1 ? await this.quickInputService.pick(options, { placeHolder: ( localize(4367, "Select where to apply the code block")) }) : options[0];
|
|
190
|
+
if (selected) {
|
|
191
|
+
switch (selected.id) {
|
|
192
|
+
case 'createFile':
|
|
193
|
+
if (resource) {
|
|
194
|
+
try {
|
|
195
|
+
await this.fileService.writeFile(resource, VSBuffer.fromString(''));
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
this.notify(( localize(4368, "Failed to create file: {0}", error.message)));
|
|
199
|
+
return ( URI.from({ scheme: 'untitled', path: resource.path }));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return resource;
|
|
203
|
+
case 'newUntitledFile':
|
|
204
|
+
return ( URI.from({ scheme: 'untitled', path: resource ? resource.path : 'Untitled-1' }));
|
|
205
|
+
case 'activeEditor':
|
|
206
|
+
return activeEditorControl?.getModel().uri;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
async handleNotebookEditor(notebookEditor, code) {
|
|
161
212
|
if (notebookEditor.isReadOnly) {
|
|
162
|
-
this.notify(( localize(
|
|
213
|
+
this.notify(( localize(4369, "Cannot apply code block to read-only notebook editor.")));
|
|
163
214
|
return undefined;
|
|
164
215
|
}
|
|
165
216
|
const focusRange = notebookEditor.getFocus();
|
|
166
217
|
const next = Math.max(focusRange.end - 1, 0);
|
|
167
|
-
insertCell(this.languageService, notebookEditor, next, CellKind.Code, 'below',
|
|
218
|
+
insertCell(this.languageService, notebookEditor, next, CellKind.Code, 'below', code, true);
|
|
168
219
|
return undefined;
|
|
169
220
|
}
|
|
170
|
-
async handleTextEditor(codeEditor,
|
|
171
|
-
|
|
172
|
-
|
|
221
|
+
async handleTextEditor(codeEditor, code) {
|
|
222
|
+
const activeModel = codeEditor.getModel();
|
|
223
|
+
if (isReadOnly(activeModel, this.textFileService)) {
|
|
224
|
+
this.notify(( localize(4370, "Cannot apply code block to read-only file.")));
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
const codeBlock = { code, resource: activeModel.uri, markdownBeforeBlock: undefined };
|
|
228
|
+
const codeMapper = this.codeMapperService.providers[0]?.displayName;
|
|
229
|
+
if (!codeMapper) {
|
|
230
|
+
this.notify(( localize(4371, "No code mapper available.")));
|
|
173
231
|
return undefined;
|
|
174
232
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
233
|
+
let editsProposed = false;
|
|
234
|
+
const cancellationTokenSource = ( new CancellationTokenSource());
|
|
235
|
+
try {
|
|
236
|
+
const iterable = await this.progressService.withProgress({ location: ProgressLocation.Notification, delay: 500, sticky: true, cancellable: true }, async (progress) => {
|
|
237
|
+
progress.report({ message: ( localize(4372, "Applying code block using {0}...", codeMapper)) });
|
|
238
|
+
const editsIterable = this.getEdits(codeBlock, cancellationTokenSource.token);
|
|
239
|
+
return await this.waitForFirstElement(editsIterable);
|
|
240
|
+
}, () => cancellationTokenSource.cancel());
|
|
241
|
+
editsProposed = await this.applyWithInlinePreview(iterable, codeEditor, cancellationTokenSource);
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
if (!isCancellationError(e)) {
|
|
245
|
+
this.notify(( localize(4373, "Failed to apply code block: {0}", e.message)));
|
|
182
246
|
}
|
|
183
247
|
}
|
|
184
|
-
|
|
248
|
+
finally {
|
|
249
|
+
cancellationTokenSource.dispose();
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
editsProposed,
|
|
253
|
+
codeMapper
|
|
254
|
+
};
|
|
185
255
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
let codeMapper;
|
|
195
|
-
try {
|
|
196
|
-
const result = await this.progressService.withProgress({ location: ProgressLocation.Notification, delay: 500, sticky: true, cancellable: true }, async (progress) => {
|
|
197
|
-
for (const provider of mappedEditsProviders) {
|
|
198
|
-
codeMapper = provider.displayName;
|
|
199
|
-
progress.report({ message: ( localize(4287, "Applying code block using {0}...", codeMapper)) });
|
|
200
|
-
const mappedEdits = await provider.provideMappedEdits(activeModel, [codeBlockActionContext.code], {
|
|
201
|
-
documents: docRefs,
|
|
202
|
-
conversation: getChatConversation(codeBlockActionContext),
|
|
203
|
-
}, cancellationTokenSource.token);
|
|
204
|
-
if (mappedEdits) {
|
|
205
|
-
return { edits: mappedEdits.edits, codeMapper };
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return undefined;
|
|
209
|
-
}, () => cancellationTokenSource.cancel());
|
|
210
|
-
if (result) {
|
|
211
|
-
return result;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
catch (e) {
|
|
215
|
-
if (!isCancellationError(e)) {
|
|
216
|
-
this.notify(( localize(4288, "Failed to apply code block: {0}", e.message)));
|
|
256
|
+
getEdits(codeBlock, token) {
|
|
257
|
+
return ( new AsyncIterableObject(async (executor) => {
|
|
258
|
+
const request = {
|
|
259
|
+
codeBlocks: [codeBlock]
|
|
260
|
+
};
|
|
261
|
+
const response = {
|
|
262
|
+
textEdit: (target, edit) => {
|
|
263
|
+
executor.emitOne(edit);
|
|
217
264
|
}
|
|
265
|
+
};
|
|
266
|
+
const result = await this.codeMapperService.mapCode(request, response, token);
|
|
267
|
+
if (result?.errorMessage) {
|
|
268
|
+
executor.reject(( new Error(result.errorMessage)));
|
|
218
269
|
}
|
|
219
|
-
|
|
220
|
-
cancellationTokenSource.dispose();
|
|
221
|
-
}
|
|
222
|
-
return { edits: [], codeMapper };
|
|
223
|
-
}
|
|
224
|
-
return { edits: [], codeMapper: undefined };
|
|
270
|
+
}));
|
|
225
271
|
}
|
|
226
|
-
async
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (textEdits.length !== edits.length) {
|
|
236
|
-
return false;
|
|
272
|
+
async waitForFirstElement(iterable) {
|
|
273
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
274
|
+
let result = await iterator.next();
|
|
275
|
+
if (result.done) {
|
|
276
|
+
return {
|
|
277
|
+
async *[Symbol.asyncIterator]() {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
};
|
|
237
281
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const firstEdit = textEdits[0];
|
|
245
|
-
editorToApply.revealLineInCenterIfOutsideViewport(firstEdit.range.startLineNumber);
|
|
246
|
-
const promise = inlineChatController.reviewEdits(textEdits[0].range, AsyncIterableObject.fromArray([textEdits]), tokenSource.token);
|
|
247
|
-
promise.finally(() => {
|
|
248
|
-
isOpen = false;
|
|
249
|
-
tokenSource.dispose();
|
|
250
|
-
});
|
|
251
|
-
this.inlineChatPreview = {
|
|
252
|
-
promise,
|
|
253
|
-
isOpen: () => isOpen,
|
|
254
|
-
cancel: () => tokenSource.cancel(),
|
|
255
|
-
};
|
|
256
|
-
return true;
|
|
282
|
+
return {
|
|
283
|
+
async *[Symbol.asyncIterator]() {
|
|
284
|
+
while (!result.done) {
|
|
285
|
+
yield result.value;
|
|
286
|
+
result = await iterator.next();
|
|
287
|
+
}
|
|
257
288
|
}
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
async applyWithInlinePreview(edits, codeEditor, tokenSource) {
|
|
292
|
+
const inlineChatController = InlineChatController.get(codeEditor);
|
|
293
|
+
if (inlineChatController) {
|
|
294
|
+
return inlineChatController.reviewEdits(edits, tokenSource.token);
|
|
258
295
|
}
|
|
259
296
|
return false;
|
|
260
297
|
}
|
|
@@ -274,15 +311,15 @@ let ApplyCodeBlockOperation = class ApplyCodeBlockOperation {
|
|
|
274
311
|
ApplyCodeBlockOperation = ( __decorate([
|
|
275
312
|
( __param(0, IEditorService)),
|
|
276
313
|
( __param(1, ITextFileService)),
|
|
277
|
-
( __param(2,
|
|
278
|
-
( __param(3,
|
|
279
|
-
( __param(4,
|
|
280
|
-
( __param(5,
|
|
281
|
-
( __param(6,
|
|
282
|
-
( __param(7,
|
|
283
|
-
( __param(8,
|
|
284
|
-
( __param(9,
|
|
285
|
-
( __param(10,
|
|
314
|
+
( __param(2, IChatService)),
|
|
315
|
+
( __param(3, ILanguageService)),
|
|
316
|
+
( __param(4, IFileService)),
|
|
317
|
+
( __param(5, IDialogService)),
|
|
318
|
+
( __param(6, ILogService)),
|
|
319
|
+
( __param(7, ICodeMapperService)),
|
|
320
|
+
( __param(8, IProgressService)),
|
|
321
|
+
( __param(9, IQuickInputService)),
|
|
322
|
+
( __param(10, ILabelService))
|
|
286
323
|
], ApplyCodeBlockOperation));
|
|
287
324
|
function notifyUserAction(chatService, context, action) {
|
|
288
325
|
if (isResponseVM(context.element)) {
|
|
@@ -311,60 +348,24 @@ function getEditableActiveCodeEditor(editorService) {
|
|
|
311
348
|
if (activeCodeEditorInNotebook && activeCodeEditorInNotebook.hasTextFocus() && activeCodeEditorInNotebook.hasModel()) {
|
|
312
349
|
return activeCodeEditorInNotebook;
|
|
313
350
|
}
|
|
314
|
-
let
|
|
315
|
-
if (
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
351
|
+
let codeEditor = getCodeEditor(editorService.activeTextEditorControl);
|
|
352
|
+
if (!codeEditor) {
|
|
353
|
+
for (const editor of editorService.visibleTextEditorControls) {
|
|
354
|
+
codeEditor = getCodeEditor(editor);
|
|
355
|
+
if (codeEditor) {
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
320
359
|
}
|
|
321
|
-
if (!
|
|
360
|
+
if (!codeEditor || !codeEditor.hasModel()) {
|
|
322
361
|
return undefined;
|
|
323
362
|
}
|
|
324
|
-
return
|
|
363
|
+
return codeEditor;
|
|
325
364
|
}
|
|
326
365
|
function isReadOnly(model, textFileService) {
|
|
327
366
|
const activeTextModel = textFileService.files.get(model.uri) ?? textFileService.untitled.get(model.uri);
|
|
328
367
|
return !!activeTextModel?.isReadonly();
|
|
329
368
|
}
|
|
330
|
-
function collectDocumentContextFromSelections(codeEditor, result) {
|
|
331
|
-
const activeModel = codeEditor.getModel();
|
|
332
|
-
const currentDocUri = activeModel.uri;
|
|
333
|
-
const currentDocVersion = activeModel.getVersionId();
|
|
334
|
-
const selections = codeEditor.getSelections();
|
|
335
|
-
if (selections.length > 0) {
|
|
336
|
-
result.push([
|
|
337
|
-
{
|
|
338
|
-
uri: currentDocUri,
|
|
339
|
-
version: currentDocVersion,
|
|
340
|
-
ranges: selections,
|
|
341
|
-
}
|
|
342
|
-
]);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
function collectDocumentContextFromContext(context, result) {
|
|
346
|
-
if (isResponseVM(context.element) && context.element.usedContext?.documents) {
|
|
347
|
-
result.push(context.element.usedContext.documents);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
function getChatConversation(context) {
|
|
351
|
-
if (isResponseVM(context.element)) {
|
|
352
|
-
return [{
|
|
353
|
-
type: 'response',
|
|
354
|
-
message: context.element.response.getMarkdown(),
|
|
355
|
-
references: getReferencesAsDocumentContext(context.element.contentReferences)
|
|
356
|
-
}];
|
|
357
|
-
}
|
|
358
|
-
else if (isRequestVM(context.element)) {
|
|
359
|
-
return [{
|
|
360
|
-
type: 'request',
|
|
361
|
-
message: context.element.messageText,
|
|
362
|
-
}];
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
return [];
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
369
|
function reindent(codeBlockContent, model, seletionStartLine) {
|
|
369
370
|
const newContent = splitLines(codeBlockContent);
|
|
370
371
|
if (newContent.length === 0) {
|