@codingame/monaco-vscode-notebook-service-override 4.0.0 → 4.1.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.
Files changed (77) hide show
  1. package/notebook.js +12 -12
  2. package/package.json +2 -2
  3. package/external/rollup-plugin-styles/dist/runtime/inject-css.js +0 -3
  4. package/external/tslib/tslib.es6.js +0 -11
  5. package/override/vs/platform/dialogs/common/dialogs.js +0 -10
  6. package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.css.js +0 -6
  7. package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.js +0 -391
  8. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/contributedStatusBarItemController.js +0 -109
  9. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/statusBarProviders.js +0 -173
  10. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.js +0 -544
  11. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookBreakpoints.js +0 -106
  12. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookCellPausing.js +0 -67
  13. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookDebugDecorations.js +0 -165
  14. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint.js +0 -67
  15. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.js +0 -320
  16. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/execute/executionEditorProgress.js +0 -72
  17. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/media/notebookFind.css.js +0 -6
  18. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFind.js +0 -168
  19. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.js +0 -209
  20. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/gettingStarted/notebookGettingStarted.js +0 -84
  21. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/kernelDetection/notebookKernelDetection.js +0 -82
  22. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/layout/layoutActions.js +0 -67
  23. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider.js +0 -101
  24. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.js +0 -393
  25. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariableContextKeys.js +0 -5
  26. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.js +0 -97
  27. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesDataSource.js +0 -120
  28. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesTree.js +0 -60
  29. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.js +0 -150
  30. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.js +0 -656
  31. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.js +0 -77
  32. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants.js +0 -517
  33. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout.js +0 -159
  34. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/undoRedo/notebookUndoRedo.js +0 -56
  35. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/viewportWarmup/viewportWarmup.js +0 -94
  36. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/apiActions.js +0 -51
  37. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/cellChatActions.js +0 -652
  38. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/executeActions.js +0 -721
  39. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.js +0 -351
  40. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/layoutActions.js +0 -315
  41. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/sectionActions.js +0 -199
  42. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.js +0 -47
  43. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.js +0 -1297
  44. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.js +0 -284
  45. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.js +0 -563
  46. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.js +0 -115
  47. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.js +0 -39
  48. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css.js +0 -6
  49. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.js +0 -313
  50. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.js +0 -911
  51. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.js +0 -13
  52. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.js +0 -395
  53. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.js +0 -185
  54. package/vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.js +0 -1187
  55. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibility.js +0 -159
  56. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.js +0 -451
  57. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.js +0 -192
  58. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.js +0 -106
  59. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl.js +0 -510
  60. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl.js +0 -130
  61. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.js +0 -341
  62. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKeymapServiceImpl.js +0 -111
  63. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookLoggingServiceImpl.js +0 -28
  64. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookRendererMessagingServiceImpl.js +0 -65
  65. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.js +0 -641
  66. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookWorkerServiceImpl.js +0 -200
  67. package/vscode/src/vs/workbench/contrib/notebook/common/model/cellEdit.js +0 -90
  68. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.js +0 -1002
  69. package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiffEditorInput.js +0 -103
  70. package/vscode/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.js +0 -203
  71. package/vscode/src/vs/workbench/contrib/notebook/common/notebookOutputRenderer.js +0 -80
  72. package/vscode/src/vs/workbench/contrib/notebook/common/notebookProvider.js +0 -98
  73. package/vscode/src/vs/workbench/services/workingCopy/common/abstractFileWorkingCopyManager.js +0 -89
  74. package/vscode/src/vs/workbench/services/workingCopy/common/fileWorkingCopyManager.js +0 -386
  75. package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopyManager.js +0 -408
  76. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopy.js +0 -144
  77. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopyManager.js +0 -129
@@ -1,77 +0,0 @@
1
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
2
- import { registerAction2, Action2 } from 'vscode/vscode/vs/platform/actions/common/actions';
3
- import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
4
- import { NotebookSetting } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
5
-
6
- var NotebookProfileType;
7
- ( (function(NotebookProfileType) {
8
- NotebookProfileType["default"] = "default";
9
- NotebookProfileType["jupyter"] = "jupyter";
10
- NotebookProfileType["colab"] = "colab";
11
- })(NotebookProfileType || (NotebookProfileType = {})));
12
- const profiles = {
13
- [NotebookProfileType.default]: {
14
- [NotebookSetting.focusIndicator]: 'gutter',
15
- [NotebookSetting.insertToolbarLocation]: 'both',
16
- [NotebookSetting.globalToolbar]: true,
17
- [NotebookSetting.cellToolbarLocation]: { default: 'right' },
18
- [NotebookSetting.compactView]: true,
19
- [NotebookSetting.showCellStatusBar]: 'visible',
20
- [NotebookSetting.consolidatedRunButton]: true,
21
- [NotebookSetting.undoRedoPerCell]: false
22
- },
23
- [NotebookProfileType.jupyter]: {
24
- [NotebookSetting.focusIndicator]: 'gutter',
25
- [NotebookSetting.insertToolbarLocation]: 'notebookToolbar',
26
- [NotebookSetting.globalToolbar]: true,
27
- [NotebookSetting.cellToolbarLocation]: { default: 'left' },
28
- [NotebookSetting.compactView]: true,
29
- [NotebookSetting.showCellStatusBar]: 'visible',
30
- [NotebookSetting.consolidatedRunButton]: false,
31
- [NotebookSetting.undoRedoPerCell]: true
32
- },
33
- [NotebookProfileType.colab]: {
34
- [NotebookSetting.focusIndicator]: 'border',
35
- [NotebookSetting.insertToolbarLocation]: 'betweenCells',
36
- [NotebookSetting.globalToolbar]: false,
37
- [NotebookSetting.cellToolbarLocation]: { default: 'right' },
38
- [NotebookSetting.compactView]: false,
39
- [NotebookSetting.showCellStatusBar]: 'hidden',
40
- [NotebookSetting.consolidatedRunButton]: true,
41
- [NotebookSetting.undoRedoPerCell]: false
42
- }
43
- };
44
- async function applyProfile(configService, profile) {
45
- const promises = [];
46
- for (const settingKey in profile) {
47
- promises.push(configService.updateValue(settingKey, profile[settingKey]));
48
- }
49
- await Promise.all(promises);
50
- }
51
- registerAction2(class extends Action2 {
52
- constructor() {
53
- super({
54
- id: 'notebook.setProfile',
55
- title: ( localizeWithPath(
56
- 'vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile',
57
- 'setProfileTitle',
58
- "Set Profile"
59
- ))
60
- });
61
- }
62
- async run(accessor, args) {
63
- if (!isSetProfileArgs(args)) {
64
- return;
65
- }
66
- const configService = accessor.get(IConfigurationService);
67
- return applyProfile(configService, profiles[args.profile]);
68
- }
69
- });
70
- function isSetProfileArgs(args) {
71
- const setProfileArgs = args;
72
- return setProfileArgs.profile === NotebookProfileType.colab ||
73
- setProfileArgs.profile === NotebookProfileType.default ||
74
- setProfileArgs.profile === NotebookProfileType.jupyter;
75
- }
76
-
77
- export { NotebookProfileType };
@@ -1,517 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../../../external/tslib/tslib.es6.js';
2
- import { HierarchicalKind } from 'vscode/vscode/vs/base/common/hierarchicalKind';
3
- import { Disposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
4
- import { isEqual } from 'vscode/vscode/vs/base/common/resources';
5
- import { ResourceTextEdit, IBulkEditService } from 'vscode/vscode/vs/editor/browser/services/bulkEditService';
6
- import { trimTrailingWhitespace } from 'vscode/vscode/vs/editor/common/commands/trimTrailingWhitespaceCommand';
7
- import { Position } from 'vscode/vscode/vs/editor/common/core/position';
8
- import { Range } from 'vscode/vscode/vs/editor/common/core/range';
9
- import { IEditorWorkerService } from 'vscode/vscode/vs/editor/common/services/editorWorker';
10
- import { ILanguageFeaturesService } from 'vscode/vscode/vs/editor/common/services/languageFeatures';
11
- import { ITextModelService } from 'vscode/vscode/vs/editor/common/services/resolverService';
12
- import { applyCodeAction, ApplyCodeActionReason, getCodeActions } from 'vscode/vscode/vs/editor/contrib/codeAction/browser/codeAction';
13
- import { CodeActionKind, CodeActionTriggerSource } from 'vscode/vscode/vs/editor/contrib/codeAction/common/types';
14
- import { getDocumentFormattingEditsUntilResult } from 'vscode/vscode/vs/editor/contrib/format/browser/format';
15
- import { SnippetController2 } from 'vscode/vscode/vs/editor/contrib/snippet/browser/snippetController2';
16
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
17
- import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
18
- import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
19
- import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
20
- import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
21
- import { IWorkspaceTrustManagementService } from 'vscode/vscode/vs/platform/workspace/common/workspaceTrust';
22
- import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
23
- import { getNotebookEditorFromEditorPane } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
24
- import { NotebookSetting, CellKind } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
25
- import { NotebookFileWorkingCopyModel } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookEditorModel';
26
- import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
27
- import { IWorkingCopyFileService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyFileService';
28
-
29
- let FormatOnSaveParticipant = class FormatOnSaveParticipant {
30
- constructor(editorWorkerService, languageFeaturesService, textModelService, bulkEditService, configurationService) {
31
- this.editorWorkerService = editorWorkerService;
32
- this.languageFeaturesService = languageFeaturesService;
33
- this.textModelService = textModelService;
34
- this.bulkEditService = bulkEditService;
35
- this.configurationService = configurationService;
36
- }
37
- async participate(workingCopy, context, progress, token) {
38
- if (!workingCopy.model || !(workingCopy.model instanceof NotebookFileWorkingCopyModel)) {
39
- return;
40
- }
41
- if (context.reason === 2 ) {
42
- return undefined;
43
- }
44
- const enabled = this.configurationService.getValue(NotebookSetting.formatOnSave);
45
- if (!enabled) {
46
- return undefined;
47
- }
48
- const notebook = workingCopy.model.notebookModel;
49
- progress.report({ message: ( localizeWithPath(
50
- 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
51
- 'notebookFormatSave.formatting',
52
- "Formatting"
53
- )) });
54
- const disposable = ( new DisposableStore());
55
- try {
56
- const allCellEdits = await Promise.all(( notebook.cells.map(async (cell) => {
57
- const ref = await this.textModelService.createModelReference(cell.uri);
58
- disposable.add(ref);
59
- const model = ref.object.textEditorModel;
60
- const formatEdits = await getDocumentFormattingEditsUntilResult(this.editorWorkerService, this.languageFeaturesService, model, model.getOptions(), token);
61
- const edits = [];
62
- if (formatEdits) {
63
- edits.push(...( formatEdits.map(edit => ( new ResourceTextEdit(model.uri, edit, model.getVersionId())))));
64
- return edits;
65
- }
66
- return [];
67
- })));
68
- await this.bulkEditService.apply( allCellEdits.flat(), { label: ( localizeWithPath(
69
- 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
70
- 'formatNotebook',
71
- "Format Notebook"
72
- )), code: 'undoredo.formatNotebook', });
73
- }
74
- finally {
75
- progress.report({ increment: 100 });
76
- disposable.dispose();
77
- }
78
- }
79
- };
80
- FormatOnSaveParticipant = ( __decorate([
81
- ( __param(0, IEditorWorkerService)),
82
- ( __param(1, ILanguageFeaturesService)),
83
- ( __param(2, ITextModelService)),
84
- ( __param(3, IBulkEditService)),
85
- ( __param(4, IConfigurationService))
86
- ], FormatOnSaveParticipant));
87
- let TrimWhitespaceParticipant = class TrimWhitespaceParticipant {
88
- constructor(configurationService, editorService, textModelService, bulkEditService) {
89
- this.configurationService = configurationService;
90
- this.editorService = editorService;
91
- this.textModelService = textModelService;
92
- this.bulkEditService = bulkEditService;
93
- }
94
- async participate(workingCopy, context, progress, _token) {
95
- const trimTrailingWhitespaceOption = this.configurationService.getValue('files.trimTrailingWhitespace');
96
- const trimInRegexAndStrings = this.configurationService.getValue('files.trimTrailingWhitespaceInRegexAndStrings');
97
- if (trimTrailingWhitespaceOption) {
98
- await this.doTrimTrailingWhitespace(workingCopy, context.reason === 2 , trimInRegexAndStrings, progress);
99
- }
100
- }
101
- async doTrimTrailingWhitespace(workingCopy, isAutoSaved, trimInRegexesAndStrings, progress) {
102
- if (!workingCopy.model || !(workingCopy.model instanceof NotebookFileWorkingCopyModel)) {
103
- return;
104
- }
105
- const disposable = ( new DisposableStore());
106
- const notebook = workingCopy.model.notebookModel;
107
- const activeCellEditor = getActiveCellCodeEditor(this.editorService);
108
- let cursors = [];
109
- let prevSelection = [];
110
- try {
111
- const allCellEdits = await Promise.all(( notebook.cells.map(async (cell) => {
112
- if (cell.cellKind !== CellKind.Code) {
113
- return [];
114
- }
115
- const ref = await this.textModelService.createModelReference(cell.uri);
116
- disposable.add(ref);
117
- const model = ref.object.textEditorModel;
118
- const isActiveCell = (activeCellEditor && ( cell.uri.toString()) === activeCellEditor.getModel()?.uri.toString());
119
- if (isActiveCell) {
120
- prevSelection = activeCellEditor.getSelections() ?? [];
121
- if (isAutoSaved) {
122
- cursors = ( prevSelection.map(s => s.getPosition()));
123
- const snippetsRange = SnippetController2.get(activeCellEditor)?.getSessionEnclosingRange();
124
- if (snippetsRange) {
125
- for (let lineNumber = snippetsRange.startLineNumber; lineNumber <= snippetsRange.endLineNumber; lineNumber++) {
126
- cursors.push(( new Position(lineNumber, model.getLineMaxColumn(lineNumber))));
127
- }
128
- }
129
- }
130
- }
131
- const ops = trimTrailingWhitespace(model, cursors, trimInRegexesAndStrings);
132
- if (!ops.length) {
133
- return [];
134
- }
135
- return ( ops.map(op => ( new ResourceTextEdit(model.uri, { ...op, text: op.text || '' }, model.getVersionId()))));
136
- })));
137
- const filteredEdits = allCellEdits.flat().filter(edit => edit !== undefined);
138
- await this.bulkEditService.apply(filteredEdits, { label: ( localizeWithPath(
139
- 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
140
- 'trimNotebookWhitespace',
141
- "Notebook Trim Trailing Whitespace"
142
- )), code: 'undoredo.notebookTrimTrailingWhitespace' });
143
- }
144
- finally {
145
- progress.report({ increment: 100 });
146
- disposable.dispose();
147
- }
148
- }
149
- };
150
- TrimWhitespaceParticipant = ( __decorate([
151
- ( __param(0, IConfigurationService)),
152
- ( __param(1, IEditorService)),
153
- ( __param(2, ITextModelService)),
154
- ( __param(3, IBulkEditService))
155
- ], TrimWhitespaceParticipant));
156
- let TrimFinalNewLinesParticipant = class TrimFinalNewLinesParticipant {
157
- constructor(configurationService, editorService, bulkEditService) {
158
- this.configurationService = configurationService;
159
- this.editorService = editorService;
160
- this.bulkEditService = bulkEditService;
161
- }
162
- async participate(workingCopy, context, progress, _token) {
163
- if (this.configurationService.getValue('files.trimFinalNewlines')) {
164
- await this.doTrimFinalNewLines(workingCopy, context.reason === 2 , progress);
165
- }
166
- }
167
- findLastNonEmptyLine(textBuffer) {
168
- for (let lineNumber = textBuffer.getLineCount(); lineNumber >= 1; lineNumber--) {
169
- const lineLength = textBuffer.getLineLength(lineNumber);
170
- if (lineLength) {
171
- return lineNumber;
172
- }
173
- }
174
- return 0;
175
- }
176
- async doTrimFinalNewLines(workingCopy, isAutoSaved, progress) {
177
- if (!workingCopy.model || !(workingCopy.model instanceof NotebookFileWorkingCopyModel)) {
178
- return;
179
- }
180
- const disposable = ( new DisposableStore());
181
- const notebook = workingCopy.model.notebookModel;
182
- const activeCellEditor = getActiveCellCodeEditor(this.editorService);
183
- try {
184
- const allCellEdits = await Promise.all(( notebook.cells.map(async (cell) => {
185
- if (cell.cellKind !== CellKind.Code) {
186
- return;
187
- }
188
- let cannotTouchLineNumber = 0;
189
- const isActiveCell = (activeCellEditor && ( cell.uri.toString()) === activeCellEditor.getModel()?.uri.toString());
190
- if (isAutoSaved && isActiveCell) {
191
- const selections = activeCellEditor.getSelections() ?? [];
192
- for (const sel of selections) {
193
- cannotTouchLineNumber = Math.max(cannotTouchLineNumber, sel.selectionStartLineNumber);
194
- }
195
- }
196
- const textBuffer = cell.textBuffer;
197
- const lastNonEmptyLine = this.findLastNonEmptyLine(textBuffer);
198
- const deleteFromLineNumber = Math.max(lastNonEmptyLine + 1, cannotTouchLineNumber + 1);
199
- if (deleteFromLineNumber > textBuffer.getLineCount()) {
200
- return;
201
- }
202
- const deletionRange = ( new Range(
203
- deleteFromLineNumber,
204
- 1,
205
- textBuffer.getLineCount(),
206
- textBuffer.getLineLastNonWhitespaceColumn(textBuffer.getLineCount())
207
- ));
208
- if (deletionRange.isEmpty()) {
209
- return;
210
- }
211
- return ( new ResourceTextEdit(
212
- cell.uri,
213
- { range: deletionRange, text: '' },
214
- cell.textModel?.getVersionId()
215
- ));
216
- })));
217
- const filteredEdits = allCellEdits.flat().filter(edit => edit !== undefined);
218
- await this.bulkEditService.apply(filteredEdits, { label: ( localizeWithPath(
219
- 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
220
- 'trimNotebookNewlines',
221
- "Trim Final New Lines"
222
- )), code: 'undoredo.trimFinalNewLines' });
223
- }
224
- finally {
225
- progress.report({ increment: 100 });
226
- disposable.dispose();
227
- }
228
- }
229
- };
230
- TrimFinalNewLinesParticipant = ( __decorate([
231
- ( __param(0, IConfigurationService)),
232
- ( __param(1, IEditorService)),
233
- ( __param(2, IBulkEditService))
234
- ], TrimFinalNewLinesParticipant));
235
- let InsertFinalNewLineParticipant = class InsertFinalNewLineParticipant {
236
- constructor(configurationService, bulkEditService, editorService) {
237
- this.configurationService = configurationService;
238
- this.bulkEditService = bulkEditService;
239
- this.editorService = editorService;
240
- }
241
- async participate(workingCopy, context, progress, _token) {
242
- if (this.configurationService.getValue(NotebookSetting.insertFinalNewline)) {
243
- await this.doInsertFinalNewLine(workingCopy, context.reason === 2 , progress);
244
- }
245
- }
246
- async doInsertFinalNewLine(workingCopy, isAutoSaved, progress) {
247
- if (!workingCopy.model || !(workingCopy.model instanceof NotebookFileWorkingCopyModel)) {
248
- return;
249
- }
250
- const disposable = ( new DisposableStore());
251
- const notebook = workingCopy.model.notebookModel;
252
- const activeCellEditor = getActiveCellCodeEditor(this.editorService);
253
- let selections;
254
- if (activeCellEditor) {
255
- selections = activeCellEditor.getSelections() ?? [];
256
- }
257
- try {
258
- const allCellEdits = await Promise.all(( notebook.cells.map(async (cell) => {
259
- if (cell.cellKind !== CellKind.Code) {
260
- return;
261
- }
262
- const lineCount = cell.textBuffer.getLineCount();
263
- const lastLineIsEmptyOrWhitespace = cell.textBuffer.getLineFirstNonWhitespaceColumn(lineCount) === 0;
264
- if (!lineCount || lastLineIsEmptyOrWhitespace) {
265
- return;
266
- }
267
- return ( new ResourceTextEdit(cell.uri, { range: ( new Range(
268
- lineCount + 1,
269
- cell.textBuffer.getLineLength(lineCount),
270
- lineCount + 1,
271
- cell.textBuffer.getLineLength(lineCount)
272
- )), text: cell.textBuffer.getEOL() }, cell.textModel?.getVersionId()));
273
- })));
274
- const filteredEdits = allCellEdits.filter(edit => edit !== undefined);
275
- await this.bulkEditService.apply(filteredEdits, { label: ( localizeWithPath(
276
- 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
277
- 'insertFinalNewLine',
278
- "Insert Final New Line"
279
- )), code: 'undoredo.insertFinalNewLine' });
280
- if (activeCellEditor && selections) {
281
- activeCellEditor.setSelections(selections);
282
- }
283
- }
284
- finally {
285
- progress.report({ increment: 100 });
286
- disposable.dispose();
287
- }
288
- }
289
- };
290
- InsertFinalNewLineParticipant = ( __decorate([
291
- ( __param(0, IConfigurationService)),
292
- ( __param(1, IBulkEditService)),
293
- ( __param(2, IEditorService))
294
- ], InsertFinalNewLineParticipant));
295
- let CodeActionOnSaveParticipant = class CodeActionOnSaveParticipant {
296
- constructor(configurationService, logService, workspaceTrustManagementService, languageFeaturesService, textModelService, instantiationService) {
297
- this.configurationService = configurationService;
298
- this.logService = logService;
299
- this.workspaceTrustManagementService = workspaceTrustManagementService;
300
- this.languageFeaturesService = languageFeaturesService;
301
- this.textModelService = textModelService;
302
- this.instantiationService = instantiationService;
303
- }
304
- async participate(workingCopy, context, progress, token) {
305
- const nbDisposable = ( new DisposableStore());
306
- const isTrusted = this.workspaceTrustManagementService.isWorkspaceTrusted();
307
- if (!isTrusted) {
308
- return;
309
- }
310
- if (!workingCopy.model || !(workingCopy.model instanceof NotebookFileWorkingCopyModel)) {
311
- return;
312
- }
313
- let saveTrigger = '';
314
- if (context.reason === 2 ) {
315
- return undefined;
316
- }
317
- else if (context.reason === 1 ) {
318
- saveTrigger = 'explicit';
319
- }
320
- else {
321
- return undefined;
322
- }
323
- const notebookModel = workingCopy.model.notebookModel;
324
- const setting = this.configurationService.getValue(NotebookSetting.codeActionsOnSave);
325
- if (!setting) {
326
- return undefined;
327
- }
328
- const settingItems = Array.isArray(setting)
329
- ? setting
330
- : ( Object.keys(setting)).filter(x => setting[x]);
331
- if (!settingItems.length) {
332
- return undefined;
333
- }
334
- const allCodeActions = this.createCodeActionsOnSave(settingItems);
335
- const excludedActions = allCodeActions
336
- .filter(x => setting[x.value] === 'never' || setting[x.value] === false);
337
- const includedActions = allCodeActions
338
- .filter(x => setting[x.value] === saveTrigger || setting[x.value] === true);
339
- const editorCodeActionsOnSave = includedActions.filter(x => !CodeActionKind.Notebook.contains(x));
340
- const notebookCodeActionsOnSave = includedActions.filter(x => CodeActionKind.Notebook.contains(x));
341
- if (!editorCodeActionsOnSave.length && !notebookCodeActionsOnSave.length) {
342
- return undefined;
343
- }
344
- if (!Array.isArray(setting)) {
345
- editorCodeActionsOnSave.sort((a, b) => {
346
- if (CodeActionKind.SourceFixAll.contains(a)) {
347
- if (CodeActionKind.SourceFixAll.contains(b)) {
348
- return 0;
349
- }
350
- return -1;
351
- }
352
- if (CodeActionKind.SourceFixAll.contains(b)) {
353
- return 1;
354
- }
355
- return 0;
356
- });
357
- }
358
- progress.report({ message: ( localizeWithPath(
359
- 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
360
- 'notebookSaveParticipants.notebookCodeActions',
361
- "Running 'Notebook' code actions"
362
- )) });
363
- try {
364
- const cell = notebookModel.cells[0];
365
- const ref = await this.textModelService.createModelReference(cell.uri);
366
- nbDisposable.add(ref);
367
- const textEditorModel = ref.object.textEditorModel;
368
- await this.applyOnSaveActions(textEditorModel, notebookCodeActionsOnSave, excludedActions, progress, token);
369
- }
370
- catch {
371
- this.logService.error('Failed to apply notebook code action on save');
372
- }
373
- finally {
374
- progress.report({ increment: 100 });
375
- nbDisposable.dispose();
376
- }
377
- const disposable = ( new DisposableStore());
378
- progress.report({ message: ( localizeWithPath(
379
- 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
380
- 'notebookSaveParticipants.cellCodeActions',
381
- "Running 'Cell' code actions"
382
- )) });
383
- try {
384
- await Promise.all(( notebookModel.cells.map(async (cell) => {
385
- const ref = await this.textModelService.createModelReference(cell.uri);
386
- disposable.add(ref);
387
- const textEditorModel = ref.object.textEditorModel;
388
- await this.applyOnSaveActions(textEditorModel, editorCodeActionsOnSave, excludedActions, progress, token);
389
- })));
390
- }
391
- catch {
392
- this.logService.error('Failed to apply code action on save');
393
- }
394
- finally {
395
- progress.report({ increment: 100 });
396
- disposable.dispose();
397
- }
398
- }
399
- createCodeActionsOnSave(settingItems) {
400
- const kinds = ( settingItems.map(x => ( new HierarchicalKind(x))));
401
- return kinds.filter(kind => {
402
- return kinds.every(otherKind => otherKind.equals(kind) || !otherKind.contains(kind));
403
- });
404
- }
405
- async applyOnSaveActions(model, codeActionsOnSave, excludes, progress, token) {
406
- const getActionProgress = new (class {
407
- constructor() {
408
- this._names = ( new Set());
409
- }
410
- _report() {
411
- progress.report({
412
- message: ( localizeWithPath(
413
- 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
414
- { key: 'codeaction.get2', comment: ['[configure]({1}) is a link. Only translate `configure`. Do not change brackets and parentheses or {1}'] },
415
- "Getting code actions from '{0}' ([configure]({1})).",
416
- ( [...this._names].map(name => `'${name}'`)).join(', '),
417
- 'command:workbench.action.openSettings?%5B%22editor.codeActionsOnSave%22%5D'
418
- ))
419
- });
420
- }
421
- report(provider) {
422
- if (provider.displayName && !( this._names.has(provider.displayName))) {
423
- this._names.add(provider.displayName);
424
- this._report();
425
- }
426
- }
427
- });
428
- for (const codeActionKind of codeActionsOnSave) {
429
- const actionsToRun = await this.getActionsToRun(model, codeActionKind, excludes, getActionProgress, token);
430
- if (token.isCancellationRequested) {
431
- actionsToRun.dispose();
432
- return;
433
- }
434
- try {
435
- for (const action of actionsToRun.validActions) {
436
- const codeActionEdits = action.action.edit?.edits;
437
- let breakFlag = false;
438
- if (!action.action.kind?.startsWith('notebook')) {
439
- for (const edit of codeActionEdits ?? []) {
440
- const workspaceTextEdit = edit;
441
- if (workspaceTextEdit.resource && isEqual(workspaceTextEdit.resource, model.uri)) {
442
- continue;
443
- }
444
- else {
445
- breakFlag = true;
446
- break;
447
- }
448
- }
449
- }
450
- if (breakFlag) {
451
- this.logService.warn('Failed to apply code action on save, applied to multiple resources.');
452
- continue;
453
- }
454
- progress.report({ message: ( localizeWithPath(
455
- 'vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants',
456
- 'codeAction.apply',
457
- "Applying code action '{0}'.",
458
- action.action.title
459
- )) });
460
- await this.instantiationService.invokeFunction(applyCodeAction, action, ApplyCodeActionReason.OnSave, {}, token);
461
- if (token.isCancellationRequested) {
462
- return;
463
- }
464
- }
465
- }
466
- catch {
467
- }
468
- finally {
469
- actionsToRun.dispose();
470
- }
471
- }
472
- }
473
- getActionsToRun(model, codeActionKind, excludes, progress, token) {
474
- return getCodeActions(this.languageFeaturesService.codeActionProvider, model, model.getFullModelRange(), {
475
- type: 1 ,
476
- triggerAction: CodeActionTriggerSource.OnSave,
477
- filter: { include: codeActionKind, excludes: excludes, includeSourceActions: true },
478
- }, progress, token);
479
- }
480
- };
481
- CodeActionOnSaveParticipant = ( __decorate([
482
- ( __param(0, IConfigurationService)),
483
- ( __param(1, ILogService)),
484
- ( __param(2, IWorkspaceTrustManagementService)),
485
- ( __param(3, ILanguageFeaturesService)),
486
- ( __param(4, ITextModelService)),
487
- ( __param(5, IInstantiationService))
488
- ], CodeActionOnSaveParticipant));
489
- function getActiveCellCodeEditor(editorService) {
490
- const activePane = editorService.activeEditorPane;
491
- const notebookEditor = getNotebookEditorFromEditorPane(activePane);
492
- const activeCodeEditor = notebookEditor?.activeCodeEditor;
493
- return activeCodeEditor;
494
- }
495
- let SaveParticipantsContribution = class SaveParticipantsContribution extends Disposable {
496
- constructor(instantiationService, workingCopyFileService) {
497
- super();
498
- this.instantiationService = instantiationService;
499
- this.workingCopyFileService = workingCopyFileService;
500
- this.registerSaveParticipants();
501
- }
502
- registerSaveParticipants() {
503
- this._register(this.workingCopyFileService.addSaveParticipant(this.instantiationService.createInstance(TrimWhitespaceParticipant)));
504
- this._register(this.workingCopyFileService.addSaveParticipant(this.instantiationService.createInstance(CodeActionOnSaveParticipant)));
505
- this._register(this.workingCopyFileService.addSaveParticipant(this.instantiationService.createInstance(FormatOnSaveParticipant)));
506
- this._register(this.workingCopyFileService.addSaveParticipant(this.instantiationService.createInstance(InsertFinalNewLineParticipant)));
507
- this._register(this.workingCopyFileService.addSaveParticipant(this.instantiationService.createInstance(TrimFinalNewLinesParticipant)));
508
- }
509
- };
510
- SaveParticipantsContribution = ( __decorate([
511
- ( __param(0, IInstantiationService)),
512
- ( __param(1, IWorkingCopyFileService))
513
- ], SaveParticipantsContribution));
514
- const workbenchContributionsRegistry = ( Registry.as(Extensions.Workbench));
515
- workbenchContributionsRegistry.registerWorkbenchContribution(SaveParticipantsContribution, 3 );
516
-
517
- export { SaveParticipantsContribution };