@codingame/monaco-vscode-chat-service-override 10.1.3 → 11.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 +6 -3
- package/package.json +6 -2
- package/vscode/src/vs/editor/common/diff/documentDiffProvider.js +8 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityHelp.js +84 -38
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClearActions.js +265 -20
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +20 -39
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContextActions.js +373 -216
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +4 -5
- 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 -5
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatGettingStarted.js +54 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.js +6 -7
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.js +12 -11
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.js +14 -42
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +82 -50
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedFileEntry.js +326 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingService.js +448 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.js +507 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingTextModelContentProviders.js +76 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +4 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditorActions.js +109 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditorController.js +284 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatParticipantContributions.js +116 -77
- package/vscode/src/vs/workbench/contrib/chat/browser/chatPasteProviders.js +100 -9
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/chatResponseAccessibleView.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +7 -9
- package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +61 -42
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +5 -5
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorHover.js +3 -3
- package/vscode/src/vs/workbench/contrib/chat/{common → browser}/languageModelToolsService.js +28 -31
- package/vscode/src/vs/workbench/contrib/chat/browser/viewsWelcome/chatViewsWelcomeContributions.js +75 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatCodeMapperService.js +120 -1
- package/vscode/src/vs/workbench/contrib/chat/common/chatProgressTypes/chatToolInvocation.js +10 -8
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +33 -18
- package/vscode/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/common/ignoredFiles.js +21 -0
- package/vscode/src/vs/workbench/contrib/chat/common/languageModelStats.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/common/languageModels.js +6 -6
- package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsContribution.js +68 -47
- package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsParametersSchema.js +250 -0
- package/vscode/src/vs/workbench/contrib/chat/common/voiceChatService.js +2 -2
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +7 -8
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibilityHelp.js +1 -1
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibleView.js +1 -1
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatCurrentLine.js +3 -3
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatNotebook.js +2 -2
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl.js +65 -128
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.js +0 -170
- package/vscode/src/vs/workbench/contrib/chat/browser/chatGettingStarted.js +0 -131
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
|
+
import { delta, compareBy } from 'vscode/vscode/vs/base/common/arrays';
|
|
3
|
+
import { AsyncIterableSource } from 'vscode/vscode/vs/base/common/async';
|
|
4
|
+
import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
|
|
5
|
+
import { Codicon } from 'vscode/vscode/vs/base/common/codicons';
|
|
6
|
+
import { BugIndicatingError } from 'vscode/vscode/vs/base/common/errors';
|
|
7
|
+
import { Emitter } from 'vscode/vscode/vs/base/common/event';
|
|
8
|
+
import { Disposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
9
|
+
import { ResourceMap } from 'vscode/vscode/vs/base/common/map';
|
|
10
|
+
import { observableValue } from 'vscode/vscode/vs/base/common/observableInternal/base';
|
|
11
|
+
import 'vscode/vscode/vs/base/common/observableInternal/autorun';
|
|
12
|
+
import { derived } from 'vscode/vscode/vs/base/common/observableInternal/derived';
|
|
13
|
+
import { runOnChange, ValueWithChangeEventFromObservable } from 'vscode/vscode/vs/base/common/observableInternal/utils';
|
|
14
|
+
import { compare } from 'vscode/vscode/vs/base/common/strings';
|
|
15
|
+
import { ThemeIcon } from 'vscode/vscode/vs/base/common/themables';
|
|
16
|
+
import { URI } from 'vscode/vscode/vs/base/common/uri';
|
|
17
|
+
import { ITextModelService } from 'vscode/vscode/vs/editor/common/services/resolverService';
|
|
18
|
+
import { localize, localize2 } from 'vscode/vscode/vs/nls';
|
|
19
|
+
import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey.service';
|
|
20
|
+
import { EditorActivation } from 'vscode/vscode/vs/platform/editor/common/editor';
|
|
21
|
+
import { IFileService } from 'vscode/vscode/vs/platform/files/common/files.service';
|
|
22
|
+
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
23
|
+
import { bindContextKey } from 'vscode/vscode/vs/platform/observable/common/platformObservableUtils';
|
|
24
|
+
import { IProgressService } from 'vscode/vscode/vs/platform/progress/common/progress.service';
|
|
25
|
+
import { IWorkbenchAssignmentService } from 'vscode/vscode/vs/workbench/services/assignment/common/assignmentService.service';
|
|
26
|
+
import { IDecorationsService } from 'vscode/vscode/vs/workbench/services/decorations/common/decorations.service';
|
|
27
|
+
import { IEditorGroupsService } from 'vscode/vscode/vs/workbench/services/editor/common/editorGroupsService.service';
|
|
28
|
+
import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService.service';
|
|
29
|
+
import { MultiDiffEditorInput } from 'vscode/vscode/vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditorInput';
|
|
30
|
+
import { MultiDiffEditorItem } from 'vscode/vscode/vs/workbench/contrib/multiDiffEditor/browser/multiDiffSourceResolverService';
|
|
31
|
+
import { IMultiDiffSourceResolverService } from 'vscode/vscode/vs/workbench/contrib/multiDiffEditor/browser/multiDiffSourceResolverService.service';
|
|
32
|
+
import { ICodeMapperService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatCodeMapperService.service';
|
|
33
|
+
import { CONTEXT_CHAT_EDITING_CAN_UNDO, CONTEXT_CHAT_EDITING_CAN_REDO } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatContextKeys';
|
|
34
|
+
import { defaultChatEditingMaxFileLimit, applyingChatEditsFailedContextKey, decidedChatEditingResourceContextKey, hasUndecidedChatEditingResourceContextKey, hasAppliedChatEditsContextKey, inChatEditingSessionContextKey, applyingChatEditsContextKey, chatEditingMaxFileAssignmentName, CHAT_EDITING_MULTI_DIFF_SOURCE_RESOLVER_SCHEME, chatEditingResourceContextKey } from '@codingame/monaco-vscode-chat-extensions-interactive-notebook-quickaccess-search-terminal-common/vscode/vs/workbench/contrib/chat/common/chatEditingService';
|
|
35
|
+
import { IChatService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatService.service';
|
|
36
|
+
import { ChatEditingSession } from './chatEditingSession.js';
|
|
37
|
+
import { ChatEditingTextModelContentProvider, ChatEditingSnapshotTextModelContentProvider } from './chatEditingTextModelContentProviders.js';
|
|
38
|
+
|
|
39
|
+
var ChatEditingMultiDiffSourceResolver_1;
|
|
40
|
+
let ChatEditingService = class ChatEditingService extends Disposable {
|
|
41
|
+
get currentAutoApplyOperation() {
|
|
42
|
+
return this._currentAutoApplyOperationObs.get();
|
|
43
|
+
}
|
|
44
|
+
get currentEditingSession() {
|
|
45
|
+
return this._currentSessionObs.get();
|
|
46
|
+
}
|
|
47
|
+
get currentEditingSessionObs() {
|
|
48
|
+
return this._currentSessionObs;
|
|
49
|
+
}
|
|
50
|
+
get onDidCreateEditingSession() {
|
|
51
|
+
return this._onDidCreateEditingSession.event;
|
|
52
|
+
}
|
|
53
|
+
get editingSessionFileLimit() {
|
|
54
|
+
return this._editingSessionFileLimit ?? defaultChatEditingMaxFileLimit;
|
|
55
|
+
}
|
|
56
|
+
constructor(_editorGroupsService, _instantiationService, multiDiffSourceResolverService, textModelService, contextKeyService, _chatService, _progressService, _codeMapperService, _editorService, decorationsService, _fileService, _workbenchAssignmentService) {
|
|
57
|
+
super();
|
|
58
|
+
this._editorGroupsService = _editorGroupsService;
|
|
59
|
+
this._instantiationService = _instantiationService;
|
|
60
|
+
this._chatService = _chatService;
|
|
61
|
+
this._progressService = _progressService;
|
|
62
|
+
this._codeMapperService = _codeMapperService;
|
|
63
|
+
this._editorService = _editorService;
|
|
64
|
+
this._fileService = _fileService;
|
|
65
|
+
this._workbenchAssignmentService = _workbenchAssignmentService;
|
|
66
|
+
this._currentSessionObs = observableValue(this, null);
|
|
67
|
+
this._currentSessionDisposables = this._register(( (new DisposableStore())));
|
|
68
|
+
this._currentAutoApplyOperationObs = observableValue(this, null);
|
|
69
|
+
this._onDidCreateEditingSession = this._register(( (new Emitter())));
|
|
70
|
+
this._onDidChangeEditingSession = this._register(( (new Emitter())));
|
|
71
|
+
this.onDidChangeEditingSession = this._onDidChangeEditingSession.event;
|
|
72
|
+
this._applyingChatEditsFailedContextKey = applyingChatEditsFailedContextKey.bindTo(contextKeyService);
|
|
73
|
+
this._applyingChatEditsFailedContextKey.set(false);
|
|
74
|
+
this._register(decorationsService.registerDecorationsProvider(( (new ChatDecorationsProvider(this._currentSessionObs)))));
|
|
75
|
+
this._register(multiDiffSourceResolverService.registerResolver(_instantiationService.createInstance(ChatEditingMultiDiffSourceResolver, this._currentSessionObs)));
|
|
76
|
+
textModelService.registerTextModelContentProvider(ChatEditingTextModelContentProvider.scheme, _instantiationService.createInstance(ChatEditingTextModelContentProvider, this._currentSessionObs));
|
|
77
|
+
textModelService.registerTextModelContentProvider(ChatEditingSnapshotTextModelContentProvider.scheme, _instantiationService.createInstance(ChatEditingSnapshotTextModelContentProvider, this._currentSessionObs));
|
|
78
|
+
this._register(bindContextKey(decidedChatEditingResourceContextKey, contextKeyService, (reader) => {
|
|
79
|
+
const currentSession = this._currentSessionObs.read(reader);
|
|
80
|
+
if (!currentSession) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const entries = currentSession.entries.read(reader);
|
|
84
|
+
const decidedEntries = entries.filter(entry => entry.state.read(reader) !== 0 );
|
|
85
|
+
return (
|
|
86
|
+
(decidedEntries.map(entry => entry.entryId))
|
|
87
|
+
);
|
|
88
|
+
}));
|
|
89
|
+
this._register(bindContextKey(hasUndecidedChatEditingResourceContextKey, contextKeyService, (reader) => {
|
|
90
|
+
const currentSession = this._currentSessionObs.read(reader);
|
|
91
|
+
if (!currentSession) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const entries = currentSession.entries.read(reader);
|
|
95
|
+
const decidedEntries = entries.filter(entry => entry.state.read(reader) === 0 );
|
|
96
|
+
return decidedEntries.length > 0;
|
|
97
|
+
}));
|
|
98
|
+
this._register(bindContextKey(hasAppliedChatEditsContextKey, contextKeyService, (reader) => {
|
|
99
|
+
const currentSession = this._currentSessionObs.read(reader);
|
|
100
|
+
if (!currentSession) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const entries = currentSession.entries.read(reader);
|
|
104
|
+
return entries.length > 0;
|
|
105
|
+
}));
|
|
106
|
+
this._register(bindContextKey(inChatEditingSessionContextKey, contextKeyService, (reader) => {
|
|
107
|
+
return this._currentSessionObs.read(reader) !== null;
|
|
108
|
+
}));
|
|
109
|
+
this._register(bindContextKey(applyingChatEditsContextKey, contextKeyService, (reader) => {
|
|
110
|
+
return this._currentAutoApplyOperationObs.read(reader) !== null;
|
|
111
|
+
}));
|
|
112
|
+
this._register(bindContextKey(CONTEXT_CHAT_EDITING_CAN_UNDO, contextKeyService, (r) => {
|
|
113
|
+
return this._currentSessionObs.read(r)?.canUndo.read(r) || false;
|
|
114
|
+
}));
|
|
115
|
+
this._register(bindContextKey(CONTEXT_CHAT_EDITING_CAN_REDO, contextKeyService, (r) => {
|
|
116
|
+
return this._currentSessionObs.read(r)?.canRedo.read(r) || false;
|
|
117
|
+
}));
|
|
118
|
+
this._register(this._chatService.onDidDisposeSession((e) => {
|
|
119
|
+
if (e.reason === 'cleared' && this._currentSessionObs.get()?.chatSessionId === e.sessionId) {
|
|
120
|
+
void this._currentSessionObs.get()?.stop();
|
|
121
|
+
}
|
|
122
|
+
}));
|
|
123
|
+
this._editingSessionFileLimitPromise = this._workbenchAssignmentService.getTreatment(chatEditingMaxFileAssignmentName).then(value => {
|
|
124
|
+
this._editingSessionFileLimit = value ?? defaultChatEditingMaxFileLimit;
|
|
125
|
+
return this._editingSessionFileLimit;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
getSnapshotUri(id, uri) {
|
|
129
|
+
const session = this._currentSessionObs.get();
|
|
130
|
+
if (!session) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
return session.getSnapshot(id, uri)?.snapshotUri;
|
|
134
|
+
}
|
|
135
|
+
getEditingSession(resource) {
|
|
136
|
+
const session = this.currentEditingSession;
|
|
137
|
+
if (!session) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
const entries = session.entries.get();
|
|
141
|
+
for (const entry of entries) {
|
|
142
|
+
if (( (entry.modifiedURI.toString())) === ( (resource.toString()))) {
|
|
143
|
+
return session;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
dispose() {
|
|
149
|
+
this._currentSessionObs.get()?.dispose();
|
|
150
|
+
super.dispose();
|
|
151
|
+
}
|
|
152
|
+
async startOrContinueEditingSession(chatSessionId, options) {
|
|
153
|
+
const session = this._currentSessionObs.get();
|
|
154
|
+
if (session) {
|
|
155
|
+
if (session.chatSessionId !== chatSessionId) {
|
|
156
|
+
throw ( (new BugIndicatingError('Cannot start new session while another session is active')));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return this._createEditingSession(chatSessionId, options);
|
|
160
|
+
}
|
|
161
|
+
async _createEditingSession(chatSessionId, options) {
|
|
162
|
+
if (this._currentSessionObs.get()) {
|
|
163
|
+
throw ( (new BugIndicatingError('Cannot have more than one active editing session')));
|
|
164
|
+
}
|
|
165
|
+
this._currentSessionDisposables.clear();
|
|
166
|
+
this._currentSessionDisposables.add(this.installAutoApplyObserver(chatSessionId));
|
|
167
|
+
const input = MultiDiffEditorInput.fromResourceMultiDiffEditorInput({
|
|
168
|
+
multiDiffSource: ChatEditingMultiDiffSourceResolver.getMultiDiffSourceUri(),
|
|
169
|
+
label: ( localize(2734, "Suggested Edits"))
|
|
170
|
+
}, this._instantiationService);
|
|
171
|
+
const editorPane = options?.silent ? undefined : await this._editorGroupsService.activeGroup.openEditor(input, { pinned: true, activation: EditorActivation.ACTIVATE });
|
|
172
|
+
const session = this._instantiationService.createInstance(ChatEditingSession, chatSessionId, editorPane, this._editingSessionFileLimitPromise);
|
|
173
|
+
this._currentSessionDisposables.add(session.onDidDispose(() => {
|
|
174
|
+
this._currentSessionDisposables.clear();
|
|
175
|
+
this._currentSessionObs.set(null, undefined);
|
|
176
|
+
this._onDidChangeEditingSession.fire();
|
|
177
|
+
}));
|
|
178
|
+
this._currentSessionDisposables.add(session.onDidChange(() => {
|
|
179
|
+
this._onDidChangeEditingSession.fire();
|
|
180
|
+
}));
|
|
181
|
+
this._currentSessionObs.set(session, undefined);
|
|
182
|
+
this._onDidCreateEditingSession.fire(session);
|
|
183
|
+
this._onDidChangeEditingSession.fire();
|
|
184
|
+
return session;
|
|
185
|
+
}
|
|
186
|
+
triggerEditComputation(responseModel) {
|
|
187
|
+
return this._continueEditingSession(async (builder, token) => {
|
|
188
|
+
const codeMapperResponse = {
|
|
189
|
+
textEdit: (resource, edits) => builder.textEdits(resource, edits, responseModel),
|
|
190
|
+
};
|
|
191
|
+
await this._codeMapperService.mapCodeFromResponse(responseModel, codeMapperResponse, token);
|
|
192
|
+
}, { silent: true });
|
|
193
|
+
}
|
|
194
|
+
createSnapshot(requestId) {
|
|
195
|
+
this._currentSessionObs.get()?.createSnapshot(requestId);
|
|
196
|
+
}
|
|
197
|
+
async restoreSnapshot(requestId) {
|
|
198
|
+
await this._currentSessionObs.get()?.restoreSnapshot(requestId);
|
|
199
|
+
}
|
|
200
|
+
installAutoApplyObserver(sessionId) {
|
|
201
|
+
const chatModel = this._chatService.getSession(sessionId);
|
|
202
|
+
if (!chatModel) {
|
|
203
|
+
throw ( (new Error(`Edit session was created for a non-existing chat session: ${sessionId}`)));
|
|
204
|
+
}
|
|
205
|
+
const observerDisposables = ( (new DisposableStore()));
|
|
206
|
+
let editsSource;
|
|
207
|
+
const editsSeen = ( (new ResourceMap()));
|
|
208
|
+
const editedFilesExist = ( (new ResourceMap()));
|
|
209
|
+
const onResponseComplete = (responseModel) => {
|
|
210
|
+
if (responseModel.result?.errorDetails) {
|
|
211
|
+
this.restoreSnapshot(responseModel.requestId);
|
|
212
|
+
this._applyingChatEditsFailedContextKey.set(true);
|
|
213
|
+
}
|
|
214
|
+
else if (responseModel.result?.metadata?.autoApplyEdits) {
|
|
215
|
+
this.triggerEditComputation(responseModel);
|
|
216
|
+
}
|
|
217
|
+
editsSource?.resolve();
|
|
218
|
+
editsSource = undefined;
|
|
219
|
+
editsSeen.clear();
|
|
220
|
+
editedFilesExist.clear();
|
|
221
|
+
};
|
|
222
|
+
const handleResponseParts = (responseModel) => {
|
|
223
|
+
for (const part of responseModel.response.value) {
|
|
224
|
+
if (part.kind === 'codeblockUri' || part.kind === 'textEditGroup') {
|
|
225
|
+
if (!editedFilesExist.get(part.uri)) {
|
|
226
|
+
editedFilesExist.set(part.uri, this._fileService.exists(part.uri).then((e) => {
|
|
227
|
+
if (e) {
|
|
228
|
+
this._editorService.openEditor({ resource: part.uri, options: { inactive: true, preserveFocus: true, pinned: true } });
|
|
229
|
+
}
|
|
230
|
+
return e;
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
const first = editsSeen.size === 0;
|
|
234
|
+
let entry = editsSeen.get(part.uri);
|
|
235
|
+
if (!entry) {
|
|
236
|
+
entry = { seen: 0 };
|
|
237
|
+
editsSeen.set(part.uri, entry);
|
|
238
|
+
}
|
|
239
|
+
const allEdits = part.kind === 'textEditGroup' ? part.edits : [];
|
|
240
|
+
const newEdits = allEdits.slice(entry.seen);
|
|
241
|
+
entry.seen += newEdits.length;
|
|
242
|
+
editsSource ??= ( (new AsyncIterableSource()));
|
|
243
|
+
editsSource.emitOne({ uri: part.uri, edits: newEdits, kind: 'textEditGroup' });
|
|
244
|
+
if (first) {
|
|
245
|
+
this._continueEditingSession(async (builder, token) => {
|
|
246
|
+
for await (const item of editsSource.asyncIterable) {
|
|
247
|
+
if (token.isCancellationRequested) {
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
for (const group of item.edits) {
|
|
251
|
+
builder.textEdits(item.uri, group, responseModel);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}, { silent: true });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
observerDisposables.add(chatModel.onDidChange(e => {
|
|
260
|
+
if (e.kind === 'addRequest') {
|
|
261
|
+
this._applyingChatEditsFailedContextKey.set(false);
|
|
262
|
+
const responseModel = e.request.response;
|
|
263
|
+
if (responseModel) {
|
|
264
|
+
if (responseModel.isComplete) {
|
|
265
|
+
handleResponseParts(responseModel);
|
|
266
|
+
onResponseComplete(responseModel);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
const disposable = responseModel.onDidChange(() => {
|
|
270
|
+
handleResponseParts(responseModel);
|
|
271
|
+
if (responseModel.isComplete) {
|
|
272
|
+
onResponseComplete(responseModel);
|
|
273
|
+
disposable.dispose();
|
|
274
|
+
}
|
|
275
|
+
else if (responseModel.isCanceled || responseModel.isStale) {
|
|
276
|
+
disposable.dispose();
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}));
|
|
283
|
+
observerDisposables.add(chatModel.onDidDispose(() => observerDisposables.dispose()));
|
|
284
|
+
return observerDisposables;
|
|
285
|
+
}
|
|
286
|
+
async _continueEditingSession(builder, options) {
|
|
287
|
+
const session = this._currentSessionObs.get();
|
|
288
|
+
if (!session) {
|
|
289
|
+
throw ( (new BugIndicatingError('Cannot continue missing session')));
|
|
290
|
+
}
|
|
291
|
+
if (session.state.get() === 1 ) {
|
|
292
|
+
throw ( (new BugIndicatingError('Cannot continue session that is still streaming')));
|
|
293
|
+
}
|
|
294
|
+
let editorPane;
|
|
295
|
+
if (!options?.silent && session.isVisible) {
|
|
296
|
+
const groupedEditors = this._findGroupedEditors();
|
|
297
|
+
if (groupedEditors.length !== 1) {
|
|
298
|
+
throw ( (new Error(`Unexpected number of editors: ${groupedEditors.length}`)));
|
|
299
|
+
}
|
|
300
|
+
const [group, editor] = groupedEditors[0];
|
|
301
|
+
editorPane = await group.openEditor(editor, { pinned: true, activation: EditorActivation.ACTIVATE });
|
|
302
|
+
}
|
|
303
|
+
const stream = {
|
|
304
|
+
textEdits: (resource, textEdits, responseModel) => {
|
|
305
|
+
session.acceptTextEdits(resource, textEdits, responseModel);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
session.acceptStreamingEditsStart();
|
|
309
|
+
const cancellationTokenSource = ( (new CancellationTokenSource()));
|
|
310
|
+
this._currentAutoApplyOperationObs.set(cancellationTokenSource, undefined);
|
|
311
|
+
try {
|
|
312
|
+
if (editorPane) {
|
|
313
|
+
await editorPane?.showWhile(builder(stream, cancellationTokenSource.token));
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
await this._progressService.withProgress({
|
|
317
|
+
location: 10 ,
|
|
318
|
+
title: ( localize2(2735, 'Generating edits...')).value,
|
|
319
|
+
}, async () => {
|
|
320
|
+
await builder(stream, cancellationTokenSource.token);
|
|
321
|
+
}, () => cancellationTokenSource.cancel());
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
finally {
|
|
325
|
+
cancellationTokenSource.dispose();
|
|
326
|
+
this._currentAutoApplyOperationObs.set(null, undefined);
|
|
327
|
+
session.resolve();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
_findGroupedEditors() {
|
|
331
|
+
const editors = [];
|
|
332
|
+
for (const group of this._editorGroupsService.groups) {
|
|
333
|
+
for (const editor of group.editors) {
|
|
334
|
+
if (editor.resource?.scheme === ChatEditingMultiDiffSourceResolver.scheme) {
|
|
335
|
+
editors.push([group, editor]);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return editors;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
ChatEditingService = ( (__decorate([
|
|
343
|
+
( (__param(0, IEditorGroupsService))),
|
|
344
|
+
( (__param(1, IInstantiationService))),
|
|
345
|
+
( (__param(2, IMultiDiffSourceResolverService))),
|
|
346
|
+
( (__param(3, ITextModelService))),
|
|
347
|
+
( (__param(4, IContextKeyService))),
|
|
348
|
+
( (__param(5, IChatService))),
|
|
349
|
+
( (__param(6, IProgressService))),
|
|
350
|
+
( (__param(7, ICodeMapperService))),
|
|
351
|
+
( (__param(8, IEditorService))),
|
|
352
|
+
( (__param(9, IDecorationsService))),
|
|
353
|
+
( (__param(10, IFileService))),
|
|
354
|
+
( (__param(11, IWorkbenchAssignmentService)))
|
|
355
|
+
], ChatEditingService)));
|
|
356
|
+
function observeArrayChanges(obs, compare, store) {
|
|
357
|
+
const emitter = store.add(( (new Emitter())));
|
|
358
|
+
store.add(runOnChange(obs, (newArr, oldArr) => {
|
|
359
|
+
const change = delta(oldArr || [], newArr, compare);
|
|
360
|
+
const changedElements = [].concat(change.added).concat(change.removed);
|
|
361
|
+
emitter.fire(changedElements);
|
|
362
|
+
}));
|
|
363
|
+
return emitter.event;
|
|
364
|
+
}
|
|
365
|
+
class ChatDecorationsProvider extends Disposable {
|
|
366
|
+
constructor(_session) {
|
|
367
|
+
super();
|
|
368
|
+
this._session = _session;
|
|
369
|
+
this.label = ( localize(2736, "Chat Editing"));
|
|
370
|
+
this._currentlyEditingUris = derived(this, (r) => {
|
|
371
|
+
const session = this._session.read(r);
|
|
372
|
+
if (!session) {
|
|
373
|
+
return [];
|
|
374
|
+
}
|
|
375
|
+
const state = session.state.read(r);
|
|
376
|
+
if (state === 3 ) {
|
|
377
|
+
return [];
|
|
378
|
+
}
|
|
379
|
+
return (
|
|
380
|
+
(session.entries.read(r).filter(entry => entry.isCurrentlyBeingModified.read(r)).map(entry => entry.modifiedURI))
|
|
381
|
+
);
|
|
382
|
+
});
|
|
383
|
+
this.onDidChange = observeArrayChanges(this._currentlyEditingUris, compareBy(uri => ( (uri.toString())), compare), this._store);
|
|
384
|
+
}
|
|
385
|
+
provideDecorations(uri, _token) {
|
|
386
|
+
const isCurrentlyBeingModified = ( (this._currentlyEditingUris.get().some(e => ( (e.toString())) === ( (uri.toString())))));
|
|
387
|
+
if (!isCurrentlyBeingModified) {
|
|
388
|
+
return undefined;
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
weight: 1000,
|
|
392
|
+
letter: ThemeIcon.modify(Codicon.loading, 'spin'),
|
|
393
|
+
bubble: false
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
let ChatEditingMultiDiffSourceResolver = class ChatEditingMultiDiffSourceResolver {
|
|
398
|
+
static { ChatEditingMultiDiffSourceResolver_1 = this; }
|
|
399
|
+
static { this.scheme = CHAT_EDITING_MULTI_DIFF_SOURCE_RESOLVER_SCHEME; }
|
|
400
|
+
static getMultiDiffSourceUri() {
|
|
401
|
+
return (
|
|
402
|
+
(URI.from({
|
|
403
|
+
scheme: ChatEditingMultiDiffSourceResolver_1.scheme,
|
|
404
|
+
path: '',
|
|
405
|
+
}))
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
constructor(_currentSession, _instantiationService) {
|
|
409
|
+
this._currentSession = _currentSession;
|
|
410
|
+
this._instantiationService = _instantiationService;
|
|
411
|
+
}
|
|
412
|
+
canHandleUri(uri) {
|
|
413
|
+
return uri.scheme === ChatEditingMultiDiffSourceResolver_1.scheme;
|
|
414
|
+
}
|
|
415
|
+
async resolveDiffSource(uri) {
|
|
416
|
+
return this._instantiationService.createInstance(ChatEditingMultiDiffSource, this._currentSession);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
ChatEditingMultiDiffSourceResolver = ChatEditingMultiDiffSourceResolver_1 = ( (__decorate([
|
|
420
|
+
( (__param(1, IInstantiationService)))
|
|
421
|
+
], ChatEditingMultiDiffSourceResolver)));
|
|
422
|
+
class ChatEditingMultiDiffSource {
|
|
423
|
+
constructor(_currentSession) {
|
|
424
|
+
this._currentSession = _currentSession;
|
|
425
|
+
this._resources = derived(this, (reader) => {
|
|
426
|
+
const currentSession = this._currentSession.read(reader);
|
|
427
|
+
if (!currentSession) {
|
|
428
|
+
return [];
|
|
429
|
+
}
|
|
430
|
+
const entries = currentSession.entries.read(reader);
|
|
431
|
+
return (
|
|
432
|
+
(entries.map((entry) => {
|
|
433
|
+
return (
|
|
434
|
+
(new MultiDiffEditorItem(entry.originalURI, entry.modifiedURI, undefined, {
|
|
435
|
+
[chatEditingResourceContextKey.key]: entry.entryId,
|
|
436
|
+
}))
|
|
437
|
+
);
|
|
438
|
+
}))
|
|
439
|
+
);
|
|
440
|
+
});
|
|
441
|
+
this.resources = ( (new ValueWithChangeEventFromObservable(this._resources)));
|
|
442
|
+
this.contextKeys = {
|
|
443
|
+
[inChatEditingSessionContextKey.key]: true
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export { ChatEditingMultiDiffSourceResolver, ChatEditingService };
|