@codingame/monaco-vscode-notebook-service-override 1.85.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/external/rollup-plugin-styles/dist/runtime/inject-css.js +3 -0
  2. package/external/tslib/tslib.es6.js +11 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +1 -0
  5. package/notebook.d.ts +5 -0
  6. package/notebook.js +44 -0
  7. package/override/vs/platform/dialogs/common/dialogs.js +8 -0
  8. package/package.json +32 -0
  9. package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.css.js +6 -0
  10. package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.js +387 -0
  11. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/cellCommands.js +668 -0
  12. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/contributedStatusBarItemController.js +109 -0
  13. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController.js +319 -0
  14. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/notebookVisibleCellObserver.js +58 -0
  15. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/statusBarProviders.js +173 -0
  16. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.js +485 -0
  17. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookBreakpoints.js +106 -0
  18. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookCellPausing.js +67 -0
  19. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookDebugDecorations.js +165 -0
  20. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint.js +67 -0
  21. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.js +238 -0
  22. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/execute/executionEditorProgress.js +72 -0
  23. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/media/notebookFind.css.js +6 -0
  24. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFind.js +168 -0
  25. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.js +317 -0
  26. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.js +209 -0
  27. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/gettingStarted/notebookGettingStarted.js +87 -0
  28. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/kernelDetection/notebookKernelDetection.js +82 -0
  29. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/layout/layoutActions.js +67 -0
  30. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider.js +93 -0
  31. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.js +383 -0
  32. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.js +51 -0
  33. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesTree.js +46 -0
  34. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.js +135 -0
  35. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.js +383 -0
  36. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.js +117 -0
  37. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants.js +511 -0
  38. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout.js +168 -0
  39. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/undoRedo/notebookUndoRedo.js +57 -0
  40. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/viewportWarmup/viewportWarmup.js +94 -0
  41. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/apiActions.js +51 -0
  42. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/executeActions.js +702 -0
  43. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/layoutActions.js +268 -0
  44. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.js +45 -0
  45. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.js +1297 -0
  46. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.js +284 -0
  47. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.js +563 -0
  48. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.js +108 -0
  49. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.js +39 -0
  50. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css.js +6 -0
  51. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.js +313 -0
  52. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.js +872 -0
  53. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.js +13 -0
  54. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.js +393 -0
  55. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.js +175 -0
  56. package/vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.js +1121 -0
  57. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibility.js +159 -0
  58. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.js +339 -0
  59. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookCellStatusBarServiceImpl.js +41 -0
  60. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.js +182 -0
  61. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.js +106 -0
  62. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl.js +509 -0
  63. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl.js +133 -0
  64. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.js +342 -0
  65. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKeymapServiceImpl.js +111 -0
  66. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookLoggingServiceImpl.js +28 -0
  67. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookRendererMessagingServiceImpl.js +65 -0
  68. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.js +666 -0
  69. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookWorkerServiceImpl.js +200 -0
  70. package/vscode/src/vs/workbench/contrib/notebook/common/model/cellEdit.js +80 -0
  71. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.js +1001 -0
  72. package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiffEditorInput.js +103 -0
  73. package/vscode/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.js +202 -0
  74. package/vscode/src/vs/workbench/contrib/notebook/common/notebookOutputRenderer.js +80 -0
  75. package/vscode/src/vs/workbench/contrib/notebook/common/notebookProvider.js +98 -0
  76. package/vscode/src/vs/workbench/contrib/notebook/common/services/notebookSimpleWorker.js +217 -0
  77. package/vscode/src/vs/workbench/services/workingCopy/common/abstractFileWorkingCopyManager.js +89 -0
  78. package/vscode/src/vs/workbench/services/workingCopy/common/fileWorkingCopyManager.js +372 -0
  79. package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopy.js +706 -0
  80. package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopyManager.js +407 -0
  81. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopy.js +144 -0
  82. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopyManager.js +129 -0
  83. package/worker.js +1 -0
  84. package/workers/notebook.worker.js +9 -0
@@ -0,0 +1,509 @@
1
+ import { __decorate, __param } from '../../../../../../../../external/tslib/tslib.es6.js';
2
+ import { Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
3
+ import { Disposable, combinedDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
4
+ import { ResourceMap } from 'monaco-editor/esm/vs/base/common/map.js';
5
+ import { isEqual } from 'monaco-editor/esm/vs/base/common/resources.js';
6
+ import { generateUuid } from 'monaco-editor/esm/vs/base/common/uuid.js';
7
+ import { AudioCue, IAudioCueService } from 'monaco-editor/esm/vs/platform/audioCues/browser/audioCueService.js';
8
+ import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
9
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
10
+ import { CellUri, NotebookCellExecutionState, NotebookExecutionState } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
11
+ import { INotebookExecutionService, CellExecutionUpdateType } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookExecutionService';
12
+ import { NotebookExecutionType, INotebookExecutionStateService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookExecutionStateService';
13
+ import { INotebookKernelService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookKernelService';
14
+ import { INotebookService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookService';
15
+
16
+ let NotebookExecutionStateService = class NotebookExecutionStateService extends Disposable {
17
+ constructor(_instantiationService, _logService, _notebookService, _audioCueService) {
18
+ super();
19
+ this._instantiationService = _instantiationService;
20
+ this._logService = _logService;
21
+ this._notebookService = _notebookService;
22
+ this._audioCueService = _audioCueService;
23
+ this._executions = ( new ResourceMap());
24
+ this._notebookExecutions = ( new ResourceMap());
25
+ this._notebookListeners = ( new ResourceMap());
26
+ this._cellListeners = ( new ResourceMap());
27
+ this._lastFailedCells = ( new ResourceMap());
28
+ this._onDidChangeExecution = this._register(( new Emitter()));
29
+ this.onDidChangeExecution = this._onDidChangeExecution.event;
30
+ this._onDidChangeLastRunFailState = this._register(( new Emitter()));
31
+ this.onDidChangeLastRunFailState = this._onDidChangeLastRunFailState.event;
32
+ }
33
+ getLastFailedCellForNotebook(notebook) {
34
+ const failedCell = this._lastFailedCells.get(notebook);
35
+ return failedCell?.visible ? failedCell.cellHandle : undefined;
36
+ }
37
+ forceCancelNotebookExecutions(notebookUri) {
38
+ const notebookCellExecutions = this._executions.get(notebookUri);
39
+ if (notebookCellExecutions) {
40
+ for (const exe of ( notebookCellExecutions.values())) {
41
+ this._onCellExecutionDidComplete(notebookUri, exe.cellHandle, exe);
42
+ }
43
+ }
44
+ if (( this._notebookExecutions.has(notebookUri))) {
45
+ this._onExecutionDidComplete(notebookUri);
46
+ }
47
+ }
48
+ getCellExecution(cellUri) {
49
+ const parsed = CellUri.parse(cellUri);
50
+ if (!parsed) {
51
+ throw new Error(`Not a cell URI: ${cellUri}`);
52
+ }
53
+ const exeMap = this._executions.get(parsed.notebook);
54
+ if (exeMap) {
55
+ return exeMap.get(parsed.handle);
56
+ }
57
+ return undefined;
58
+ }
59
+ getExecution(notebook) {
60
+ return this._notebookExecutions.get(notebook)?.[0];
61
+ }
62
+ getCellExecutionsForNotebook(notebook) {
63
+ const exeMap = this._executions.get(notebook);
64
+ return exeMap ? Array.from(( exeMap.values())) : [];
65
+ }
66
+ getCellExecutionsByHandleForNotebook(notebook) {
67
+ const exeMap = this._executions.get(notebook);
68
+ return exeMap ? ( new Map(exeMap.entries())) : undefined;
69
+ }
70
+ _onCellExecutionDidChange(notebookUri, cellHandle, exe) {
71
+ this._onDidChangeExecution.fire(( new NotebookCellExecutionEvent(notebookUri, cellHandle, exe)));
72
+ }
73
+ _onCellExecutionDidComplete(notebookUri, cellHandle, exe, lastRunSuccess) {
74
+ const notebookExecutions = this._executions.get(notebookUri);
75
+ if (!notebookExecutions) {
76
+ this._logService.debug(`NotebookExecutionStateService#_onCellExecutionDidComplete - unknown notebook ${( notebookUri.toString())}`);
77
+ return;
78
+ }
79
+ exe.dispose();
80
+ const cellUri = CellUri.generate(notebookUri, cellHandle);
81
+ this._cellListeners.get(cellUri)?.dispose();
82
+ this._cellListeners.delete(cellUri);
83
+ notebookExecutions.delete(cellHandle);
84
+ if (notebookExecutions.size === 0) {
85
+ this._executions.delete(notebookUri);
86
+ this._notebookListeners.get(notebookUri)?.dispose();
87
+ this._notebookListeners.delete(notebookUri);
88
+ }
89
+ if (lastRunSuccess !== undefined) {
90
+ if (lastRunSuccess) {
91
+ if (this._executions.size === 0) {
92
+ this._audioCueService.playAudioCue(AudioCue.notebookCellCompleted);
93
+ }
94
+ this._clearLastFailedCell(notebookUri);
95
+ }
96
+ else {
97
+ this._audioCueService.playAudioCue(AudioCue.notebookCellFailed);
98
+ this._setLastFailedCell(notebookUri, cellHandle);
99
+ }
100
+ }
101
+ this._onDidChangeExecution.fire(( new NotebookCellExecutionEvent(notebookUri, cellHandle)));
102
+ }
103
+ _onExecutionDidChange(notebookUri, exe) {
104
+ this._onDidChangeExecution.fire(( new NotebookExecutionEvent(notebookUri, exe)));
105
+ }
106
+ _onExecutionDidComplete(notebookUri) {
107
+ const disposables = this._notebookExecutions.get(notebookUri);
108
+ if (!Array.isArray(disposables)) {
109
+ this._logService.debug(`NotebookExecutionStateService#_onCellExecutionDidComplete - unknown notebook ${( notebookUri.toString())}`);
110
+ return;
111
+ }
112
+ this._notebookExecutions.delete(notebookUri);
113
+ this._onDidChangeExecution.fire(( new NotebookExecutionEvent(notebookUri)));
114
+ disposables.forEach(d => d.dispose());
115
+ }
116
+ createCellExecution(notebookUri, cellHandle) {
117
+ const notebook = this._notebookService.getNotebookTextModel(notebookUri);
118
+ if (!notebook) {
119
+ throw new Error(`Notebook not found: ${notebookUri.toString()}`);
120
+ }
121
+ let notebookExecutionMap = this._executions.get(notebookUri);
122
+ if (!notebookExecutionMap) {
123
+ const listeners = this._instantiationService.createInstance(NotebookExecutionListeners, notebookUri);
124
+ this._notebookListeners.set(notebookUri, listeners);
125
+ notebookExecutionMap = ( new Map());
126
+ this._executions.set(notebookUri, notebookExecutionMap);
127
+ }
128
+ let exe = notebookExecutionMap.get(cellHandle);
129
+ if (!exe) {
130
+ exe = this._createNotebookCellExecution(notebook, cellHandle);
131
+ notebookExecutionMap.set(cellHandle, exe);
132
+ exe.initialize();
133
+ this._onDidChangeExecution.fire(( new NotebookCellExecutionEvent(notebookUri, cellHandle, exe)));
134
+ }
135
+ return exe;
136
+ }
137
+ createExecution(notebookUri) {
138
+ const notebook = this._notebookService.getNotebookTextModel(notebookUri);
139
+ if (!notebook) {
140
+ throw new Error(`Notebook not found: ${notebookUri.toString()}`);
141
+ }
142
+ if (!( this._notebookListeners.has(notebookUri))) {
143
+ const listeners = this._instantiationService.createInstance(NotebookExecutionListeners, notebookUri);
144
+ this._notebookListeners.set(notebookUri, listeners);
145
+ }
146
+ let info = this._notebookExecutions.get(notebookUri);
147
+ if (!info) {
148
+ info = this._createNotebookExecution(notebook);
149
+ this._notebookExecutions.set(notebookUri, info);
150
+ this._onDidChangeExecution.fire(( new NotebookExecutionEvent(notebookUri, info[0])));
151
+ }
152
+ return info[0];
153
+ }
154
+ _createNotebookCellExecution(notebook, cellHandle) {
155
+ const notebookUri = notebook.uri;
156
+ const exe = this._instantiationService.createInstance(CellExecution, cellHandle, notebook);
157
+ const disposable = combinedDisposable(exe.onDidUpdate(() => this._onCellExecutionDidChange(notebookUri, cellHandle, exe)), exe.onDidComplete(lastRunSuccess => this._onCellExecutionDidComplete(notebookUri, cellHandle, exe, lastRunSuccess)));
158
+ this._cellListeners.set(CellUri.generate(notebookUri, cellHandle), disposable);
159
+ return exe;
160
+ }
161
+ _createNotebookExecution(notebook) {
162
+ const notebookUri = notebook.uri;
163
+ const exe = this._instantiationService.createInstance(NotebookExecution, notebook);
164
+ const disposable = combinedDisposable(exe.onDidUpdate(() => this._onExecutionDidChange(notebookUri, exe)), exe.onDidComplete(() => this._onExecutionDidComplete(notebookUri)));
165
+ return [exe, disposable];
166
+ }
167
+ _setLastFailedCell(notebookURI, cellHandle) {
168
+ const prevLastFailedCellInfo = this._lastFailedCells.get(notebookURI);
169
+ const notebook = this._notebookService.getNotebookTextModel(notebookURI);
170
+ if (!notebook) {
171
+ return;
172
+ }
173
+ const newLastFailedCellInfo = {
174
+ cellHandle: cellHandle,
175
+ disposable: prevLastFailedCellInfo ? prevLastFailedCellInfo.disposable : this._getFailedCellListener(notebook),
176
+ visible: true
177
+ };
178
+ this._lastFailedCells.set(notebookURI, newLastFailedCellInfo);
179
+ this._onDidChangeLastRunFailState.fire({ visible: true, notebook: notebookURI });
180
+ }
181
+ _setLastFailedCellVisibility(notebookURI, visible) {
182
+ const lastFailedCellInfo = this._lastFailedCells.get(notebookURI);
183
+ if (lastFailedCellInfo) {
184
+ this._lastFailedCells.set(notebookURI, {
185
+ cellHandle: lastFailedCellInfo.cellHandle,
186
+ disposable: lastFailedCellInfo.disposable,
187
+ visible: visible,
188
+ });
189
+ }
190
+ this._onDidChangeLastRunFailState.fire({ visible: visible, notebook: notebookURI });
191
+ }
192
+ _clearLastFailedCell(notebookURI) {
193
+ const lastFailedCellInfo = this._lastFailedCells.get(notebookURI);
194
+ if (lastFailedCellInfo) {
195
+ lastFailedCellInfo.disposable?.dispose();
196
+ this._lastFailedCells.delete(notebookURI);
197
+ }
198
+ this._onDidChangeLastRunFailState.fire({ visible: false, notebook: notebookURI });
199
+ }
200
+ _getFailedCellListener(notebook) {
201
+ return notebook.onWillAddRemoveCells((e) => {
202
+ const lastFailedCell = this._lastFailedCells.get(notebook.uri)?.cellHandle;
203
+ if (lastFailedCell !== undefined) {
204
+ const lastFailedCellPos = notebook.cells.findIndex(c => c.handle === lastFailedCell);
205
+ e.rawEvent.changes.forEach(([start, deleteCount, addedCells]) => {
206
+ if (deleteCount) {
207
+ if (lastFailedCellPos >= start && lastFailedCellPos < start + deleteCount) {
208
+ this._setLastFailedCellVisibility(notebook.uri, false);
209
+ }
210
+ }
211
+ if (( addedCells.some(cell => cell.handle === lastFailedCell))) {
212
+ this._setLastFailedCellVisibility(notebook.uri, true);
213
+ }
214
+ });
215
+ }
216
+ });
217
+ }
218
+ dispose() {
219
+ super.dispose();
220
+ this._executions.forEach(executionMap => {
221
+ executionMap.forEach(execution => execution.dispose());
222
+ executionMap.clear();
223
+ });
224
+ this._executions.clear();
225
+ this._notebookExecutions.forEach(disposables => {
226
+ disposables.forEach(d => d.dispose());
227
+ });
228
+ this._notebookExecutions.clear();
229
+ this._cellListeners.forEach(disposable => disposable.dispose());
230
+ this._notebookListeners.forEach(disposable => disposable.dispose());
231
+ this._lastFailedCells.forEach(elem => elem.disposable.dispose());
232
+ }
233
+ };
234
+ NotebookExecutionStateService = ( __decorate([
235
+ ( __param(0, IInstantiationService)),
236
+ ( __param(1, ILogService)),
237
+ ( __param(2, INotebookService)),
238
+ ( __param(3, IAudioCueService))
239
+ ], NotebookExecutionStateService));
240
+ class NotebookCellExecutionEvent {
241
+ constructor(notebook, cellHandle, changed) {
242
+ this.notebook = notebook;
243
+ this.cellHandle = cellHandle;
244
+ this.changed = changed;
245
+ this.type = NotebookExecutionType.cell;
246
+ }
247
+ affectsCell(cell) {
248
+ const parsedUri = CellUri.parse(cell);
249
+ return !!parsedUri && isEqual(this.notebook, parsedUri.notebook) && this.cellHandle === parsedUri.handle;
250
+ }
251
+ affectsNotebook(notebook) {
252
+ return isEqual(this.notebook, notebook);
253
+ }
254
+ }
255
+ class NotebookExecutionEvent {
256
+ constructor(notebook, changed) {
257
+ this.notebook = notebook;
258
+ this.changed = changed;
259
+ this.type = NotebookExecutionType.notebook;
260
+ }
261
+ affectsNotebook(notebook) {
262
+ return isEqual(this.notebook, notebook);
263
+ }
264
+ }
265
+ let NotebookExecutionListeners = class NotebookExecutionListeners extends Disposable {
266
+ constructor(notebook, _notebookService, _notebookKernelService, _notebookExecutionService, _notebookExecutionStateService, _logService) {
267
+ super();
268
+ this._notebookService = _notebookService;
269
+ this._notebookKernelService = _notebookKernelService;
270
+ this._notebookExecutionService = _notebookExecutionService;
271
+ this._notebookExecutionStateService = _notebookExecutionStateService;
272
+ this._logService = _logService;
273
+ this._logService.debug(`NotebookExecution#ctor ${( notebook.toString())}`);
274
+ const notebookModel = this._notebookService.getNotebookTextModel(notebook);
275
+ if (!notebookModel) {
276
+ throw new Error('Notebook not found: ' + notebook);
277
+ }
278
+ this._notebookModel = notebookModel;
279
+ this._register(this._notebookModel.onWillAddRemoveCells(e => this.onWillAddRemoveCells(e)));
280
+ this._register(this._notebookModel.onWillDispose(() => this.onWillDisposeDocument()));
281
+ }
282
+ cancelAll() {
283
+ this._logService.debug(`NotebookExecutionListeners#cancelAll`);
284
+ const exes = this._notebookExecutionStateService.getCellExecutionsForNotebook(this._notebookModel.uri);
285
+ this._notebookExecutionService.cancelNotebookCellHandles(this._notebookModel, ( exes.map(exe => exe.cellHandle)));
286
+ }
287
+ onWillDisposeDocument() {
288
+ this._logService.debug(`NotebookExecution#onWillDisposeDocument`);
289
+ this.cancelAll();
290
+ }
291
+ onWillAddRemoveCells(e) {
292
+ const notebookExes = this._notebookExecutionStateService.getCellExecutionsByHandleForNotebook(this._notebookModel.uri);
293
+ const executingDeletedHandles = ( new Set());
294
+ const pendingDeletedHandles = ( new Set());
295
+ if (notebookExes) {
296
+ e.rawEvent.changes.forEach(([start, deleteCount]) => {
297
+ if (deleteCount) {
298
+ const deletedHandles = ( this._notebookModel.cells.slice(start, start + deleteCount).map(c => c.handle));
299
+ deletedHandles.forEach(h => {
300
+ const exe = notebookExes.get(h);
301
+ if (exe?.state === NotebookCellExecutionState.Executing) {
302
+ executingDeletedHandles.add(h);
303
+ }
304
+ else if (exe) {
305
+ pendingDeletedHandles.add(h);
306
+ }
307
+ });
308
+ }
309
+ });
310
+ }
311
+ if (executingDeletedHandles.size || pendingDeletedHandles.size) {
312
+ const kernel = this._notebookKernelService.getSelectedOrSuggestedKernel(this._notebookModel);
313
+ if (kernel) {
314
+ const implementsInterrupt = kernel.implementsInterrupt;
315
+ const handlesToCancel = implementsInterrupt ? [...executingDeletedHandles] : [...executingDeletedHandles, ...pendingDeletedHandles];
316
+ this._logService.debug(`NotebookExecution#onWillAddRemoveCells, ${JSON.stringify([...handlesToCancel])}`);
317
+ if (handlesToCancel.length) {
318
+ kernel.cancelNotebookCellExecution(this._notebookModel.uri, handlesToCancel);
319
+ }
320
+ }
321
+ }
322
+ }
323
+ };
324
+ NotebookExecutionListeners = ( __decorate([
325
+ ( __param(1, INotebookService)),
326
+ ( __param(2, INotebookKernelService)),
327
+ ( __param(3, INotebookExecutionService)),
328
+ ( __param(4, INotebookExecutionStateService)),
329
+ ( __param(5, ILogService))
330
+ ], NotebookExecutionListeners));
331
+ function updateToEdit(update, cellHandle) {
332
+ if (update.editType === CellExecutionUpdateType.Output) {
333
+ return {
334
+ editType: 2 ,
335
+ handle: update.cellHandle,
336
+ append: update.append,
337
+ outputs: update.outputs,
338
+ };
339
+ }
340
+ else if (update.editType === CellExecutionUpdateType.OutputItems) {
341
+ return {
342
+ editType: 7 ,
343
+ items: update.items,
344
+ append: update.append,
345
+ outputId: update.outputId
346
+ };
347
+ }
348
+ else if (update.editType === CellExecutionUpdateType.ExecutionState) {
349
+ const newInternalMetadata = {};
350
+ if (typeof update.executionOrder !== 'undefined') {
351
+ newInternalMetadata.executionOrder = update.executionOrder;
352
+ }
353
+ if (typeof update.runStartTime !== 'undefined') {
354
+ newInternalMetadata.runStartTime = update.runStartTime;
355
+ }
356
+ return {
357
+ editType: 9 ,
358
+ handle: cellHandle,
359
+ internalMetadata: newInternalMetadata
360
+ };
361
+ }
362
+ throw new Error('Unknown cell update type');
363
+ }
364
+ let CellExecution = class CellExecution extends Disposable {
365
+ get state() {
366
+ return this._state;
367
+ }
368
+ get notebook() {
369
+ return this._notebookModel.uri;
370
+ }
371
+ get didPause() {
372
+ return this._didPause;
373
+ }
374
+ get isPaused() {
375
+ return this._isPaused;
376
+ }
377
+ constructor(cellHandle, _notebookModel, _logService) {
378
+ super();
379
+ this.cellHandle = cellHandle;
380
+ this._notebookModel = _notebookModel;
381
+ this._logService = _logService;
382
+ this._onDidUpdate = this._register(( new Emitter()));
383
+ this.onDidUpdate = this._onDidUpdate.event;
384
+ this._onDidComplete = this._register(( new Emitter()));
385
+ this.onDidComplete = this._onDidComplete.event;
386
+ this._state = NotebookCellExecutionState.Unconfirmed;
387
+ this._didPause = false;
388
+ this._isPaused = false;
389
+ this._logService.debug(`CellExecution#ctor ${this.getCellLog()}`);
390
+ }
391
+ initialize() {
392
+ const startExecuteEdit = {
393
+ editType: 9 ,
394
+ handle: this.cellHandle,
395
+ internalMetadata: {
396
+ executionId: generateUuid(),
397
+ runStartTime: null,
398
+ runEndTime: null,
399
+ lastRunSuccess: null,
400
+ executionOrder: null,
401
+ renderDuration: null,
402
+ }
403
+ };
404
+ this._applyExecutionEdits([startExecuteEdit]);
405
+ }
406
+ getCellLog() {
407
+ return `${( this._notebookModel.uri.toString())}, ${this.cellHandle}`;
408
+ }
409
+ logUpdates(updates) {
410
+ const updateTypes = ( updates.map(u => CellExecutionUpdateType[u.editType])).join(', ');
411
+ this._logService.debug(`CellExecution#updateExecution ${this.getCellLog()}, [${updateTypes}]`);
412
+ }
413
+ confirm() {
414
+ this._logService.debug(`CellExecution#confirm ${this.getCellLog()}`);
415
+ this._state = NotebookCellExecutionState.Pending;
416
+ this._onDidUpdate.fire();
417
+ }
418
+ update(updates) {
419
+ this.logUpdates(updates);
420
+ if (( updates.some(u => u.editType === CellExecutionUpdateType.ExecutionState))) {
421
+ this._state = NotebookCellExecutionState.Executing;
422
+ }
423
+ if (!this._didPause && ( updates.some(u => u.editType === CellExecutionUpdateType.ExecutionState && u.didPause))) {
424
+ this._didPause = true;
425
+ }
426
+ const lastIsPausedUpdate = [...updates].reverse().find(u => u.editType === CellExecutionUpdateType.ExecutionState && typeof u.isPaused === 'boolean');
427
+ if (lastIsPausedUpdate) {
428
+ this._isPaused = lastIsPausedUpdate.isPaused;
429
+ }
430
+ const cellModel = this._notebookModel.cells.find(c => c.handle === this.cellHandle);
431
+ if (!cellModel) {
432
+ this._logService.debug(`CellExecution#update, updating cell not in notebook: ${( this._notebookModel.uri.toString())}, ${this.cellHandle}`);
433
+ }
434
+ else {
435
+ const edits = ( updates.map(update => updateToEdit(update, this.cellHandle)));
436
+ this._applyExecutionEdits(edits);
437
+ }
438
+ if (( updates.some(u => u.editType === CellExecutionUpdateType.ExecutionState))) {
439
+ this._onDidUpdate.fire();
440
+ }
441
+ }
442
+ complete(completionData) {
443
+ const cellModel = this._notebookModel.cells.find(c => c.handle === this.cellHandle);
444
+ if (!cellModel) {
445
+ this._logService.debug(`CellExecution#complete, completing cell not in notebook: ${( this._notebookModel.uri.toString())}, ${this.cellHandle}`);
446
+ }
447
+ else {
448
+ const edit = {
449
+ editType: 9 ,
450
+ handle: this.cellHandle,
451
+ internalMetadata: {
452
+ lastRunSuccess: completionData.lastRunSuccess,
453
+ runStartTime: this._didPause ? null : cellModel.internalMetadata.runStartTime,
454
+ runEndTime: this._didPause ? null : completionData.runEndTime,
455
+ }
456
+ };
457
+ this._applyExecutionEdits([edit]);
458
+ }
459
+ this._onDidComplete.fire(completionData.lastRunSuccess);
460
+ }
461
+ _applyExecutionEdits(edits) {
462
+ this._notebookModel.applyEdits(edits, true, undefined, () => undefined, undefined, false);
463
+ }
464
+ };
465
+ CellExecution = ( __decorate([
466
+ ( __param(2, ILogService))
467
+ ], CellExecution));
468
+ let NotebookExecution = class NotebookExecution extends Disposable {
469
+ get state() {
470
+ return this._state;
471
+ }
472
+ get notebook() {
473
+ return this._notebookModel.uri;
474
+ }
475
+ constructor(_notebookModel, _logService) {
476
+ super();
477
+ this._notebookModel = _notebookModel;
478
+ this._logService = _logService;
479
+ this._onDidUpdate = this._register(( new Emitter()));
480
+ this.onDidUpdate = this._onDidUpdate.event;
481
+ this._onDidComplete = this._register(( new Emitter()));
482
+ this.onDidComplete = this._onDidComplete.event;
483
+ this._state = NotebookExecutionState.Unconfirmed;
484
+ this._logService.debug(`NotebookExecution#ctor`);
485
+ }
486
+ debug(message) {
487
+ this._logService.debug(`${message} ${( this._notebookModel.uri.toString())}`);
488
+ }
489
+ confirm() {
490
+ this.debug(`Execution#confirm`);
491
+ this._state = NotebookExecutionState.Pending;
492
+ this._onDidUpdate.fire();
493
+ }
494
+ begin() {
495
+ this.debug(`Execution#begin`);
496
+ this._state = NotebookExecutionState.Executing;
497
+ this._onDidUpdate.fire();
498
+ }
499
+ complete() {
500
+ this.debug(`Execution#begin`);
501
+ this._state = NotebookExecutionState.Unconfirmed;
502
+ this._onDidComplete.fire();
503
+ }
504
+ };
505
+ NotebookExecution = ( __decorate([
506
+ ( __param(1, ILogService))
507
+ ], NotebookExecution));
508
+
509
+ export { NotebookExecutionStateService };
@@ -0,0 +1,133 @@
1
+ import { __decorate, __param } from '../../../../../../../../external/tslib/tslib.es6.js';
2
+ import { Disposable, DisposableStore } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
3
+ import { LinkedMap } from 'monaco-editor/esm/vs/base/common/map.js';
4
+ import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
5
+ import { Categories } from 'monaco-editor/esm/vs/platform/action/common/actionCommonCategories.js';
6
+ import { registerAction2, Action2 } from 'monaco-editor/esm/vs/platform/actions/common/actions.js';
7
+ import { IStorageService } from 'monaco-editor/esm/vs/platform/storage/common/storage.js';
8
+ import { INotebookKernelHistoryService, INotebookKernelService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookKernelService';
9
+ import { INotebookLoggingService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookLoggingService';
10
+
11
+ var NotebookKernelHistoryService_1;
12
+ const MAX_KERNELS_IN_HISTORY = 5;
13
+ let NotebookKernelHistoryService = class NotebookKernelHistoryService extends Disposable {
14
+ static { NotebookKernelHistoryService_1 = this; }
15
+ static { this.STORAGE_KEY = 'notebook.kernelHistory'; }
16
+ constructor(_storageService, _notebookKernelService, _notebookLoggingService) {
17
+ super();
18
+ this._storageService = _storageService;
19
+ this._notebookKernelService = _notebookKernelService;
20
+ this._notebookLoggingService = _notebookLoggingService;
21
+ this._mostRecentKernelsMap = {};
22
+ this._loadState();
23
+ this._register(this._storageService.onWillSaveState(() => this._saveState()));
24
+ this._register(this._storageService.onDidChangeValue(1 , NotebookKernelHistoryService_1.STORAGE_KEY, this._register(( new DisposableStore())))(() => {
25
+ this._loadState();
26
+ }));
27
+ }
28
+ getKernels(notebook) {
29
+ const allAvailableKernels = this._notebookKernelService.getMatchingKernel(notebook);
30
+ const allKernels = allAvailableKernels.all;
31
+ const selectedKernel = allAvailableKernels.selected;
32
+ const suggested = allAvailableKernels.all.length === 1 ? allAvailableKernels.all[0] : undefined;
33
+ this._notebookLoggingService.debug('History', `getMatchingKernels: ${allAvailableKernels.all.length} kernels available for ${notebook.uri.path}. Selected: ${allAvailableKernels.selected?.label}. Suggested: ${suggested?.label}`);
34
+ const mostRecentKernelIds = this._mostRecentKernelsMap[notebook.viewType] ? [...( this._mostRecentKernelsMap[notebook.viewType].values())] : [];
35
+ const all = ( mostRecentKernelIds.map(kernelId => allKernels.find(kernel => kernel.id === kernelId))).filter(kernel => !!kernel);
36
+ this._notebookLoggingService.debug('History', `mru: ${mostRecentKernelIds.length} kernels in history, ${all.length} registered already.`);
37
+ return {
38
+ selected: selectedKernel ?? suggested,
39
+ all
40
+ };
41
+ }
42
+ addMostRecentKernel(kernel) {
43
+ const key = kernel.id;
44
+ const viewType = kernel.viewType;
45
+ const recentKeynels = this._mostRecentKernelsMap[viewType] ?? ( new LinkedMap());
46
+ recentKeynels.set(key, key, 1 );
47
+ if (recentKeynels.size > MAX_KERNELS_IN_HISTORY) {
48
+ const reserved = [...recentKeynels.entries()].slice(0, MAX_KERNELS_IN_HISTORY);
49
+ recentKeynels.fromJSON(reserved);
50
+ }
51
+ this._mostRecentKernelsMap[viewType] = recentKeynels;
52
+ }
53
+ _saveState() {
54
+ let notEmpty = false;
55
+ for (const [_, kernels] of Object.entries(this._mostRecentKernelsMap)) {
56
+ notEmpty = notEmpty || kernels.size > 0;
57
+ }
58
+ if (notEmpty) {
59
+ const serialized = this._serialize();
60
+ this._storageService.store(NotebookKernelHistoryService_1.STORAGE_KEY, JSON.stringify(serialized), 1 , 0 );
61
+ }
62
+ else {
63
+ this._storageService.remove(NotebookKernelHistoryService_1.STORAGE_KEY, 1 );
64
+ }
65
+ }
66
+ _loadState() {
67
+ const serialized = this._storageService.get(NotebookKernelHistoryService_1.STORAGE_KEY, 1 );
68
+ if (serialized) {
69
+ try {
70
+ this._deserialize(JSON.parse(serialized));
71
+ }
72
+ catch (e) {
73
+ this._mostRecentKernelsMap = {};
74
+ }
75
+ }
76
+ else {
77
+ this._mostRecentKernelsMap = {};
78
+ }
79
+ }
80
+ _serialize() {
81
+ const result = Object.create(null);
82
+ for (const [viewType, kernels] of Object.entries(this._mostRecentKernelsMap)) {
83
+ result[viewType] = {
84
+ entries: [...( kernels.values())]
85
+ };
86
+ }
87
+ return result;
88
+ }
89
+ _deserialize(serialized) {
90
+ this._mostRecentKernelsMap = {};
91
+ for (const [viewType, kernels] of Object.entries(serialized)) {
92
+ const linkedMap = ( new LinkedMap());
93
+ const mapValues = [];
94
+ for (const entry of kernels.entries) {
95
+ mapValues.push([entry, entry]);
96
+ }
97
+ linkedMap.fromJSON(mapValues);
98
+ this._mostRecentKernelsMap[viewType] = linkedMap;
99
+ }
100
+ }
101
+ _clear() {
102
+ this._mostRecentKernelsMap = {};
103
+ this._saveState();
104
+ }
105
+ };
106
+ NotebookKernelHistoryService = NotebookKernelHistoryService_1 = ( __decorate([
107
+ ( __param(0, IStorageService)),
108
+ ( __param(1, INotebookKernelService)),
109
+ ( __param(2, INotebookLoggingService))
110
+ ], NotebookKernelHistoryService));
111
+ registerAction2(class extends Action2 {
112
+ constructor() {
113
+ super({
114
+ id: 'notebook.clearNotebookKernelsMRUCache',
115
+ title: {
116
+ value: ( localizeWithPath(
117
+ 'vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl',
118
+ 'workbench.notebook.clearNotebookKernelsMRUCache',
119
+ "Clear Notebook Kernels MRU Cache"
120
+ )),
121
+ original: 'Clear Notebook Kernels MRU Cache'
122
+ },
123
+ category: Categories.Developer,
124
+ f1: true
125
+ });
126
+ }
127
+ async run(accessor) {
128
+ const historyService = accessor.get(INotebookKernelHistoryService);
129
+ historyService._clear();
130
+ }
131
+ });
132
+
133
+ export { NotebookKernelHistoryService };