@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,511 @@
1
+ import { __decorate, __param } from '../../../../../../../../../external/tslib/tslib.es6.js';
2
+ import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
3
+ import { Disposable, DisposableStore } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
4
+ import { isEqual } from 'monaco-editor/esm/vs/base/common/resources.js';
5
+ import { ResourceTextEdit, IBulkEditService } from 'monaco-editor/esm/vs/editor/browser/services/bulkEditService.js';
6
+ import { trimTrailingWhitespace } from 'monaco-editor/esm/vs/editor/common/commands/trimTrailingWhitespaceCommand.js';
7
+ import { Position } from 'monaco-editor/esm/vs/editor/common/core/position.js';
8
+ import { Range } from 'monaco-editor/esm/vs/editor/common/core/range.js';
9
+ import { IEditorWorkerService } from 'monaco-editor/esm/vs/editor/common/services/editorWorker.js';
10
+ import { ILanguageFeaturesService } from 'monaco-editor/esm/vs/editor/common/services/languageFeatures.js';
11
+ import { ITextModelService } from 'monaco-editor/esm/vs/editor/common/services/resolverService.js';
12
+ import { applyCodeAction, ApplyCodeActionReason, getCodeActions } from 'monaco-editor/esm/vs/editor/contrib/codeAction/browser/codeAction.js';
13
+ import { CodeActionKind, CodeActionTriggerSource } from 'monaco-editor/esm/vs/editor/contrib/codeAction/common/types.js';
14
+ import { getDocumentFormattingEditsUntilResult } from 'monaco-editor/esm/vs/editor/contrib/format/browser/format.js';
15
+ import { SnippetController2 } from 'monaco-editor/esm/vs/editor/contrib/snippet/browser/snippetController2.js';
16
+ import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
17
+ import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
18
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
19
+ import { Registry } from 'monaco-editor/esm/vs/platform/registry/common/platform.js';
20
+ import { IWorkspaceTrustManagementService } from 'monaco-editor/esm/vs/platform/workspace/common/workspaceTrust.js';
21
+ import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
22
+ import { getNotebookEditorFromEditorPane } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
23
+ import { NotebookSetting, CellKind } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
24
+ import { NotebookFileWorkingCopyModel } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookEditorModel';
25
+ import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
26
+ import { IWorkingCopyFileService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyFileService';
27
+
28
+ let FormatOnSaveParticipant = class FormatOnSaveParticipant {
29
+ constructor(editorWorkerService, languageFeaturesService, textModelService, bulkEditService, configurationService) {
30
+ this.editorWorkerService = editorWorkerService;
31
+ this.languageFeaturesService = languageFeaturesService;
32
+ this.textModelService = textModelService;
33
+ this.bulkEditService = bulkEditService;
34
+ this.configurationService = configurationService;
35
+ }
36
+ async participate(workingCopy, context, progress, token) {
37
+ if (!workingCopy.model || !(workingCopy.model instanceof NotebookFileWorkingCopyModel)) {
38
+ return;
39
+ }
40
+ if (context.reason === 2 ) {
41
+ return undefined;
42
+ }
43
+ const enabled = this.configurationService.getValue(NotebookSetting.formatOnSave);
44
+ if (!enabled) {
45
+ return undefined;
46
+ }
47
+ const notebook = workingCopy.model.notebookModel;
48
+ progress.report({ message: ( localizeWithPath(
49
+ 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
50
+ 'notebookFormatSave.formatting',
51
+ "Formatting"
52
+ )) });
53
+ const disposable = ( new DisposableStore());
54
+ try {
55
+ const allCellEdits = await Promise.all(( notebook.cells.map(async (cell) => {
56
+ const ref = await this.textModelService.createModelReference(cell.uri);
57
+ disposable.add(ref);
58
+ const model = ref.object.textEditorModel;
59
+ const formatEdits = await getDocumentFormattingEditsUntilResult(this.editorWorkerService, this.languageFeaturesService, model, model.getOptions(), token);
60
+ const edits = [];
61
+ if (formatEdits) {
62
+ edits.push(...( formatEdits.map(edit => ( new ResourceTextEdit(model.uri, edit, model.getVersionId())))));
63
+ return edits;
64
+ }
65
+ return [];
66
+ })));
67
+ await this.bulkEditService.apply( allCellEdits.flat(), { label: ( localizeWithPath(
68
+ 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
69
+ 'formatNotebook',
70
+ "Format Notebook"
71
+ )), code: 'undoredo.formatNotebook', });
72
+ }
73
+ finally {
74
+ progress.report({ increment: 100 });
75
+ disposable.dispose();
76
+ }
77
+ }
78
+ };
79
+ FormatOnSaveParticipant = ( __decorate([
80
+ ( __param(0, IEditorWorkerService)),
81
+ ( __param(1, ILanguageFeaturesService)),
82
+ ( __param(2, ITextModelService)),
83
+ ( __param(3, IBulkEditService)),
84
+ ( __param(4, IConfigurationService))
85
+ ], FormatOnSaveParticipant));
86
+ let TrimWhitespaceParticipant = class TrimWhitespaceParticipant {
87
+ constructor(configurationService, editorService, textModelService, bulkEditService) {
88
+ this.configurationService = configurationService;
89
+ this.editorService = editorService;
90
+ this.textModelService = textModelService;
91
+ this.bulkEditService = bulkEditService;
92
+ }
93
+ async participate(workingCopy, context, progress, _token) {
94
+ if (this.configurationService.getValue('files.trimTrailingWhitespace')) {
95
+ await this.doTrimTrailingWhitespace(workingCopy, context.reason === 2 , progress);
96
+ }
97
+ }
98
+ async doTrimTrailingWhitespace(workingCopy, isAutoSaved, progress) {
99
+ if (!workingCopy.model || !(workingCopy.model instanceof NotebookFileWorkingCopyModel)) {
100
+ return;
101
+ }
102
+ const disposable = ( new DisposableStore());
103
+ const notebook = workingCopy.model.notebookModel;
104
+ const activeCellEditor = getActiveCellCodeEditor(this.editorService);
105
+ let cursors = [];
106
+ let prevSelection = [];
107
+ try {
108
+ const allCellEdits = await Promise.all(( notebook.cells.map(async (cell) => {
109
+ if (cell.cellKind !== CellKind.Code) {
110
+ return [];
111
+ }
112
+ const ref = await this.textModelService.createModelReference(cell.uri);
113
+ disposable.add(ref);
114
+ const model = ref.object.textEditorModel;
115
+ const isActiveCell = (activeCellEditor && ( cell.uri.toString()) === activeCellEditor.getModel()?.uri.toString());
116
+ if (isActiveCell) {
117
+ prevSelection = activeCellEditor.getSelections() ?? [];
118
+ if (isAutoSaved) {
119
+ cursors = ( prevSelection.map(s => s.getPosition()));
120
+ const snippetsRange = SnippetController2.get(activeCellEditor)?.getSessionEnclosingRange();
121
+ if (snippetsRange) {
122
+ for (let lineNumber = snippetsRange.startLineNumber; lineNumber <= snippetsRange.endLineNumber; lineNumber++) {
123
+ cursors.push(( new Position(lineNumber, model.getLineMaxColumn(lineNumber))));
124
+ }
125
+ }
126
+ }
127
+ }
128
+ const ops = trimTrailingWhitespace(model, cursors);
129
+ if (!ops.length) {
130
+ return [];
131
+ }
132
+ return ( ops.map(op => ( new ResourceTextEdit(model.uri, { ...op, text: op.text || '' }, model.getVersionId()))));
133
+ })));
134
+ const filteredEdits = allCellEdits.flat().filter(edit => edit !== undefined);
135
+ await this.bulkEditService.apply(filteredEdits, { label: ( localizeWithPath(
136
+ 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
137
+ 'trimNotebookWhitespace',
138
+ "Notebook Trim Trailing Whitespace"
139
+ )), code: 'undoredo.notebookTrimTrailingWhitespace' });
140
+ }
141
+ finally {
142
+ progress.report({ increment: 100 });
143
+ disposable.dispose();
144
+ }
145
+ }
146
+ };
147
+ TrimWhitespaceParticipant = ( __decorate([
148
+ ( __param(0, IConfigurationService)),
149
+ ( __param(1, IEditorService)),
150
+ ( __param(2, ITextModelService)),
151
+ ( __param(3, IBulkEditService))
152
+ ], TrimWhitespaceParticipant));
153
+ let TrimFinalNewLinesParticipant = class TrimFinalNewLinesParticipant {
154
+ constructor(configurationService, editorService, bulkEditService) {
155
+ this.configurationService = configurationService;
156
+ this.editorService = editorService;
157
+ this.bulkEditService = bulkEditService;
158
+ }
159
+ async participate(workingCopy, context, progress, _token) {
160
+ if (this.configurationService.getValue('files.trimFinalNewlines')) {
161
+ await this.doTrimFinalNewLines(workingCopy, context.reason === 2 , progress);
162
+ }
163
+ }
164
+ findLastNonEmptyLine(textBuffer) {
165
+ for (let lineNumber = textBuffer.getLineCount(); lineNumber >= 1; lineNumber--) {
166
+ const lineLength = textBuffer.getLineLength(lineNumber);
167
+ if (lineLength) {
168
+ return lineNumber;
169
+ }
170
+ }
171
+ return 0;
172
+ }
173
+ async doTrimFinalNewLines(workingCopy, isAutoSaved, progress) {
174
+ if (!workingCopy.model || !(workingCopy.model instanceof NotebookFileWorkingCopyModel)) {
175
+ return;
176
+ }
177
+ const disposable = ( new DisposableStore());
178
+ const notebook = workingCopy.model.notebookModel;
179
+ const activeCellEditor = getActiveCellCodeEditor(this.editorService);
180
+ try {
181
+ const allCellEdits = await Promise.all(( notebook.cells.map(async (cell) => {
182
+ if (cell.cellKind !== CellKind.Code) {
183
+ return;
184
+ }
185
+ let cannotTouchLineNumber = 0;
186
+ const isActiveCell = (activeCellEditor && ( cell.uri.toString()) === activeCellEditor.getModel()?.uri.toString());
187
+ if (isAutoSaved && isActiveCell) {
188
+ const selections = activeCellEditor.getSelections() ?? [];
189
+ for (const sel of selections) {
190
+ cannotTouchLineNumber = Math.max(cannotTouchLineNumber, sel.selectionStartLineNumber);
191
+ }
192
+ }
193
+ const textBuffer = cell.textBuffer;
194
+ const lastNonEmptyLine = this.findLastNonEmptyLine(textBuffer);
195
+ const deleteFromLineNumber = Math.max(lastNonEmptyLine + 1, cannotTouchLineNumber + 1);
196
+ const deletionRange = ( new Range(
197
+ deleteFromLineNumber,
198
+ 1,
199
+ textBuffer.getLineCount(),
200
+ textBuffer.getLineLastNonWhitespaceColumn(textBuffer.getLineCount())
201
+ ));
202
+ if (deletionRange.isEmpty()) {
203
+ return;
204
+ }
205
+ return ( new ResourceTextEdit(
206
+ cell.uri,
207
+ { range: deletionRange, text: '' },
208
+ cell.textModel?.getVersionId()
209
+ ));
210
+ })));
211
+ const filteredEdits = allCellEdits.flat().filter(edit => edit !== undefined);
212
+ await this.bulkEditService.apply(filteredEdits, { label: ( localizeWithPath(
213
+ 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
214
+ 'trimNotebookNewlines',
215
+ "Trim Final New Lines"
216
+ )), code: 'undoredo.trimFinalNewLines' });
217
+ }
218
+ finally {
219
+ progress.report({ increment: 100 });
220
+ disposable.dispose();
221
+ }
222
+ }
223
+ };
224
+ TrimFinalNewLinesParticipant = ( __decorate([
225
+ ( __param(0, IConfigurationService)),
226
+ ( __param(1, IEditorService)),
227
+ ( __param(2, IBulkEditService))
228
+ ], TrimFinalNewLinesParticipant));
229
+ let FinalNewLineParticipant = class FinalNewLineParticipant {
230
+ constructor(configurationService, bulkEditService, editorService) {
231
+ this.configurationService = configurationService;
232
+ this.bulkEditService = bulkEditService;
233
+ this.editorService = editorService;
234
+ }
235
+ async participate(workingCopy, context, progress, _token) {
236
+ if (this.configurationService.getValue(NotebookSetting.insertFinalNewline)) {
237
+ await this.doInsertFinalNewLine(workingCopy, context.reason === 2 , progress);
238
+ }
239
+ }
240
+ async doInsertFinalNewLine(workingCopy, isAutoSaved, progress) {
241
+ if (!workingCopy.model || !(workingCopy.model instanceof NotebookFileWorkingCopyModel)) {
242
+ return;
243
+ }
244
+ const disposable = ( new DisposableStore());
245
+ const notebook = workingCopy.model.notebookModel;
246
+ const activeCellEditor = getActiveCellCodeEditor(this.editorService);
247
+ let selections;
248
+ if (activeCellEditor) {
249
+ selections = activeCellEditor.getSelections() ?? [];
250
+ }
251
+ try {
252
+ const allCellEdits = await Promise.all(( notebook.cells.map(async (cell) => {
253
+ if (cell.cellKind !== CellKind.Code) {
254
+ return;
255
+ }
256
+ const lineCount = cell.textBuffer.getLineCount();
257
+ const lastLineIsEmptyOrWhitespace = cell.textBuffer.getLineFirstNonWhitespaceColumn(lineCount) === 0;
258
+ if (!lineCount || lastLineIsEmptyOrWhitespace) {
259
+ return;
260
+ }
261
+ return ( new ResourceTextEdit(cell.uri, { range: ( new Range(
262
+ lineCount + 1,
263
+ cell.textBuffer.getLineLength(lineCount),
264
+ lineCount + 1,
265
+ cell.textBuffer.getLineLength(lineCount)
266
+ )), text: cell.textBuffer.getEOL() }, cell.textModel?.getVersionId()));
267
+ })));
268
+ const filteredEdits = allCellEdits.filter(edit => edit !== undefined);
269
+ await this.bulkEditService.apply(filteredEdits, { label: ( localizeWithPath(
270
+ 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
271
+ 'insertFinalNewLine',
272
+ "Insert Final New Line"
273
+ )), code: 'undoredo.insertFinalNewLine' });
274
+ if (activeCellEditor && selections) {
275
+ activeCellEditor.setSelections(selections);
276
+ }
277
+ }
278
+ finally {
279
+ progress.report({ increment: 100 });
280
+ disposable.dispose();
281
+ }
282
+ }
283
+ };
284
+ FinalNewLineParticipant = ( __decorate([
285
+ ( __param(0, IConfigurationService)),
286
+ ( __param(1, IBulkEditService)),
287
+ ( __param(2, IEditorService))
288
+ ], FinalNewLineParticipant));
289
+ let CodeActionOnSaveParticipant = class CodeActionOnSaveParticipant {
290
+ constructor(configurationService, logService, workspaceTrustManagementService, languageFeaturesService, textModelService, instantiationService) {
291
+ this.configurationService = configurationService;
292
+ this.logService = logService;
293
+ this.workspaceTrustManagementService = workspaceTrustManagementService;
294
+ this.languageFeaturesService = languageFeaturesService;
295
+ this.textModelService = textModelService;
296
+ this.instantiationService = instantiationService;
297
+ }
298
+ async participate(workingCopy, context, progress, token) {
299
+ const nbDisposable = ( new DisposableStore());
300
+ const isTrusted = this.workspaceTrustManagementService.isWorkspaceTrusted();
301
+ if (!isTrusted) {
302
+ return;
303
+ }
304
+ if (!workingCopy.model || !(workingCopy.model instanceof NotebookFileWorkingCopyModel)) {
305
+ return;
306
+ }
307
+ let saveTrigger = '';
308
+ if (context.reason === 2 ) {
309
+ return undefined;
310
+ }
311
+ else if (context.reason === 1 ) {
312
+ saveTrigger = 'explicit';
313
+ }
314
+ else {
315
+ return undefined;
316
+ }
317
+ const notebookModel = workingCopy.model.notebookModel;
318
+ const setting = this.configurationService.getValue(NotebookSetting.codeActionsOnSave);
319
+ if (!setting) {
320
+ return undefined;
321
+ }
322
+ const settingItems = Array.isArray(setting)
323
+ ? setting
324
+ : ( Object.keys(setting)).filter(x => setting[x]);
325
+ if (!settingItems.length) {
326
+ return undefined;
327
+ }
328
+ const allCodeActions = this.createCodeActionsOnSave(settingItems);
329
+ const excludedActions = allCodeActions
330
+ .filter(x => setting[x.value] === 'never' || setting[x.value] === false);
331
+ const includedActions = allCodeActions
332
+ .filter(x => setting[x.value] === saveTrigger || setting[x.value] === true);
333
+ const editorCodeActionsOnSave = includedActions.filter(x => !CodeActionKind.Notebook.contains(x));
334
+ const notebookCodeActionsOnSave = includedActions.filter(x => CodeActionKind.Notebook.contains(x));
335
+ if (!editorCodeActionsOnSave.length && !notebookCodeActionsOnSave.length) {
336
+ return undefined;
337
+ }
338
+ if (!Array.isArray(setting)) {
339
+ editorCodeActionsOnSave.sort((a, b) => {
340
+ if (CodeActionKind.SourceFixAll.contains(a)) {
341
+ if (CodeActionKind.SourceFixAll.contains(b)) {
342
+ return 0;
343
+ }
344
+ return -1;
345
+ }
346
+ if (CodeActionKind.SourceFixAll.contains(b)) {
347
+ return 1;
348
+ }
349
+ return 0;
350
+ });
351
+ }
352
+ progress.report({ message: ( localizeWithPath(
353
+ 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
354
+ 'notebookSaveParticipants.notebookCodeActions',
355
+ "Running 'Notebook' code actions"
356
+ )) });
357
+ try {
358
+ const cell = notebookModel.cells[0];
359
+ const ref = await this.textModelService.createModelReference(cell.uri);
360
+ nbDisposable.add(ref);
361
+ const textEditorModel = ref.object.textEditorModel;
362
+ await this.applyOnSaveActions(textEditorModel, notebookCodeActionsOnSave, excludedActions, progress, token);
363
+ }
364
+ catch {
365
+ this.logService.error('Failed to apply notebook code action on save');
366
+ }
367
+ finally {
368
+ progress.report({ increment: 100 });
369
+ nbDisposable.dispose();
370
+ }
371
+ const disposable = ( new DisposableStore());
372
+ progress.report({ message: ( localizeWithPath(
373
+ 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
374
+ 'notebookSaveParticipants.cellCodeActions',
375
+ "Running 'Cell' code actions"
376
+ )) });
377
+ try {
378
+ await Promise.all(( notebookModel.cells.map(async (cell) => {
379
+ const ref = await this.textModelService.createModelReference(cell.uri);
380
+ disposable.add(ref);
381
+ const textEditorModel = ref.object.textEditorModel;
382
+ await this.applyOnSaveActions(textEditorModel, editorCodeActionsOnSave, excludedActions, progress, token);
383
+ })));
384
+ }
385
+ catch {
386
+ this.logService.error('Failed to apply code action on save');
387
+ }
388
+ finally {
389
+ progress.report({ increment: 100 });
390
+ disposable.dispose();
391
+ }
392
+ }
393
+ createCodeActionsOnSave(settingItems) {
394
+ const kinds = ( settingItems.map(x => ( new CodeActionKind(x))));
395
+ return kinds.filter(kind => {
396
+ return kinds.every(otherKind => otherKind.equals(kind) || !otherKind.contains(kind));
397
+ });
398
+ }
399
+ async applyOnSaveActions(model, codeActionsOnSave, excludes, progress, token) {
400
+ const getActionProgress = new (class {
401
+ constructor() {
402
+ this._names = ( new Set());
403
+ }
404
+ _report() {
405
+ progress.report({
406
+ message: ( localizeWithPath(
407
+ 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
408
+ { key: 'codeaction.get2', comment: ['[configure]({1}) is a link. Only translate `configure`. Do not change brackets and parentheses or {1}'] },
409
+ "Getting code actions from '{0}' ([configure]({1})).",
410
+ ( [...this._names].map(name => `'${name}'`)).join(', '),
411
+ 'command:workbench.action.openSettings?%5B%22editor.codeActionsOnSave%22%5D'
412
+ ))
413
+ });
414
+ }
415
+ report(provider) {
416
+ if (provider.displayName && !( this._names.has(provider.displayName))) {
417
+ this._names.add(provider.displayName);
418
+ this._report();
419
+ }
420
+ }
421
+ });
422
+ for (const codeActionKind of codeActionsOnSave) {
423
+ const actionsToRun = await this.getActionsToRun(model, codeActionKind, excludes, getActionProgress, token);
424
+ if (token.isCancellationRequested) {
425
+ actionsToRun.dispose();
426
+ return;
427
+ }
428
+ try {
429
+ for (const action of actionsToRun.validActions) {
430
+ const codeActionEdits = action.action.edit?.edits;
431
+ let breakFlag = false;
432
+ if (!action.action.kind?.startsWith('notebook')) {
433
+ for (const edit of codeActionEdits ?? []) {
434
+ const workspaceTextEdit = edit;
435
+ if (workspaceTextEdit.resource && isEqual(workspaceTextEdit.resource, model.uri)) {
436
+ continue;
437
+ }
438
+ else {
439
+ breakFlag = true;
440
+ break;
441
+ }
442
+ }
443
+ }
444
+ if (breakFlag) {
445
+ this.logService.warn('Failed to apply code action on save, applied to multiple resources.');
446
+ continue;
447
+ }
448
+ progress.report({ message: ( localizeWithPath(
449
+ 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
450
+ 'codeAction.apply',
451
+ "Applying code action '{0}'.",
452
+ action.action.title
453
+ )) });
454
+ await this.instantiationService.invokeFunction(applyCodeAction, action, ApplyCodeActionReason.OnSave, {}, token);
455
+ if (token.isCancellationRequested) {
456
+ return;
457
+ }
458
+ }
459
+ }
460
+ catch {
461
+ }
462
+ finally {
463
+ actionsToRun.dispose();
464
+ }
465
+ }
466
+ }
467
+ getActionsToRun(model, codeActionKind, excludes, progress, token) {
468
+ return getCodeActions(this.languageFeaturesService.codeActionProvider, model, model.getFullModelRange(), {
469
+ type: 1 ,
470
+ triggerAction: CodeActionTriggerSource.OnSave,
471
+ filter: { include: codeActionKind, excludes: excludes, includeSourceActions: true },
472
+ }, progress, token);
473
+ }
474
+ };
475
+ CodeActionOnSaveParticipant = ( __decorate([
476
+ ( __param(0, IConfigurationService)),
477
+ ( __param(1, ILogService)),
478
+ ( __param(2, IWorkspaceTrustManagementService)),
479
+ ( __param(3, ILanguageFeaturesService)),
480
+ ( __param(4, ITextModelService)),
481
+ ( __param(5, IInstantiationService))
482
+ ], CodeActionOnSaveParticipant));
483
+ function getActiveCellCodeEditor(editorService) {
484
+ const activePane = editorService.activeEditorPane;
485
+ const notebookEditor = getNotebookEditorFromEditorPane(activePane);
486
+ const activeCodeEditor = notebookEditor?.activeCodeEditor;
487
+ return activeCodeEditor;
488
+ }
489
+ let SaveParticipantsContribution = class SaveParticipantsContribution extends Disposable {
490
+ constructor(instantiationService, workingCopyFileService) {
491
+ super();
492
+ this.instantiationService = instantiationService;
493
+ this.workingCopyFileService = workingCopyFileService;
494
+ this.registerSaveParticipants();
495
+ }
496
+ registerSaveParticipants() {
497
+ this._register(this.workingCopyFileService.addSaveParticipant(this.instantiationService.createInstance(TrimWhitespaceParticipant)));
498
+ this._register(this.workingCopyFileService.addSaveParticipant(this.instantiationService.createInstance(CodeActionOnSaveParticipant)));
499
+ this._register(this.workingCopyFileService.addSaveParticipant(this.instantiationService.createInstance(FormatOnSaveParticipant)));
500
+ this._register(this.workingCopyFileService.addSaveParticipant(this.instantiationService.createInstance(FinalNewLineParticipant)));
501
+ this._register(this.workingCopyFileService.addSaveParticipant(this.instantiationService.createInstance(TrimFinalNewLinesParticipant)));
502
+ }
503
+ };
504
+ SaveParticipantsContribution = ( __decorate([
505
+ ( __param(0, IInstantiationService)),
506
+ ( __param(1, IWorkingCopyFileService))
507
+ ], SaveParticipantsContribution));
508
+ const workbenchContributionsRegistry = ( Registry.as(Extensions.Workbench));
509
+ workbenchContributionsRegistry.registerWorkbenchContribution(SaveParticipantsContribution, 3 );
510
+
511
+ export { SaveParticipantsContribution };
@@ -0,0 +1,168 @@
1
+ import { Disposable, DisposableStore, dispose } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
2
+ import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
3
+ import { registerAction2, Action2 } from 'monaco-editor/esm/vs/platform/actions/common/actions.js';
4
+ import { Categories } from 'monaco-editor/esm/vs/platform/action/common/actionCommonCategories.js';
5
+ import { getNotebookEditorFromEditorPane } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
6
+ import { registerNotebookContribution } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
7
+ import { INotebookService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookService';
8
+ import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
9
+
10
+ class TroubleshootController extends Disposable {
11
+ static { this.id = 'workbench.notebook.troubleshoot'; }
12
+ constructor(_notebookEditor) {
13
+ super();
14
+ this._notebookEditor = _notebookEditor;
15
+ this._localStore = this._register(( new DisposableStore()));
16
+ this._cellStateListeners = [];
17
+ this._enabled = false;
18
+ this._cellStatusItems = [];
19
+ this._register(this._notebookEditor.onDidChangeModel(() => {
20
+ this._update();
21
+ }));
22
+ this._update();
23
+ }
24
+ toggle() {
25
+ this._enabled = !this._enabled;
26
+ this._update();
27
+ }
28
+ _update() {
29
+ this._localStore.clear();
30
+ this._cellStateListeners.forEach(listener => listener.dispose());
31
+ if (!this._notebookEditor.hasModel()) {
32
+ return;
33
+ }
34
+ this._updateListener();
35
+ }
36
+ _log(cell, e) {
37
+ if (this._enabled) {
38
+ const oldHeight = this._notebookEditor.getViewHeight(cell);
39
+ console.log(`cell#${cell.handle}`, e, `${oldHeight} -> ${cell.layoutInfo.totalHeight}`);
40
+ }
41
+ }
42
+ _updateListener() {
43
+ if (!this._notebookEditor.hasModel()) {
44
+ return;
45
+ }
46
+ for (let i = 0; i < this._notebookEditor.getLength(); i++) {
47
+ const cell = this._notebookEditor.cellAt(i);
48
+ this._cellStateListeners.push(cell.onDidChangeLayout(e => {
49
+ this._log(cell, e);
50
+ }));
51
+ }
52
+ this._localStore.add(this._notebookEditor.onDidChangeViewCells(e => {
53
+ [...e.splices].reverse().forEach(splice => {
54
+ const [start, deleted, newCells] = splice;
55
+ const deletedCells = this._cellStateListeners.splice(start, deleted, ...( newCells.map(cell => {
56
+ return cell.onDidChangeLayout((e) => {
57
+ this._log(cell, e);
58
+ });
59
+ })));
60
+ dispose(deletedCells);
61
+ });
62
+ }));
63
+ const vm = this._notebookEditor.getViewModel();
64
+ let items = [];
65
+ if (this._enabled) {
66
+ items = this._getItemsForCells();
67
+ }
68
+ this._cellStatusItems = vm.deltaCellStatusBarItems(this._cellStatusItems, items);
69
+ }
70
+ _getItemsForCells() {
71
+ const items = [];
72
+ for (let i = 0; i < this._notebookEditor.getLength(); i++) {
73
+ items.push({
74
+ handle: i,
75
+ items: [
76
+ {
77
+ text: `index: ${i}`,
78
+ alignment: 1 ,
79
+ priority: Number.MAX_SAFE_INTEGER
80
+ }
81
+ ]
82
+ });
83
+ }
84
+ return items;
85
+ }
86
+ dispose() {
87
+ dispose(this._cellStateListeners);
88
+ super.dispose();
89
+ }
90
+ }
91
+ registerNotebookContribution(TroubleshootController.id, TroubleshootController);
92
+ registerAction2(class extends Action2 {
93
+ constructor() {
94
+ super({
95
+ id: 'notebook.toggleLayoutTroubleshoot',
96
+ title: {
97
+ value: ( localizeWithPath(
98
+ 'vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout',
99
+ 'workbench.notebook.toggleLayoutTroubleshoot',
100
+ "Toggle Layout Troubleshoot"
101
+ )),
102
+ original: 'Toggle Notebook Layout Troubleshoot'
103
+ },
104
+ category: Categories.Developer,
105
+ f1: true
106
+ });
107
+ }
108
+ async run(accessor) {
109
+ const editorService = accessor.get(IEditorService);
110
+ const editor = getNotebookEditorFromEditorPane(editorService.activeEditorPane);
111
+ if (!editor) {
112
+ return;
113
+ }
114
+ const controller = editor.getContribution(TroubleshootController.id);
115
+ controller?.toggle();
116
+ }
117
+ });
118
+ registerAction2(class extends Action2 {
119
+ constructor() {
120
+ super({
121
+ id: 'notebook.inspectLayout',
122
+ title: {
123
+ value: ( localizeWithPath(
124
+ 'vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout',
125
+ 'workbench.notebook.inspectLayout',
126
+ "Inspect Notebook Layout"
127
+ )),
128
+ original: 'Inspect Notebook Layout'
129
+ },
130
+ category: Categories.Developer,
131
+ f1: true
132
+ });
133
+ }
134
+ async run(accessor) {
135
+ const editorService = accessor.get(IEditorService);
136
+ const editor = getNotebookEditorFromEditorPane(editorService.activeEditorPane);
137
+ if (!editor || !editor.hasModel()) {
138
+ return;
139
+ }
140
+ for (let i = 0; i < editor.getLength(); i++) {
141
+ const cell = editor.cellAt(i);
142
+ console.log(`cell#${cell.handle}`, cell.layoutInfo);
143
+ }
144
+ }
145
+ });
146
+ registerAction2(class extends Action2 {
147
+ constructor() {
148
+ super({
149
+ id: 'notebook.clearNotebookEdtitorTypeCache',
150
+ title: {
151
+ value: ( localizeWithPath(
152
+ 'vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout',
153
+ 'workbench.notebook.clearNotebookEdtitorTypeCache',
154
+ "Clear Notebook Editor Type Cache"
155
+ )),
156
+ original: 'Clear Notebook Editor Cache'
157
+ },
158
+ category: Categories.Developer,
159
+ f1: true
160
+ });
161
+ }
162
+ async run(accessor) {
163
+ const notebookService = accessor.get(INotebookService);
164
+ notebookService.clearEditorCache();
165
+ }
166
+ });
167
+
168
+ export { TroubleshootController };