@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,217 @@
1
+ import { LcsDiff } from 'monaco-editor/esm/vs/base/common/diff/diff.js';
2
+ import { hash, numberHash, doHash } from 'monaco-editor/esm/vs/base/common/hash.js';
3
+ import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
4
+ import { PieceTreeTextBufferBuilder } from 'monaco-editor/esm/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder.js';
5
+ import { CellKind, NotebookCellsChangeType } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
6
+ import { Range } from 'monaco-editor/esm/vs/editor/common/core/range.js';
7
+ import { SearchParams } from 'monaco-editor/esm/vs/editor/common/model/textModelSearch.js';
8
+
9
+ function bufferHash(buffer) {
10
+ let initialHashVal = numberHash(104579, 0);
11
+ for (let k = 0; k < buffer.buffer.length; k++) {
12
+ initialHashVal = doHash(buffer.buffer[k], initialHashVal);
13
+ }
14
+ return initialHashVal;
15
+ }
16
+ class MirrorCell {
17
+ get textBuffer() {
18
+ if (this._textBuffer) {
19
+ return this._textBuffer;
20
+ }
21
+ const builder = ( new PieceTreeTextBufferBuilder());
22
+ builder.acceptChunk(Array.isArray(this._source) ? this._source.join('\n') : this._source);
23
+ const bufferFactory = builder.finish(true);
24
+ this._textBuffer = bufferFactory.create(1 ).textBuffer;
25
+ return this._textBuffer;
26
+ }
27
+ primaryKey() {
28
+ if (this._primaryKey === undefined) {
29
+ this._primaryKey = hash(this.getValue());
30
+ }
31
+ return this._primaryKey;
32
+ }
33
+ constructor(handle, _source, language, cellKind, outputs, metadata, internalMetadata) {
34
+ this.handle = handle;
35
+ this._source = _source;
36
+ this.language = language;
37
+ this.cellKind = cellKind;
38
+ this.outputs = outputs;
39
+ this.metadata = metadata;
40
+ this.internalMetadata = internalMetadata;
41
+ this._primaryKey = null;
42
+ this._hash = null;
43
+ }
44
+ getFullModelRange() {
45
+ const lineCount = this.textBuffer.getLineCount();
46
+ return ( new Range(1, 1, lineCount, this.textBuffer.getLineLength(lineCount) + 1));
47
+ }
48
+ getValue() {
49
+ const fullRange = this.getFullModelRange();
50
+ return this.textBuffer.getValueInRange(fullRange, 1 );
51
+ }
52
+ getComparisonValue() {
53
+ if (this._primaryKey !== null) {
54
+ return this._primaryKey;
55
+ }
56
+ this._hash = hash([hash(this.language), hash(this.getValue()), this.metadata, this.internalMetadata, ( this.outputs.map(op => ({
57
+ outputs: ( op.outputs.map(output => ({
58
+ mime: output.mime,
59
+ data: bufferHash(output.data)
60
+ }))),
61
+ metadata: op.metadata
62
+ })))]);
63
+ return this._hash;
64
+ }
65
+ getHashValue() {
66
+ if (this._hash !== null) {
67
+ return this._hash;
68
+ }
69
+ this._hash = hash([hash(this.getValue()), this.language, this.metadata, this.internalMetadata]);
70
+ return this._hash;
71
+ }
72
+ }
73
+ class MirrorNotebookDocument {
74
+ constructor(uri, cells, metadata) {
75
+ this.uri = uri;
76
+ this.cells = cells;
77
+ this.metadata = metadata;
78
+ }
79
+ acceptModelChanged(event) {
80
+ event.rawEvents.forEach(e => {
81
+ if (e.kind === NotebookCellsChangeType.ModelChange) {
82
+ this._spliceNotebookCells(e.changes);
83
+ }
84
+ else if (e.kind === NotebookCellsChangeType.Move) {
85
+ const cells = this.cells.splice(e.index, 1);
86
+ this.cells.splice(e.newIdx, 0, ...cells);
87
+ }
88
+ else if (e.kind === NotebookCellsChangeType.Output) {
89
+ const cell = this.cells[e.index];
90
+ cell.outputs = e.outputs;
91
+ }
92
+ else if (e.kind === NotebookCellsChangeType.ChangeCellLanguage) {
93
+ this._assertIndex(e.index);
94
+ const cell = this.cells[e.index];
95
+ cell.language = e.language;
96
+ }
97
+ else if (e.kind === NotebookCellsChangeType.ChangeCellMetadata) {
98
+ this._assertIndex(e.index);
99
+ const cell = this.cells[e.index];
100
+ cell.metadata = e.metadata;
101
+ }
102
+ else if (e.kind === NotebookCellsChangeType.ChangeCellInternalMetadata) {
103
+ this._assertIndex(e.index);
104
+ const cell = this.cells[e.index];
105
+ cell.internalMetadata = e.internalMetadata;
106
+ }
107
+ });
108
+ }
109
+ _assertIndex(index) {
110
+ if (index < 0 || index >= this.cells.length) {
111
+ throw new Error(`Illegal index ${index}. Cells length: ${this.cells.length}`);
112
+ }
113
+ }
114
+ _spliceNotebookCells(splices) {
115
+ splices.reverse().forEach(splice => {
116
+ const cellDtos = splice[2];
117
+ const newCells = ( cellDtos.map(cell => {
118
+ return ( new MirrorCell(
119
+ cell.handle,
120
+ cell.source,
121
+ cell.language,
122
+ cell.cellKind,
123
+ cell.outputs,
124
+ cell.metadata
125
+ ));
126
+ }));
127
+ this.cells.splice(splice[0], splice[1], ...newCells);
128
+ });
129
+ }
130
+ }
131
+ class CellSequence {
132
+ constructor(textModel) {
133
+ this.textModel = textModel;
134
+ }
135
+ getElements() {
136
+ const hashValue = ( new Int32Array(this.textModel.cells.length));
137
+ for (let i = 0; i < this.textModel.cells.length; i++) {
138
+ hashValue[i] = this.textModel.cells[i].getComparisonValue();
139
+ }
140
+ return hashValue;
141
+ }
142
+ getCellHash(cell) {
143
+ const source = Array.isArray(cell.source) ? cell.source.join('\n') : cell.source;
144
+ const hashVal = hash([hash(source), cell.metadata]);
145
+ return hashVal;
146
+ }
147
+ }
148
+ class NotebookEditorSimpleWorker {
149
+ constructor() {
150
+ this._models = Object.create(null);
151
+ }
152
+ dispose() {
153
+ }
154
+ acceptNewModel(uri, data) {
155
+ this._models[uri] = ( new MirrorNotebookDocument(( URI.parse(uri)), ( data.cells.map(dto => ( new MirrorCell(
156
+ dto.handle,
157
+ dto.source,
158
+ dto.language,
159
+ dto.cellKind,
160
+ dto.outputs,
161
+ dto.metadata
162
+ )))), data.metadata));
163
+ }
164
+ acceptModelChanged(strURL, event) {
165
+ const model = this._models[strURL];
166
+ model?.acceptModelChanged(event);
167
+ }
168
+ acceptRemovedModel(strURL) {
169
+ if (!this._models[strURL]) {
170
+ return;
171
+ }
172
+ delete this._models[strURL];
173
+ }
174
+ computeDiff(originalUrl, modifiedUrl) {
175
+ const original = this._getModel(originalUrl);
176
+ const modified = this._getModel(modifiedUrl);
177
+ const diff = ( new LcsDiff(( new CellSequence(original)), ( new CellSequence(modified))));
178
+ const diffResult = diff.ComputeDiff(false);
179
+ return {
180
+ cellsDiff: diffResult,
181
+ };
182
+ }
183
+ canPromptRecommendation(modelUrl) {
184
+ const model = this._getModel(modelUrl);
185
+ const cells = model.cells;
186
+ for (let i = 0; i < cells.length; i++) {
187
+ const cell = cells[i];
188
+ if (cell.cellKind === CellKind.Markup) {
189
+ continue;
190
+ }
191
+ if (cell.language !== 'python') {
192
+ continue;
193
+ }
194
+ const lineCount = cell.textBuffer.getLineCount();
195
+ const maxLineCount = Math.min(lineCount, 20);
196
+ const range = ( new Range(1, 1, maxLineCount, cell.textBuffer.getLineLength(maxLineCount) + 1));
197
+ const searchParams = ( new SearchParams('import\\s*pandas|from\\s*pandas', true, false, null));
198
+ const searchData = searchParams.parseSearchRequest();
199
+ if (!searchData) {
200
+ continue;
201
+ }
202
+ const cellMatches = cell.textBuffer.findMatchesLineByLine(range, searchData, true, 1);
203
+ if (cellMatches.length > 0) {
204
+ return true;
205
+ }
206
+ }
207
+ return false;
208
+ }
209
+ _getModel(uri) {
210
+ return this._models[uri];
211
+ }
212
+ }
213
+ function create(host) {
214
+ return ( new NotebookEditorSimpleWorker());
215
+ }
216
+
217
+ export { NotebookEditorSimpleWorker, create };
@@ -0,0 +1,89 @@
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, dispose } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
4
+ import { ResourceMap } from 'monaco-editor/esm/vs/base/common/map.js';
5
+ import { Promises } from 'monaco-editor/esm/vs/base/common/async.js';
6
+ import { IFileService } from 'monaco-editor/esm/vs/platform/files/common/files.js';
7
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
8
+ import { IWorkingCopyBackupService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyBackup';
9
+
10
+ let BaseFileWorkingCopyManager = class BaseFileWorkingCopyManager extends Disposable {
11
+ constructor(fileService, logService, workingCopyBackupService) {
12
+ super();
13
+ this.fileService = fileService;
14
+ this.logService = logService;
15
+ this.workingCopyBackupService = workingCopyBackupService;
16
+ this._onDidCreate = this._register(( new Emitter()));
17
+ this.onDidCreate = this._onDidCreate.event;
18
+ this.mapResourceToWorkingCopy = ( new ResourceMap());
19
+ this.mapResourceToDisposeListener = ( new ResourceMap());
20
+ }
21
+ has(resource) {
22
+ return ( this.mapResourceToWorkingCopy.has(resource));
23
+ }
24
+ add(resource, workingCopy) {
25
+ const knownWorkingCopy = this.get(resource);
26
+ if (knownWorkingCopy === workingCopy) {
27
+ return;
28
+ }
29
+ this.mapResourceToWorkingCopy.set(resource, workingCopy);
30
+ this.mapResourceToDisposeListener.get(resource)?.dispose();
31
+ this.mapResourceToDisposeListener.set(resource, workingCopy.onWillDispose(() => this.remove(resource)));
32
+ this._onDidCreate.fire(workingCopy);
33
+ }
34
+ remove(resource) {
35
+ const disposeListener = this.mapResourceToDisposeListener.get(resource);
36
+ if (disposeListener) {
37
+ dispose(disposeListener);
38
+ this.mapResourceToDisposeListener.delete(resource);
39
+ }
40
+ return this.mapResourceToWorkingCopy.delete(resource);
41
+ }
42
+ get workingCopies() {
43
+ return [...( this.mapResourceToWorkingCopy.values())];
44
+ }
45
+ get(resource) {
46
+ return this.mapResourceToWorkingCopy.get(resource);
47
+ }
48
+ dispose() {
49
+ super.dispose();
50
+ this.mapResourceToWorkingCopy.clear();
51
+ dispose(( this.mapResourceToDisposeListener.values()));
52
+ this.mapResourceToDisposeListener.clear();
53
+ }
54
+ async destroy() {
55
+ try {
56
+ await Promises.settled(( this.workingCopies.map(async (workingCopy) => {
57
+ if (workingCopy.isDirty()) {
58
+ await this.saveWithFallback(workingCopy);
59
+ }
60
+ })));
61
+ }
62
+ catch (error) {
63
+ this.logService.error(error);
64
+ }
65
+ dispose(( this.mapResourceToWorkingCopy.values()));
66
+ this.dispose();
67
+ }
68
+ async saveWithFallback(workingCopy) {
69
+ let saveSuccess = false;
70
+ try {
71
+ saveSuccess = await workingCopy.save();
72
+ }
73
+ catch (error) {
74
+ }
75
+ if (!saveSuccess || workingCopy.isDirty()) {
76
+ const backup = await this.workingCopyBackupService.resolve(workingCopy);
77
+ if (backup) {
78
+ await this.fileService.writeFile(workingCopy.resource, backup.value, { unlock: true });
79
+ }
80
+ }
81
+ }
82
+ };
83
+ BaseFileWorkingCopyManager = ( __decorate([
84
+ ( __param(0, IFileService)),
85
+ ( __param(1, ILogService)),
86
+ ( __param(2, IWorkingCopyBackupService))
87
+ ], BaseFileWorkingCopyManager));
88
+
89
+ export { BaseFileWorkingCopyManager };
@@ -0,0 +1,372 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
3
+ import { Event, Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
4
+ import { Promises } from 'monaco-editor/esm/vs/base/common/async.js';
5
+ import { CancellationToken } from 'monaco-editor/esm/vs/base/common/cancellation.js';
6
+ import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
7
+ import { isEqual, toLocalResource, basename, dirname, joinPath } from 'monaco-editor/esm/vs/base/common/resources.js';
8
+ import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
9
+ import '../../../../../../../override/vs/platform/dialogs/common/dialogs.js';
10
+ import { IFileService } from 'monaco-editor/esm/vs/platform/files/common/files.js';
11
+ import { SaveSourceRegistry } from 'vscode/vscode/vs/workbench/common/editor';
12
+ import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService';
13
+ import { IPathService } from 'vscode/vscode/vs/workbench/services/path/common/pathService';
14
+ import { IUriIdentityService } from 'monaco-editor/esm/vs/platform/uriIdentity/common/uriIdentity.js';
15
+ import { StoredFileWorkingCopyManager } from './storedFileWorkingCopyManager.js';
16
+ import { UntitledFileWorkingCopy } from './untitledFileWorkingCopy.js';
17
+ import { UntitledFileWorkingCopyManager } from './untitledFileWorkingCopyManager.js';
18
+ import { IWorkingCopyFileService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyFileService';
19
+ import { ILabelService } from 'monaco-editor/esm/vs/platform/label/common/label.js';
20
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
21
+ import { INotificationService } from 'monaco-editor/esm/vs/platform/notification/common/notification.js';
22
+ import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
23
+ import { IElevatedFileService } from 'vscode/vscode/vs/workbench/services/files/common/elevatedFileService';
24
+ import { IFilesConfigurationService } from 'vscode/vscode/vs/workbench/services/filesConfiguration/common/filesConfigurationService';
25
+ import { ILifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle';
26
+ import { IWorkingCopyBackupService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyBackup';
27
+ import { IWorkingCopyEditorService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyEditorService';
28
+ import { IWorkingCopyService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyService';
29
+ import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
30
+ import { IDecorationsService } from 'vscode/vscode/vs/workbench/services/decorations/common/decorations';
31
+ import { Codicon } from 'monaco-editor/esm/vs/base/common/codicons.js';
32
+ import { listErrorForeground } from 'monaco-editor/esm/vs/platform/theme/common/colorRegistry.js';
33
+ import { IFileDialogService, IDialogService } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
34
+
35
+ var FileWorkingCopyManager_1;
36
+ let FileWorkingCopyManager = class FileWorkingCopyManager extends Disposable {
37
+ static { FileWorkingCopyManager_1 = this; }
38
+ static { this.FILE_WORKING_COPY_SAVE_CREATE_SOURCE = SaveSourceRegistry.registerSource('fileWorkingCopyCreate.source', ( localizeWithPath(
39
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
40
+ 'fileWorkingCopyCreate.source',
41
+ "File Created"
42
+ ))); }
43
+ static { this.FILE_WORKING_COPY_SAVE_REPLACE_SOURCE = SaveSourceRegistry.registerSource('fileWorkingCopyReplace.source', ( localizeWithPath(
44
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
45
+ 'fileWorkingCopyReplace.source',
46
+ "File Replaced"
47
+ ))); }
48
+ constructor(workingCopyTypeId, storedWorkingCopyModelFactory, untitledWorkingCopyModelFactory, fileService, lifecycleService, labelService, logService, workingCopyFileService, workingCopyBackupService, uriIdentityService, fileDialogService, filesConfigurationService, workingCopyService, notificationService, workingCopyEditorService, editorService, elevatedFileService, pathService, environmentService, dialogService, decorationsService) {
49
+ super();
50
+ this.workingCopyTypeId = workingCopyTypeId;
51
+ this.storedWorkingCopyModelFactory = storedWorkingCopyModelFactory;
52
+ this.untitledWorkingCopyModelFactory = untitledWorkingCopyModelFactory;
53
+ this.fileService = fileService;
54
+ this.logService = logService;
55
+ this.workingCopyFileService = workingCopyFileService;
56
+ this.uriIdentityService = uriIdentityService;
57
+ this.fileDialogService = fileDialogService;
58
+ this.filesConfigurationService = filesConfigurationService;
59
+ this.pathService = pathService;
60
+ this.environmentService = environmentService;
61
+ this.dialogService = dialogService;
62
+ this.decorationsService = decorationsService;
63
+ this.stored = this._register(( new StoredFileWorkingCopyManager(
64
+ this.workingCopyTypeId,
65
+ this.storedWorkingCopyModelFactory,
66
+ fileService,
67
+ lifecycleService,
68
+ labelService,
69
+ logService,
70
+ workingCopyFileService,
71
+ workingCopyBackupService,
72
+ uriIdentityService,
73
+ filesConfigurationService,
74
+ workingCopyService,
75
+ notificationService,
76
+ workingCopyEditorService,
77
+ editorService,
78
+ elevatedFileService
79
+ )));
80
+ this.untitled = this._register(( new UntitledFileWorkingCopyManager(
81
+ this.workingCopyTypeId,
82
+ this.untitledWorkingCopyModelFactory,
83
+ async (workingCopy, options) => {
84
+ const result = await this.saveAs(workingCopy.resource, undefined, options);
85
+ return result ? true : false;
86
+ },
87
+ fileService,
88
+ labelService,
89
+ logService,
90
+ workingCopyBackupService,
91
+ workingCopyService
92
+ )));
93
+ this.onDidCreate = Event.any(this.stored.onDidCreate, this.untitled.onDidCreate);
94
+ this.provideDecorations();
95
+ }
96
+ provideDecorations() {
97
+ const provider = this._register(new (class extends Disposable {
98
+ constructor(stored) {
99
+ super();
100
+ this.stored = stored;
101
+ this.label = ( localizeWithPath(
102
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
103
+ 'fileWorkingCopyDecorations',
104
+ "File Working Copy Decorations"
105
+ ));
106
+ this._onDidChange = this._register(( new Emitter()));
107
+ this.onDidChange = this._onDidChange.event;
108
+ this.registerListeners();
109
+ }
110
+ registerListeners() {
111
+ this._register(this.stored.onDidResolve(workingCopy => {
112
+ if (workingCopy.isReadonly() || workingCopy.hasState(4 )) {
113
+ this._onDidChange.fire([workingCopy.resource]);
114
+ }
115
+ }));
116
+ this._register(this.stored.onDidRemove(workingCopyUri => this._onDidChange.fire([workingCopyUri])));
117
+ this._register(this.stored.onDidChangeReadonly(workingCopy => this._onDidChange.fire([workingCopy.resource])));
118
+ this._register(this.stored.onDidChangeOrphaned(workingCopy => this._onDidChange.fire([workingCopy.resource])));
119
+ }
120
+ provideDecorations(uri) {
121
+ const workingCopy = this.stored.get(uri);
122
+ if (!workingCopy || workingCopy.isDisposed()) {
123
+ return undefined;
124
+ }
125
+ const isReadonly = workingCopy.isReadonly();
126
+ const isOrphaned = workingCopy.hasState(4 );
127
+ if (isReadonly && isOrphaned) {
128
+ return {
129
+ color: listErrorForeground,
130
+ letter: Codicon.lockSmall,
131
+ strikethrough: true,
132
+ tooltip: ( localizeWithPath(
133
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
134
+ 'readonlyAndDeleted',
135
+ "Deleted, Read-only"
136
+ )),
137
+ };
138
+ }
139
+ else if (isReadonly) {
140
+ return {
141
+ letter: Codicon.lockSmall,
142
+ tooltip: ( localizeWithPath(
143
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
144
+ 'readonly',
145
+ "Read-only"
146
+ )),
147
+ };
148
+ }
149
+ else if (isOrphaned) {
150
+ return {
151
+ color: listErrorForeground,
152
+ strikethrough: true,
153
+ tooltip: ( localizeWithPath(
154
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
155
+ 'deleted',
156
+ "Deleted"
157
+ )),
158
+ };
159
+ }
160
+ return undefined;
161
+ }
162
+ })(this.stored));
163
+ this._register(this.decorationsService.registerDecorationsProvider(provider));
164
+ }
165
+ get workingCopies() {
166
+ return [...this.stored.workingCopies, ...this.untitled.workingCopies];
167
+ }
168
+ get(resource) {
169
+ return this.stored.get(resource) ?? this.untitled.get(resource);
170
+ }
171
+ resolve(arg1, arg2) {
172
+ if (URI.isUri(arg1)) {
173
+ if (arg1.scheme === Schemas.untitled) {
174
+ return this.untitled.resolve({ untitledResource: arg1 });
175
+ }
176
+ else {
177
+ return this.stored.resolve(arg1, arg2);
178
+ }
179
+ }
180
+ return this.untitled.resolve(arg1);
181
+ }
182
+ async saveAs(source, target, options) {
183
+ if (!target) {
184
+ const workingCopy = this.get(source);
185
+ if (workingCopy instanceof UntitledFileWorkingCopy && workingCopy.hasAssociatedFilePath) {
186
+ target = await this.suggestSavePath(source);
187
+ }
188
+ else {
189
+ target = await this.fileDialogService.pickFileToSave(await this.suggestSavePath(options?.suggestedTarget ?? source), options?.availableFileSystems);
190
+ }
191
+ }
192
+ if (!target) {
193
+ return;
194
+ }
195
+ if (this.filesConfigurationService.isReadonly(target)) {
196
+ const confirmed = await this.confirmMakeWriteable(target);
197
+ if (!confirmed) {
198
+ return;
199
+ }
200
+ else {
201
+ this.filesConfigurationService.updateReadonly(target, false);
202
+ }
203
+ }
204
+ if (this.fileService.hasProvider(source) && isEqual(source, target)) {
205
+ return this.doSave(source, { ...options, force: true });
206
+ }
207
+ if (this.fileService.hasProvider(source) && this.uriIdentityService.extUri.isEqual(source, target) && (await this.fileService.exists(source))) {
208
+ await this.workingCopyFileService.move([{ file: { source, target } }], CancellationToken.None);
209
+ return (await this.doSave(source, options)) ?? (await this.doSave(target, options));
210
+ }
211
+ return this.doSaveAs(source, target, options);
212
+ }
213
+ async doSave(resource, options) {
214
+ const storedFileWorkingCopy = this.stored.get(resource);
215
+ if (storedFileWorkingCopy) {
216
+ const success = await storedFileWorkingCopy.save(options);
217
+ if (success) {
218
+ return storedFileWorkingCopy;
219
+ }
220
+ }
221
+ return undefined;
222
+ }
223
+ async doSaveAs(source, target, options) {
224
+ let sourceContents;
225
+ const sourceWorkingCopy = this.get(source);
226
+ if (sourceWorkingCopy?.isResolved()) {
227
+ sourceContents = await sourceWorkingCopy.model.snapshot(CancellationToken.None);
228
+ }
229
+ else {
230
+ sourceContents = (await this.fileService.readFileStream(source)).value;
231
+ }
232
+ const { targetFileExists, targetStoredFileWorkingCopy } = await this.doResolveSaveTarget(source, target);
233
+ if (sourceWorkingCopy instanceof UntitledFileWorkingCopy &&
234
+ sourceWorkingCopy.hasAssociatedFilePath &&
235
+ targetFileExists &&
236
+ this.uriIdentityService.extUri.isEqual(target, toLocalResource(sourceWorkingCopy.resource, this.environmentService.remoteAuthority, this.pathService.defaultUriScheme))) {
237
+ const overwrite = await this.confirmOverwrite(target);
238
+ if (!overwrite) {
239
+ return undefined;
240
+ }
241
+ }
242
+ await targetStoredFileWorkingCopy.model?.update(sourceContents, CancellationToken.None);
243
+ if (!options?.source) {
244
+ options = {
245
+ ...options,
246
+ source: targetFileExists ? FileWorkingCopyManager_1.FILE_WORKING_COPY_SAVE_REPLACE_SOURCE : FileWorkingCopyManager_1.FILE_WORKING_COPY_SAVE_CREATE_SOURCE
247
+ };
248
+ }
249
+ const success = await targetStoredFileWorkingCopy.save({ ...options, force: true });
250
+ if (!success) {
251
+ return undefined;
252
+ }
253
+ try {
254
+ await sourceWorkingCopy?.revert();
255
+ }
256
+ catch (error) {
257
+ this.logService.error(error);
258
+ }
259
+ return targetStoredFileWorkingCopy;
260
+ }
261
+ async doResolveSaveTarget(source, target) {
262
+ let targetFileExists = false;
263
+ let targetStoredFileWorkingCopy = this.stored.get(target);
264
+ if (targetStoredFileWorkingCopy?.isResolved()) {
265
+ targetFileExists = true;
266
+ }
267
+ else {
268
+ targetFileExists = await this.fileService.exists(target);
269
+ if (!targetFileExists) {
270
+ await this.workingCopyFileService.create([{ resource: target }], CancellationToken.None);
271
+ }
272
+ if (this.uriIdentityService.extUri.isEqual(source, target) && this.get(source)) {
273
+ targetStoredFileWorkingCopy = await this.stored.resolve(source);
274
+ }
275
+ else {
276
+ targetStoredFileWorkingCopy = await this.stored.resolve(target);
277
+ }
278
+ }
279
+ return { targetFileExists, targetStoredFileWorkingCopy };
280
+ }
281
+ async confirmOverwrite(resource) {
282
+ const { confirmed } = await this.dialogService.confirm({
283
+ type: 'warning',
284
+ message: ( localizeWithPath(
285
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
286
+ 'confirmOverwrite',
287
+ "'{0}' already exists. Do you want to replace it?",
288
+ basename(resource)
289
+ )),
290
+ detail: ( localizeWithPath(
291
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
292
+ 'overwriteIrreversible',
293
+ "A file or folder with the name '{0}' already exists in the folder '{1}'. Replacing it will overwrite its current contents.",
294
+ basename(resource),
295
+ basename(dirname(resource))
296
+ )),
297
+ primaryButton: ( localizeWithPath(
298
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
299
+ { key: 'replaceButtonLabel', comment: ['&& denotes a mnemonic'] },
300
+ "&&Replace"
301
+ ))
302
+ });
303
+ return confirmed;
304
+ }
305
+ async confirmMakeWriteable(resource) {
306
+ const { confirmed } = await this.dialogService.confirm({
307
+ type: 'warning',
308
+ message: ( localizeWithPath(
309
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
310
+ 'confirmMakeWriteable',
311
+ "'{0}' is marked as read-only. Do you want to save anyway?",
312
+ basename(resource)
313
+ )),
314
+ detail: ( localizeWithPath(
315
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
316
+ 'confirmMakeWriteableDetail',
317
+ "Paths can be configured as read-only via settings."
318
+ )),
319
+ primaryButton: ( localizeWithPath(
320
+ 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager',
321
+ { key: 'makeWriteableButtonLabel', comment: ['&& denotes a mnemonic'] },
322
+ "&&Save Anyway"
323
+ ))
324
+ });
325
+ return confirmed;
326
+ }
327
+ async suggestSavePath(resource) {
328
+ if (this.fileService.hasProvider(resource)) {
329
+ return resource;
330
+ }
331
+ const workingCopy = this.get(resource);
332
+ if (workingCopy instanceof UntitledFileWorkingCopy && workingCopy.hasAssociatedFilePath) {
333
+ return toLocalResource(resource, this.environmentService.remoteAuthority, this.pathService.defaultUriScheme);
334
+ }
335
+ const defaultFilePath = await this.fileDialogService.defaultFilePath();
336
+ if (workingCopy) {
337
+ const candidatePath = joinPath(defaultFilePath, workingCopy.name);
338
+ if (await this.pathService.hasValidBasename(candidatePath, workingCopy.name)) {
339
+ return candidatePath;
340
+ }
341
+ }
342
+ return joinPath(defaultFilePath, basename(resource));
343
+ }
344
+ async destroy() {
345
+ await Promises.settled([
346
+ this.stored.destroy(),
347
+ this.untitled.destroy()
348
+ ]);
349
+ }
350
+ };
351
+ FileWorkingCopyManager = FileWorkingCopyManager_1 = ( __decorate([
352
+ ( __param(3, IFileService)),
353
+ ( __param(4, ILifecycleService)),
354
+ ( __param(5, ILabelService)),
355
+ ( __param(6, ILogService)),
356
+ ( __param(7, IWorkingCopyFileService)),
357
+ ( __param(8, IWorkingCopyBackupService)),
358
+ ( __param(9, IUriIdentityService)),
359
+ ( __param(10, IFileDialogService)),
360
+ ( __param(11, IFilesConfigurationService)),
361
+ ( __param(12, IWorkingCopyService)),
362
+ ( __param(13, INotificationService)),
363
+ ( __param(14, IWorkingCopyEditorService)),
364
+ ( __param(15, IEditorService)),
365
+ ( __param(16, IElevatedFileService)),
366
+ ( __param(17, IPathService)),
367
+ ( __param(18, IWorkbenchEnvironmentService)),
368
+ ( __param(19, IDialogService)),
369
+ ( __param(20, IDecorationsService))
370
+ ], FileWorkingCopyManager));
371
+
372
+ export { FileWorkingCopyManager };