@codingame/monaco-vscode-notebook-service-override 2.2.2 → 3.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/package.json +2 -2
- package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.js +6 -1
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/cellCommands.js +101 -161
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.js +4 -5
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.js +85 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/gettingStarted/notebookGettingStarted.js +8 -11
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider.js +3 -5
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.js +34 -12
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariableContextKeys.js +5 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.js +55 -17
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.js +39 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.js +1 -41
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout.js +17 -26
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/undoRedo/notebookUndoRedo.js +3 -4
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/cellChatActions.js +565 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/notebookChatContext.js +31 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController.js +744 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/executeActions.js +28 -23
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.js +351 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/layoutActions.js +41 -42
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.js +31 -13
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.js +4 -4
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.js +4 -4
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.js +25 -16
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.js +118 -6
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl.js +6 -6
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl.js +6 -9
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.js +2 -3
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.js +3 -39
- package/vscode/src/vs/workbench/contrib/search/browser/notebookSearch/notebookSearchService.js +43 -11
- package/vscode/src/vs/workbench/services/workingCopy/common/fileWorkingCopyManager.js +5 -1
package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController.js
ADDED
|
@@ -0,0 +1,744 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { getWindow, scheduleAtNextAnimationFrame, trackFocus, WindowIntervalTimer, Dimension } from 'vscode/vscode/vs/base/browser/dom';
|
|
3
|
+
import { disposableTimeout, createCancelablePromise, Queue, raceCancellationError } from 'vscode/vscode/vs/base/common/async';
|
|
4
|
+
import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
|
|
5
|
+
import { Event } from 'vscode/vscode/vs/base/common/event';
|
|
6
|
+
import { MarkdownString } from 'vscode/vscode/vs/base/common/htmlContent';
|
|
7
|
+
import { Disposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
8
|
+
import { Schemas } from 'vscode/vscode/vs/base/common/network';
|
|
9
|
+
import { MovingAverage } from 'vscode/vscode/vs/base/common/numbers';
|
|
10
|
+
import { StopWatch } from 'vscode/vscode/vs/base/common/stopwatch';
|
|
11
|
+
import { assertType } from 'vscode/vscode/vs/base/common/types';
|
|
12
|
+
import { generateUuid } from 'vscode/vscode/vs/base/common/uuid';
|
|
13
|
+
import { CodeEditorWidget } from 'vscode/vscode/vs/editor/browser/widget/codeEditorWidget';
|
|
14
|
+
import { Selection } from 'vscode/vscode/vs/editor/common/core/selection';
|
|
15
|
+
import { TextEdit } from 'vscode/vscode/vs/editor/common/languages';
|
|
16
|
+
import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
|
|
17
|
+
import { IEditorWorkerService } from 'vscode/vscode/vs/editor/common/services/editorWorker';
|
|
18
|
+
import { IModelService } from 'vscode/vscode/vs/editor/common/services/model';
|
|
19
|
+
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
20
|
+
import { ICommandService } from 'vscode/vscode/vs/platform/commands/common/commands';
|
|
21
|
+
import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
|
|
22
|
+
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
23
|
+
import { AsyncProgress } from 'vscode/vscode/vs/platform/progress/common/progress';
|
|
24
|
+
import { countWords } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatWordCounter';
|
|
25
|
+
import { IInlineChatSavingService } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatSavingService';
|
|
26
|
+
import { SessionPrompt, EmptyResponse, ReplyResponse, ErrorResponse, SessionExchange } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatSession';
|
|
27
|
+
import { IInlineChatSessionService } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService';
|
|
28
|
+
import { InlineChatWidget } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/inlineChatWidget';
|
|
29
|
+
import { performAsyncTextEdit, asProgressiveEdit } from 'vscode/vscode/vs/workbench/contrib/inlineChat/browser/utils';
|
|
30
|
+
import { CTX_INLINE_CHAT_LAST_RESPONSE_TYPE } from 'vscode/vscode/vs/workbench/contrib/inlineChat/common/inlineChat';
|
|
31
|
+
import { insertCell, runDeleteAction } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/controller/cellOperations';
|
|
32
|
+
import { CTX_NOTEBOOK_CHAT_HAS_ACTIVE_REQUEST, CTX_NOTEBOOK_CELL_CHAT_FOCUSED, CTX_NOTEBOOK_CHAT_USER_DID_EDIT, CTX_NOTEBOOK_CHAT_OUTER_FOCUS_POSITION, MENU_CELL_CHAT_INPUT, MENU_CELL_CHAT_WIDGET, MENU_CELL_CHAT_WIDGET_STATUS, MENU_CELL_CHAT_WIDGET_FEEDBACK } from './notebookChatContext.js';
|
|
33
|
+
import { ScrollToRevealBehavior } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
|
|
34
|
+
import { registerNotebookContribution } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
|
|
35
|
+
import { CellKind } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
|
|
36
|
+
import { NotebookExecutionType, INotebookExecutionStateService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookExecutionStateService';
|
|
37
|
+
|
|
38
|
+
var NotebookChatController_1;
|
|
39
|
+
const WIDGET_MARGIN_BOTTOM = 16;
|
|
40
|
+
class NotebookChatWidget extends Disposable {
|
|
41
|
+
set afterModelPosition(afterModelPosition) {
|
|
42
|
+
this.notebookViewZone.afterModelPosition = afterModelPosition;
|
|
43
|
+
}
|
|
44
|
+
get afterModelPosition() {
|
|
45
|
+
return this.notebookViewZone.afterModelPosition;
|
|
46
|
+
}
|
|
47
|
+
set heightInPx(heightInPx) {
|
|
48
|
+
this.notebookViewZone.heightInPx = heightInPx;
|
|
49
|
+
}
|
|
50
|
+
get heightInPx() {
|
|
51
|
+
return this.notebookViewZone.heightInPx;
|
|
52
|
+
}
|
|
53
|
+
get editingCell() {
|
|
54
|
+
return this._editingCell;
|
|
55
|
+
}
|
|
56
|
+
constructor(_notebookEditor, id, notebookViewZone, domNode, widgetContainer, inlineChatWidget, parentEditor, _languageService) {
|
|
57
|
+
super();
|
|
58
|
+
this._notebookEditor = _notebookEditor;
|
|
59
|
+
this.id = id;
|
|
60
|
+
this.notebookViewZone = notebookViewZone;
|
|
61
|
+
this.domNode = domNode;
|
|
62
|
+
this.widgetContainer = widgetContainer;
|
|
63
|
+
this.inlineChatWidget = inlineChatWidget;
|
|
64
|
+
this.parentEditor = parentEditor;
|
|
65
|
+
this._languageService = _languageService;
|
|
66
|
+
this._editingCell = null;
|
|
67
|
+
this._register(inlineChatWidget.onDidChangeHeight(() => {
|
|
68
|
+
this.heightInPx = inlineChatWidget.getHeight() + WIDGET_MARGIN_BOTTOM;
|
|
69
|
+
this._notebookEditor.changeViewZones(accessor => {
|
|
70
|
+
accessor.layoutZone(id);
|
|
71
|
+
});
|
|
72
|
+
this._layoutWidget(inlineChatWidget, widgetContainer);
|
|
73
|
+
}));
|
|
74
|
+
this._layoutWidget(inlineChatWidget, widgetContainer);
|
|
75
|
+
}
|
|
76
|
+
focus() {
|
|
77
|
+
this.inlineChatWidget.focus();
|
|
78
|
+
}
|
|
79
|
+
getEditingCell() {
|
|
80
|
+
return this._editingCell;
|
|
81
|
+
}
|
|
82
|
+
async getOrCreateEditingCell() {
|
|
83
|
+
if (this._editingCell) {
|
|
84
|
+
await this._notebookEditor.focusNotebookCell(this._editingCell, 'editor');
|
|
85
|
+
if (this._notebookEditor.activeCodeEditor?.hasModel()) {
|
|
86
|
+
return {
|
|
87
|
+
cell: this._editingCell,
|
|
88
|
+
editor: this._notebookEditor.activeCodeEditor
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!this._notebookEditor.hasModel()) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
this._editingCell = insertCell(this._languageService, this._notebookEditor, this.afterModelPosition, CellKind.Code, 'above');
|
|
99
|
+
if (!this._editingCell) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
await this._notebookEditor.focusNotebookCell(this._editingCell, 'editor', { revealBehavior: ScrollToRevealBehavior.firstLine });
|
|
103
|
+
if (this._notebookEditor.activeCodeEditor?.hasModel()) {
|
|
104
|
+
return {
|
|
105
|
+
cell: this._editingCell,
|
|
106
|
+
editor: this._notebookEditor.activeCodeEditor
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
async discardChange() {
|
|
112
|
+
if (this._notebookEditor.hasModel() && this._editingCell) {
|
|
113
|
+
runDeleteAction(this._notebookEditor, this._editingCell);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
_layoutWidget(inlineChatWidget, widgetContainer) {
|
|
117
|
+
const layoutConfiguration = this._notebookEditor.notebookOptions.getLayoutConfiguration();
|
|
118
|
+
const rightMargin = layoutConfiguration.cellRightMargin;
|
|
119
|
+
const leftMargin = this._notebookEditor.notebookOptions.getCellEditorContainerLeftMargin();
|
|
120
|
+
const maxWidth = !inlineChatWidget.showsAnyPreview() ? 640 : Number.MAX_SAFE_INTEGER;
|
|
121
|
+
const width = Math.min(maxWidth, this._notebookEditor.getLayoutInfo().width - leftMargin - rightMargin);
|
|
122
|
+
inlineChatWidget.layout(( new Dimension(width, 80 + WIDGET_MARGIN_BOTTOM)));
|
|
123
|
+
inlineChatWidget.domNode.style.width = `${width}px`;
|
|
124
|
+
widgetContainer.style.left = `${leftMargin}px`;
|
|
125
|
+
}
|
|
126
|
+
dispose() {
|
|
127
|
+
this._notebookEditor.changeViewZones(accessor => {
|
|
128
|
+
accessor.removeZone(this.id);
|
|
129
|
+
});
|
|
130
|
+
this.domNode.remove();
|
|
131
|
+
super.dispose();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
let NotebookChatController = class NotebookChatController extends Disposable {
|
|
135
|
+
static { NotebookChatController_1 = this; }
|
|
136
|
+
static { this.id = 'workbench.notebook.chatController'; }
|
|
137
|
+
static { this.counter = 0; }
|
|
138
|
+
static get(editor) {
|
|
139
|
+
return editor.getContribution(NotebookChatController_1.id);
|
|
140
|
+
}
|
|
141
|
+
constructor(_notebookEditor, _instantiationService, _inlineChatSessionService, _contextKeyService, _commandService, _editorWorkerService, _inlineChatSavingService, _modelService, _languageService, _executionStateService) {
|
|
142
|
+
super();
|
|
143
|
+
this._notebookEditor = _notebookEditor;
|
|
144
|
+
this._instantiationService = _instantiationService;
|
|
145
|
+
this._inlineChatSessionService = _inlineChatSessionService;
|
|
146
|
+
this._contextKeyService = _contextKeyService;
|
|
147
|
+
this._commandService = _commandService;
|
|
148
|
+
this._editorWorkerService = _editorWorkerService;
|
|
149
|
+
this._inlineChatSavingService = _inlineChatSavingService;
|
|
150
|
+
this._modelService = _modelService;
|
|
151
|
+
this._languageService = _languageService;
|
|
152
|
+
this._executionStateService = _executionStateService;
|
|
153
|
+
this._userEditingDisposables = this._register(( new DisposableStore()));
|
|
154
|
+
this._widgetDisposableStore = this._register(( new DisposableStore()));
|
|
155
|
+
this._ctxHasActiveRequest = CTX_NOTEBOOK_CHAT_HAS_ACTIVE_REQUEST.bindTo(this._contextKeyService);
|
|
156
|
+
this._ctxCellWidgetFocused = CTX_NOTEBOOK_CELL_CHAT_FOCUSED.bindTo(this._contextKeyService);
|
|
157
|
+
this._ctxLastResponseType = CTX_INLINE_CHAT_LAST_RESPONSE_TYPE.bindTo(this._contextKeyService);
|
|
158
|
+
this._ctxUserDidEdit = CTX_NOTEBOOK_CHAT_USER_DID_EDIT.bindTo(this._contextKeyService);
|
|
159
|
+
this._ctxOuterFocusPosition = CTX_NOTEBOOK_CHAT_OUTER_FOCUS_POSITION.bindTo(this._contextKeyService);
|
|
160
|
+
this._registerFocusTracker();
|
|
161
|
+
}
|
|
162
|
+
_registerFocusTracker() {
|
|
163
|
+
this._register(this._notebookEditor.onDidChangeFocus(() => {
|
|
164
|
+
if (!this._widget) {
|
|
165
|
+
this._ctxOuterFocusPosition.set('');
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const widgetIndex = this._widget.afterModelPosition;
|
|
169
|
+
const focus = this._notebookEditor.getFocus().start;
|
|
170
|
+
if (focus + 1 === widgetIndex) {
|
|
171
|
+
this._ctxOuterFocusPosition.set('above');
|
|
172
|
+
}
|
|
173
|
+
else if (focus === widgetIndex) {
|
|
174
|
+
this._ctxOuterFocusPosition.set('below');
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
this._ctxOuterFocusPosition.set('');
|
|
178
|
+
}
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
181
|
+
run(index, input, autoSend) {
|
|
182
|
+
if (this._widget) {
|
|
183
|
+
if (this._widget.afterModelPosition === index) ;
|
|
184
|
+
else {
|
|
185
|
+
const window = getWindow(this._widget.domNode);
|
|
186
|
+
this._widget.dispose();
|
|
187
|
+
this._widget = undefined;
|
|
188
|
+
this._widgetDisposableStore.clear();
|
|
189
|
+
scheduleAtNextAnimationFrame(window, () => {
|
|
190
|
+
this._createWidget(index, input, autoSend);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
this._createWidget(index, input, autoSend);
|
|
196
|
+
}
|
|
197
|
+
_createWidget(index, input, autoSend) {
|
|
198
|
+
if (!this._notebookEditor.hasModel()) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
this._widgetDisposableStore.clear();
|
|
202
|
+
const viewZoneContainer = document.createElement('div');
|
|
203
|
+
viewZoneContainer.classList.add('monaco-editor');
|
|
204
|
+
const widgetContainer = document.createElement('div');
|
|
205
|
+
widgetContainer.style.position = 'absolute';
|
|
206
|
+
viewZoneContainer.appendChild(widgetContainer);
|
|
207
|
+
this._focusTracker = this._widgetDisposableStore.add(trackFocus(viewZoneContainer));
|
|
208
|
+
this._widgetDisposableStore.add(this._focusTracker.onDidFocus(() => {
|
|
209
|
+
this._updateNotebookEditorFocusNSelections();
|
|
210
|
+
}));
|
|
211
|
+
const fakeParentEditorElement = document.createElement('div');
|
|
212
|
+
const fakeParentEditor = this._widgetDisposableStore.add(this._instantiationService.createInstance(CodeEditorWidget, fakeParentEditorElement, {}, { isSimpleWidget: true }));
|
|
213
|
+
const inputBoxFragment = `notebook-chat-input-${NotebookChatController_1.counter++}`;
|
|
214
|
+
const notebookUri = this._notebookEditor.textModel.uri;
|
|
215
|
+
const inputUri = notebookUri.with({ scheme: Schemas.untitled, fragment: inputBoxFragment });
|
|
216
|
+
const result = this._modelService.createModel('', null, inputUri, false);
|
|
217
|
+
fakeParentEditor.setModel(result);
|
|
218
|
+
const inlineChatWidget = this._widgetDisposableStore.add(this._instantiationService.createInstance(InlineChatWidget, fakeParentEditor, {
|
|
219
|
+
menuId: MENU_CELL_CHAT_INPUT,
|
|
220
|
+
widgetMenuId: MENU_CELL_CHAT_WIDGET,
|
|
221
|
+
statusMenuId: MENU_CELL_CHAT_WIDGET_STATUS,
|
|
222
|
+
feedbackMenuId: MENU_CELL_CHAT_WIDGET_FEEDBACK
|
|
223
|
+
}));
|
|
224
|
+
inlineChatWidget.placeholder = ( localizeWithPath(
|
|
225
|
+
'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController',
|
|
226
|
+
'default.placeholder',
|
|
227
|
+
"Ask a question"
|
|
228
|
+
));
|
|
229
|
+
inlineChatWidget.updateInfo(( localizeWithPath(
|
|
230
|
+
'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController',
|
|
231
|
+
'welcome.1',
|
|
232
|
+
"AI-generated code may be incorrect"
|
|
233
|
+
)));
|
|
234
|
+
widgetContainer.appendChild(inlineChatWidget.domNode);
|
|
235
|
+
this._widgetDisposableStore.add(inlineChatWidget.onDidChangeInput(() => {
|
|
236
|
+
this._warmupRequestCts?.dispose(true);
|
|
237
|
+
this._warmupRequestCts = undefined;
|
|
238
|
+
}));
|
|
239
|
+
this._notebookEditor.changeViewZones(accessor => {
|
|
240
|
+
const notebookViewZone = {
|
|
241
|
+
afterModelPosition: index,
|
|
242
|
+
heightInPx: 80 + WIDGET_MARGIN_BOTTOM,
|
|
243
|
+
domNode: viewZoneContainer
|
|
244
|
+
};
|
|
245
|
+
const id = accessor.addZone(notebookViewZone);
|
|
246
|
+
this._scrollWidgetIntoView(index);
|
|
247
|
+
this._widget = ( new NotebookChatWidget(
|
|
248
|
+
this._notebookEditor,
|
|
249
|
+
id,
|
|
250
|
+
notebookViewZone,
|
|
251
|
+
viewZoneContainer,
|
|
252
|
+
widgetContainer,
|
|
253
|
+
inlineChatWidget,
|
|
254
|
+
fakeParentEditor,
|
|
255
|
+
this._languageService
|
|
256
|
+
));
|
|
257
|
+
this._ctxCellWidgetFocused.set(true);
|
|
258
|
+
disposableTimeout(() => {
|
|
259
|
+
this._focusWidget();
|
|
260
|
+
}, 0, this._store);
|
|
261
|
+
this._sessionCtor = createCancelablePromise(async (token) => {
|
|
262
|
+
if (fakeParentEditor.hasModel()) {
|
|
263
|
+
await this._startSession(fakeParentEditor, token);
|
|
264
|
+
this._warmupRequestCts = ( new CancellationTokenSource());
|
|
265
|
+
this._startInitialFolowups(fakeParentEditor, this._warmupRequestCts.token);
|
|
266
|
+
if (this._widget) {
|
|
267
|
+
this._widget.inlineChatWidget.placeholder = this._activeSession?.session.placeholder ?? ( localizeWithPath(
|
|
268
|
+
'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController',
|
|
269
|
+
'default.placeholder',
|
|
270
|
+
"Ask a question"
|
|
271
|
+
));
|
|
272
|
+
this._widget.inlineChatWidget.updateInfo(this._activeSession?.session.message ?? ( localizeWithPath(
|
|
273
|
+
'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController',
|
|
274
|
+
'welcome.1',
|
|
275
|
+
"AI-generated code may be incorrect"
|
|
276
|
+
)));
|
|
277
|
+
this._widget.inlineChatWidget.updateSlashCommands(this._activeSession?.session.slashCommands ?? []);
|
|
278
|
+
this._focusWidget();
|
|
279
|
+
}
|
|
280
|
+
if (this._widget && input) {
|
|
281
|
+
this._widget.inlineChatWidget.value = input;
|
|
282
|
+
if (autoSend) {
|
|
283
|
+
this.acceptInput();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
_scrollWidgetIntoView(index) {
|
|
291
|
+
if (index === 0 || this._notebookEditor.getLength() === 0) {
|
|
292
|
+
this._notebookEditor.revealOffsetInCenterIfOutsideViewport(0);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
const previousCell = this._notebookEditor.cellAt(Math.min(index - 1, this._notebookEditor.getLength() - 1));
|
|
296
|
+
if (previousCell) {
|
|
297
|
+
const cellTop = this._notebookEditor.getAbsoluteTopOfElement(previousCell);
|
|
298
|
+
const cellHeight = this._notebookEditor.getHeightOfElement(previousCell);
|
|
299
|
+
this._notebookEditor.revealOffsetInCenterIfOutsideViewport(cellTop + cellHeight + 48 );
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
_focusWidget() {
|
|
304
|
+
if (!this._widget) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
this._updateNotebookEditorFocusNSelections();
|
|
308
|
+
this._widget.focus();
|
|
309
|
+
}
|
|
310
|
+
_updateNotebookEditorFocusNSelections() {
|
|
311
|
+
if (!this._widget) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
this._notebookEditor.focusContainer(true);
|
|
315
|
+
this._notebookEditor.setFocus({ start: this._widget.afterModelPosition, end: this._widget.afterModelPosition });
|
|
316
|
+
this._notebookEditor.setSelections([{
|
|
317
|
+
start: this._widget.afterModelPosition,
|
|
318
|
+
end: this._widget.afterModelPosition
|
|
319
|
+
}]);
|
|
320
|
+
}
|
|
321
|
+
async acceptInput() {
|
|
322
|
+
assertType(this._widget);
|
|
323
|
+
await this._sessionCtor;
|
|
324
|
+
assertType(this._activeSession);
|
|
325
|
+
this._warmupRequestCts?.dispose(true);
|
|
326
|
+
this._warmupRequestCts = undefined;
|
|
327
|
+
this._activeSession.addInput(( new SessionPrompt(this._widget.inlineChatWidget.value)));
|
|
328
|
+
assertType(this._activeSession.lastInput);
|
|
329
|
+
const value = this._activeSession.lastInput.value;
|
|
330
|
+
const editor = this._widget.parentEditor;
|
|
331
|
+
const model = editor.getModel();
|
|
332
|
+
if (!editor.hasModel() || !model) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (this._widget.editingCell && this._widget.editingCell.textBuffer.getLength() > 0) {
|
|
336
|
+
const ref = await this._widget.editingCell.resolveTextModel();
|
|
337
|
+
ref.setValue('');
|
|
338
|
+
}
|
|
339
|
+
const editingCellIndex = this._widget.editingCell ? this._notebookEditor.getCellIndex(this._widget.editingCell) : undefined;
|
|
340
|
+
if (editingCellIndex !== undefined) {
|
|
341
|
+
this._notebookEditor.setSelections([{
|
|
342
|
+
start: editingCellIndex,
|
|
343
|
+
end: editingCellIndex + 1
|
|
344
|
+
}]);
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
this._notebookEditor.setSelections([{
|
|
348
|
+
start: this._widget.afterModelPosition,
|
|
349
|
+
end: this._widget.afterModelPosition
|
|
350
|
+
}]);
|
|
351
|
+
}
|
|
352
|
+
this._ctxHasActiveRequest.set(true);
|
|
353
|
+
this._widget.inlineChatWidget.updateSlashCommands(this._activeSession.session.slashCommands ?? []);
|
|
354
|
+
this._widget?.inlineChatWidget.updateProgress(true);
|
|
355
|
+
const request = {
|
|
356
|
+
requestId: generateUuid(),
|
|
357
|
+
prompt: value,
|
|
358
|
+
attempt: this._activeSession.lastInput.attempt,
|
|
359
|
+
selection: { selectionStartLineNumber: 1, selectionStartColumn: 1, positionLineNumber: 1, positionColumn: 1 },
|
|
360
|
+
wholeRange: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 },
|
|
361
|
+
live: true,
|
|
362
|
+
previewDocument: model.uri,
|
|
363
|
+
withIntentDetection: true,
|
|
364
|
+
};
|
|
365
|
+
this._activeRequestCts?.cancel();
|
|
366
|
+
this._activeRequestCts = ( new CancellationTokenSource());
|
|
367
|
+
const progressEdits = [];
|
|
368
|
+
const progressiveEditsQueue = ( new Queue());
|
|
369
|
+
const progressiveEditsClock = StopWatch.create();
|
|
370
|
+
const progressiveEditsAvgDuration = ( new MovingAverage());
|
|
371
|
+
const progressiveEditsCts = ( new CancellationTokenSource(this._activeRequestCts.token));
|
|
372
|
+
let progressiveChatResponse;
|
|
373
|
+
const progress = ( new AsyncProgress(async (data) => {
|
|
374
|
+
if (this._activeRequestCts?.token.isCancellationRequested) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (data.message) {
|
|
378
|
+
this._widget?.inlineChatWidget.updateToolbar(false);
|
|
379
|
+
this._widget?.inlineChatWidget.updateInfo(data.message);
|
|
380
|
+
}
|
|
381
|
+
if (data.edits?.length) {
|
|
382
|
+
if (!request.live) {
|
|
383
|
+
throw new Error('Progress in NOT supported in non-live mode');
|
|
384
|
+
}
|
|
385
|
+
progressEdits.push(data.edits);
|
|
386
|
+
progressiveEditsAvgDuration.update(progressiveEditsClock.elapsed());
|
|
387
|
+
progressiveEditsClock.reset();
|
|
388
|
+
progressiveEditsQueue.queue(async () => {
|
|
389
|
+
await this._makeChanges(data.edits, data.editsShouldBeInstant
|
|
390
|
+
? undefined
|
|
391
|
+
: { duration: progressiveEditsAvgDuration.value, token: progressiveEditsCts.token });
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
if (data.markdownFragment) {
|
|
395
|
+
if (!progressiveChatResponse) {
|
|
396
|
+
const message = {
|
|
397
|
+
message: ( new MarkdownString(
|
|
398
|
+
data.markdownFragment,
|
|
399
|
+
{ supportThemeIcons: true, supportHtml: true, isTrusted: false }
|
|
400
|
+
)),
|
|
401
|
+
providerId: this._activeSession.provider.debugName,
|
|
402
|
+
requestId: request.requestId,
|
|
403
|
+
};
|
|
404
|
+
progressiveChatResponse = this._widget?.inlineChatWidget.updateChatMessage(message, true);
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
progressiveChatResponse.appendContent(data.markdownFragment);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}));
|
|
411
|
+
const task = this._activeSession.provider.provideResponse(this._activeSession.session, request, progress, this._activeRequestCts.token);
|
|
412
|
+
let response;
|
|
413
|
+
try {
|
|
414
|
+
this._widget?.inlineChatWidget.updateChatMessage(undefined);
|
|
415
|
+
this._widget?.inlineChatWidget.updateFollowUps(undefined);
|
|
416
|
+
this._widget?.inlineChatWidget.updateProgress(true);
|
|
417
|
+
this._widget?.inlineChatWidget.updateInfo(!this._activeSession.lastExchange ? ( localizeWithPath(
|
|
418
|
+
'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController',
|
|
419
|
+
'thinking',
|
|
420
|
+
"Thinking\u2026"
|
|
421
|
+
)) : '');
|
|
422
|
+
this._ctxHasActiveRequest.set(true);
|
|
423
|
+
const reply = await raceCancellationError(Promise.resolve(task), this._activeRequestCts.token);
|
|
424
|
+
if (progressiveEditsQueue.size > 0) {
|
|
425
|
+
await Event.toPromise(progressiveEditsQueue.onDrained);
|
|
426
|
+
}
|
|
427
|
+
await progress.drain();
|
|
428
|
+
if (!reply) {
|
|
429
|
+
response = ( new EmptyResponse());
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
const markdownContents = ( new MarkdownString('', { supportThemeIcons: true, supportHtml: true, isTrusted: false }));
|
|
433
|
+
const replyResponse = response = this._instantiationService.createInstance(ReplyResponse, reply, markdownContents, this._activeSession.textModelN.uri, this._activeSession.textModelN.getAlternativeVersionId(), progressEdits, request.requestId);
|
|
434
|
+
for (let i = progressEdits.length; i < replyResponse.allLocalEdits.length; i++) {
|
|
435
|
+
await this._makeChanges(replyResponse.allLocalEdits[i], undefined);
|
|
436
|
+
}
|
|
437
|
+
if (this._activeSession?.provider.provideFollowups) {
|
|
438
|
+
const followupCts = ( new CancellationTokenSource());
|
|
439
|
+
const followups = await this._activeSession.provider.provideFollowups(this._activeSession.session, replyResponse.raw, followupCts.token);
|
|
440
|
+
if (followups && this._widget) {
|
|
441
|
+
const widget = this._widget;
|
|
442
|
+
widget.inlineChatWidget.updateFollowUps(followups, async (followup) => {
|
|
443
|
+
if (followup.kind === 'reply') {
|
|
444
|
+
widget.inlineChatWidget.value = followup.message;
|
|
445
|
+
this.acceptInput();
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
await this.acceptSession();
|
|
449
|
+
this._commandService.executeCommand(followup.commandId, ...(followup.args ?? []));
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
this._userEditingDisposables.clear();
|
|
455
|
+
const editingCell = this._widget.getEditingCell();
|
|
456
|
+
if (editingCell) {
|
|
457
|
+
this._userEditingDisposables.add(editingCell.model.onDidChangeContent(() => this._updateUserEditingState()));
|
|
458
|
+
this._userEditingDisposables.add(editingCell.model.onDidChangeLanguage(() => this._updateUserEditingState()));
|
|
459
|
+
this._userEditingDisposables.add(editingCell.model.onDidChangeMetadata(() => this._updateUserEditingState()));
|
|
460
|
+
this._userEditingDisposables.add(editingCell.model.onDidChangeInternalMetadata(() => this._updateUserEditingState()));
|
|
461
|
+
this._userEditingDisposables.add(editingCell.model.onDidChangeOutputs(() => this._updateUserEditingState()));
|
|
462
|
+
this._userEditingDisposables.add(this._executionStateService.onDidChangeExecution(e => {
|
|
463
|
+
if (e.type === NotebookExecutionType.cell && e.affectsCell(editingCell.uri)) {
|
|
464
|
+
this._updateUserEditingState();
|
|
465
|
+
}
|
|
466
|
+
}));
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
catch (e) {
|
|
471
|
+
response = ( new ErrorResponse(e));
|
|
472
|
+
}
|
|
473
|
+
finally {
|
|
474
|
+
this._ctxHasActiveRequest.set(false);
|
|
475
|
+
this._widget?.inlineChatWidget.updateProgress(false);
|
|
476
|
+
this._widget?.inlineChatWidget.updateInfo('');
|
|
477
|
+
this._widget?.inlineChatWidget.updateToolbar(true);
|
|
478
|
+
}
|
|
479
|
+
this._ctxHasActiveRequest.set(false);
|
|
480
|
+
this._widget?.inlineChatWidget.updateProgress(false);
|
|
481
|
+
this._widget?.inlineChatWidget.updateInfo('');
|
|
482
|
+
this._widget?.inlineChatWidget.updateToolbar(true);
|
|
483
|
+
this._activeSession?.addExchange(( new SessionExchange(this._activeSession.lastInput, response)));
|
|
484
|
+
this._ctxLastResponseType.set(response instanceof ReplyResponse ? response.raw.type : undefined);
|
|
485
|
+
}
|
|
486
|
+
async _startSession(editor, token) {
|
|
487
|
+
if (this._activeSession) {
|
|
488
|
+
this._inlineChatSessionService.releaseSession(this._activeSession);
|
|
489
|
+
}
|
|
490
|
+
const session = await this._inlineChatSessionService.createSession(editor, { editMode: "live" }, token);
|
|
491
|
+
if (!session) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
this._activeSession = session;
|
|
495
|
+
this._strategy = ( new EditStrategy(session));
|
|
496
|
+
}
|
|
497
|
+
async _startInitialFolowups(editor, token) {
|
|
498
|
+
if (!this._activeSession || !this._activeSession.provider.provideFollowups) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
const request = {
|
|
502
|
+
requestId: generateUuid(),
|
|
503
|
+
prompt: '',
|
|
504
|
+
attempt: 0,
|
|
505
|
+
selection: { selectionStartLineNumber: 1, selectionStartColumn: 1, positionLineNumber: 1, positionColumn: 1 },
|
|
506
|
+
wholeRange: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 },
|
|
507
|
+
live: true,
|
|
508
|
+
previewDocument: editor.getModel().uri,
|
|
509
|
+
withIntentDetection: true
|
|
510
|
+
};
|
|
511
|
+
const progress = ( new AsyncProgress(async (data) => { }));
|
|
512
|
+
const task = this._activeSession.provider.provideResponse(this._activeSession.session, request, progress, token);
|
|
513
|
+
const reply = await raceCancellationError(Promise.resolve(task), token);
|
|
514
|
+
if (token.isCancellationRequested) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
if (!reply) {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
const markdownContents = ( new MarkdownString('', { supportThemeIcons: true, supportHtml: true, isTrusted: false }));
|
|
521
|
+
const response = this._instantiationService.createInstance(ReplyResponse, reply, markdownContents, this._activeSession.textModelN.uri, this._activeSession.textModelN.getAlternativeVersionId(), [], request.requestId);
|
|
522
|
+
const followups = await this._activeSession.provider.provideFollowups(this._activeSession.session, response.raw, token);
|
|
523
|
+
if (followups && this._widget) {
|
|
524
|
+
const widget = this._widget;
|
|
525
|
+
widget.inlineChatWidget.updateFollowUps(followups, async (followup) => {
|
|
526
|
+
if (followup.kind === 'reply') {
|
|
527
|
+
widget.inlineChatWidget.value = followup.message;
|
|
528
|
+
this.acceptInput();
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
await this.acceptSession();
|
|
532
|
+
this._commandService.executeCommand(followup.commandId, ...(followup.args ?? []));
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
async _makeChanges(edits, opts) {
|
|
538
|
+
assertType(this._activeSession);
|
|
539
|
+
assertType(this._strategy);
|
|
540
|
+
assertType(this._widget);
|
|
541
|
+
const editingCell = await this._widget.getOrCreateEditingCell();
|
|
542
|
+
if (!editingCell) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
const editor = editingCell.editor;
|
|
546
|
+
const moreMinimalEdits = await this._editorWorkerService.computeMoreMinimalEdits(editor.getModel().uri, edits);
|
|
547
|
+
if (moreMinimalEdits?.length === 0) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const actualEdits = !opts && moreMinimalEdits ? moreMinimalEdits : edits;
|
|
551
|
+
const editOperations = ( actualEdits.map(TextEdit.asEditOperation));
|
|
552
|
+
this._inlineChatSavingService.markChanged(this._activeSession);
|
|
553
|
+
try {
|
|
554
|
+
this._activeSession.wholeRange.trackEdits(editOperations);
|
|
555
|
+
if (opts) {
|
|
556
|
+
await this._strategy.makeProgressiveChanges(editor, editOperations, opts);
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
await this._strategy.makeChanges(editor, editOperations);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
finally {
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
_updateUserEditingState() {
|
|
566
|
+
this._ctxUserDidEdit.set(true);
|
|
567
|
+
}
|
|
568
|
+
async acceptSession() {
|
|
569
|
+
assertType(this._activeSession);
|
|
570
|
+
assertType(this._strategy);
|
|
571
|
+
const editor = this._widget?.parentEditor;
|
|
572
|
+
if (!editor?.hasModel()) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
try {
|
|
576
|
+
await this._strategy.apply(editor);
|
|
577
|
+
this._inlineChatSessionService.releaseSession(this._activeSession);
|
|
578
|
+
}
|
|
579
|
+
catch (_err) { }
|
|
580
|
+
this.dismiss();
|
|
581
|
+
}
|
|
582
|
+
async focusAbove() {
|
|
583
|
+
if (!this._widget) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const index = this._widget.afterModelPosition;
|
|
587
|
+
const prev = index - 1;
|
|
588
|
+
if (prev < 0) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
const cell = this._notebookEditor.cellAt(prev);
|
|
592
|
+
if (!cell) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
await this._notebookEditor.focusNotebookCell(cell, 'editor');
|
|
596
|
+
}
|
|
597
|
+
async focusNext() {
|
|
598
|
+
if (!this._widget) {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
const index = this._widget.afterModelPosition;
|
|
602
|
+
const cell = this._notebookEditor.cellAt(index);
|
|
603
|
+
if (!cell) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
await this._notebookEditor.focusNotebookCell(cell, 'editor');
|
|
607
|
+
}
|
|
608
|
+
focus() {
|
|
609
|
+
this._focusWidget();
|
|
610
|
+
}
|
|
611
|
+
focusNearestWidget(index, direction) {
|
|
612
|
+
switch (direction) {
|
|
613
|
+
case 'above':
|
|
614
|
+
if (this._widget?.afterModelPosition === index) {
|
|
615
|
+
this._focusWidget();
|
|
616
|
+
}
|
|
617
|
+
break;
|
|
618
|
+
case 'below':
|
|
619
|
+
if (this._widget?.afterModelPosition === index + 1) {
|
|
620
|
+
this._focusWidget();
|
|
621
|
+
}
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
async cancelCurrentRequest(discard) {
|
|
626
|
+
if (discard) {
|
|
627
|
+
this._strategy?.cancel();
|
|
628
|
+
}
|
|
629
|
+
this._activeRequestCts?.cancel();
|
|
630
|
+
}
|
|
631
|
+
discard() {
|
|
632
|
+
this._strategy?.cancel();
|
|
633
|
+
this._activeRequestCts?.cancel();
|
|
634
|
+
this._widget?.discardChange();
|
|
635
|
+
this.dismiss();
|
|
636
|
+
}
|
|
637
|
+
async feedbackLast(kind) {
|
|
638
|
+
if (this._activeSession?.lastExchange && this._activeSession.lastExchange.response instanceof ReplyResponse) {
|
|
639
|
+
this._activeSession.provider.handleInlineChatResponseFeedback?.(this._activeSession.session, this._activeSession.lastExchange.response.raw, kind);
|
|
640
|
+
this._widget?.inlineChatWidget.updateStatus('Thank you for your feedback!', { resetAfter: 1250 });
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
dismiss() {
|
|
644
|
+
if (this._widget) {
|
|
645
|
+
const widgetIndex = this._widget.afterModelPosition;
|
|
646
|
+
const currentFocus = this._notebookEditor.getFocus();
|
|
647
|
+
if (currentFocus.start === widgetIndex && currentFocus.end === widgetIndex) {
|
|
648
|
+
if (widgetIndex === 0) {
|
|
649
|
+
if (this._notebookEditor.getLength() > 0) {
|
|
650
|
+
this._notebookEditor.focusNotebookCell(this._notebookEditor.cellAt(0), 'container');
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
const cell = this._notebookEditor.cellAt(widgetIndex - 1);
|
|
655
|
+
if (cell) {
|
|
656
|
+
this._notebookEditor.focusNotebookCell(cell, 'container');
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
this._ctxCellWidgetFocused.set(false);
|
|
662
|
+
this._ctxUserDidEdit.set(false);
|
|
663
|
+
this._sessionCtor?.cancel();
|
|
664
|
+
this._sessionCtor = undefined;
|
|
665
|
+
this._widget?.dispose();
|
|
666
|
+
this._widget = undefined;
|
|
667
|
+
this._widgetDisposableStore.clear();
|
|
668
|
+
}
|
|
669
|
+
dispose() {
|
|
670
|
+
this.dismiss();
|
|
671
|
+
super.dispose();
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
NotebookChatController = NotebookChatController_1 = ( __decorate([
|
|
675
|
+
( __param(1, IInstantiationService)),
|
|
676
|
+
( __param(2, IInlineChatSessionService)),
|
|
677
|
+
( __param(3, IContextKeyService)),
|
|
678
|
+
( __param(4, ICommandService)),
|
|
679
|
+
( __param(5, IEditorWorkerService)),
|
|
680
|
+
( __param(6, IInlineChatSavingService)),
|
|
681
|
+
( __param(7, IModelService)),
|
|
682
|
+
( __param(8, ILanguageService)),
|
|
683
|
+
( __param(9, INotebookExecutionStateService))
|
|
684
|
+
], NotebookChatController));
|
|
685
|
+
class EditStrategy {
|
|
686
|
+
constructor(_session) {
|
|
687
|
+
this._session = _session;
|
|
688
|
+
this._editCount = 0;
|
|
689
|
+
}
|
|
690
|
+
async makeProgressiveChanges(editor, edits, opts) {
|
|
691
|
+
if (++this._editCount === 1) {
|
|
692
|
+
editor.pushUndoStop();
|
|
693
|
+
}
|
|
694
|
+
const durationInSec = opts.duration / 1000;
|
|
695
|
+
for (const edit of edits) {
|
|
696
|
+
const wordCount = countWords(edit.text ?? '');
|
|
697
|
+
const speed = wordCount / durationInSec;
|
|
698
|
+
await performAsyncTextEdit(editor.getModel(), asProgressiveEdit(( new WindowIntervalTimer()), edit, speed, opts.token));
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
async makeChanges(editor, edits) {
|
|
702
|
+
const cursorStateComputerAndInlineDiffCollection = (undoEdits) => {
|
|
703
|
+
let last = null;
|
|
704
|
+
for (const edit of undoEdits) {
|
|
705
|
+
last = !last || last.isBefore(edit.range.getEndPosition()) ? edit.range.getEndPosition() : last;
|
|
706
|
+
}
|
|
707
|
+
return last && [Selection.fromPositions(last)];
|
|
708
|
+
};
|
|
709
|
+
if (++this._editCount === 1) {
|
|
710
|
+
editor.pushUndoStop();
|
|
711
|
+
}
|
|
712
|
+
editor.executeEdits('inline-chat-live', edits, cursorStateComputerAndInlineDiffCollection);
|
|
713
|
+
}
|
|
714
|
+
async apply(editor) {
|
|
715
|
+
if (this._editCount > 0) {
|
|
716
|
+
editor.pushUndoStop();
|
|
717
|
+
}
|
|
718
|
+
if (!(this._session.lastExchange?.response instanceof ReplyResponse)) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
const { untitledTextModel } = this._session.lastExchange.response;
|
|
722
|
+
if (untitledTextModel && !untitledTextModel.isDisposed() && untitledTextModel.isDirty()) {
|
|
723
|
+
await untitledTextModel.save({ reason: 1 });
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
async cancel() {
|
|
727
|
+
const { textModelN: modelN, textModelNAltVersion, textModelNSnapshotAltVersion } = this._session;
|
|
728
|
+
if (modelN.isDisposed()) {
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
const targetAltVersion = textModelNSnapshotAltVersion ?? textModelNAltVersion;
|
|
732
|
+
while (targetAltVersion < modelN.getAlternativeVersionId() && modelN.canUndo()) {
|
|
733
|
+
modelN.undo();
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
createSnapshot() {
|
|
737
|
+
if (this._session && !this._session.textModel0.equalsTextBuffer(this._session.textModelN.getTextBuffer())) {
|
|
738
|
+
this._session.createSnapshot();
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
registerNotebookContribution(NotebookChatController.id, NotebookChatController);
|
|
743
|
+
|
|
744
|
+
export { EditStrategy, NotebookChatController };
|