@codingame/monaco-vscode-files-service-override 3.2.3 → 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.
@@ -1,404 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
3
- import { toErrorMessage } from 'vscode/vscode/vs/base/common/errorMessage';
4
- import { Emitter, Event } from 'vscode/vscode/vs/base/common/event';
5
- import { URI } from 'vscode/vscode/vs/base/common/uri';
6
- import { TextFileEditorModel } from 'vscode/vscode/vs/workbench/services/textfile/common/textFileEditorModel';
7
- import { Disposable, DisposableStore, dispose } from 'vscode/vscode/vs/base/common/lifecycle';
8
- import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
9
- import { ResourceMap } from 'vscode/vscode/vs/base/common/map';
10
- import { IFileService } from 'vscode/vscode/vs/platform/files/common/files';
11
- import { ResourceQueue, Promises } from 'vscode/vscode/vs/base/common/async';
12
- import { onUnexpectedError } from 'vscode/vscode/vs/base/common/errors';
13
- import { TextFileSaveParticipant } from './textFileSaveParticipant.js';
14
- import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification';
15
- import { IWorkingCopyFileService } from 'vscode/vscode/vs/workbench/services/workingCopy/common/workingCopyFileService';
16
- import { joinPath, extname } from 'vscode/vscode/vs/base/common/resources';
17
- import { createTextBufferFactoryFromSnapshot } from 'vscode/vscode/vs/editor/common/model/textModel';
18
- import { PLAINTEXT_LANGUAGE_ID, PLAINTEXT_EXTENSION } from 'vscode/vscode/vs/editor/common/languages/modesRegistry';
19
- import { IUriIdentityService } from 'vscode/vscode/vs/platform/uriIdentity/common/uriIdentity';
20
-
21
- let TextFileEditorModelManager = class TextFileEditorModelManager extends Disposable {
22
- get models() {
23
- return [...( this.mapResourceToModel.values())];
24
- }
25
- constructor(instantiationService, fileService, notificationService, workingCopyFileService, uriIdentityService) {
26
- super();
27
- this.instantiationService = instantiationService;
28
- this.fileService = fileService;
29
- this.notificationService = notificationService;
30
- this.workingCopyFileService = workingCopyFileService;
31
- this.uriIdentityService = uriIdentityService;
32
- this._onDidCreate = this._register(( new Emitter()));
33
- this.onDidCreate = this._onDidCreate.event;
34
- this._onDidResolve = this._register(( new Emitter()));
35
- this.onDidResolve = this._onDidResolve.event;
36
- this._onDidRemove = this._register(( new Emitter()));
37
- this.onDidRemove = this._onDidRemove.event;
38
- this._onDidChangeDirty = this._register(( new Emitter()));
39
- this.onDidChangeDirty = this._onDidChangeDirty.event;
40
- this._onDidChangeReadonly = this._register(( new Emitter()));
41
- this.onDidChangeReadonly = this._onDidChangeReadonly.event;
42
- this._onDidChangeOrphaned = this._register(( new Emitter()));
43
- this.onDidChangeOrphaned = this._onDidChangeOrphaned.event;
44
- this._onDidSaveError = this._register(( new Emitter()));
45
- this.onDidSaveError = this._onDidSaveError.event;
46
- this._onDidSave = this._register(( new Emitter()));
47
- this.onDidSave = this._onDidSave.event;
48
- this._onDidRevert = this._register(( new Emitter()));
49
- this.onDidRevert = this._onDidRevert.event;
50
- this._onDidChangeEncoding = this._register(( new Emitter()));
51
- this.onDidChangeEncoding = this._onDidChangeEncoding.event;
52
- this.mapResourceToModel = ( new ResourceMap());
53
- this.mapResourceToModelListeners = ( new ResourceMap());
54
- this.mapResourceToDisposeListener = ( new ResourceMap());
55
- this.mapResourceToPendingModelResolvers = ( new ResourceMap());
56
- this.modelResolveQueue = this._register(( new ResourceQueue()));
57
- this.saveErrorHandler = (() => {
58
- const notificationService = this.notificationService;
59
- return {
60
- onSaveError(error, model) {
61
- notificationService.error(( localizeWithPath(
62
- 'vs/workbench/services/textfile/common/textFileEditorModelManager',
63
- { key: 'genericSaveError', comment: ['{0} is the resource that failed to save and {1} the error message'] },
64
- "Failed to save '{0}': {1}",
65
- model.name,
66
- toErrorMessage(error, false)
67
- )));
68
- }
69
- };
70
- })();
71
- this.mapCorrelationIdToModelsToRestore = ( new Map());
72
- this.saveParticipants = this._register(this.instantiationService.createInstance(TextFileSaveParticipant));
73
- this.registerListeners();
74
- }
75
- registerListeners() {
76
- this._register(this.fileService.onDidFilesChange(e => this.onDidFilesChange(e)));
77
- this._register(this.fileService.onDidChangeFileSystemProviderCapabilities(e => this.onDidChangeFileSystemProviderCapabilities(e)));
78
- this._register(this.fileService.onDidChangeFileSystemProviderRegistrations(e => this.onDidChangeFileSystemProviderRegistrations(e)));
79
- this._register(this.workingCopyFileService.onWillRunWorkingCopyFileOperation(e => this.onWillRunWorkingCopyFileOperation(e)));
80
- this._register(this.workingCopyFileService.onDidFailWorkingCopyFileOperation(e => this.onDidFailWorkingCopyFileOperation(e)));
81
- this._register(this.workingCopyFileService.onDidRunWorkingCopyFileOperation(e => this.onDidRunWorkingCopyFileOperation(e)));
82
- }
83
- onDidFilesChange(e) {
84
- for (const model of this.models) {
85
- if (model.isDirty()) {
86
- continue;
87
- }
88
- if (e.contains(model.resource, 0 , 1 )) {
89
- this.queueModelReload(model);
90
- }
91
- }
92
- }
93
- onDidChangeFileSystemProviderCapabilities(e) {
94
- this.queueModelReloads(e.scheme);
95
- }
96
- onDidChangeFileSystemProviderRegistrations(e) {
97
- if (!e.added) {
98
- return;
99
- }
100
- this.queueModelReloads(e.scheme);
101
- }
102
- queueModelReloads(scheme) {
103
- for (const model of this.models) {
104
- if (model.isDirty()) {
105
- continue;
106
- }
107
- if (scheme === model.resource.scheme) {
108
- this.queueModelReload(model);
109
- }
110
- }
111
- }
112
- queueModelReload(model) {
113
- const queueSize = this.modelResolveQueue.queueSize(model.resource);
114
- if (queueSize <= 1) {
115
- this.modelResolveQueue.queueFor(model.resource, async () => {
116
- try {
117
- await this.reload(model);
118
- }
119
- catch (error) {
120
- onUnexpectedError(error);
121
- }
122
- });
123
- }
124
- }
125
- onWillRunWorkingCopyFileOperation(e) {
126
- if (e.operation === 2 || e.operation === 3 ) {
127
- const modelsToRestore = [];
128
- for (const { source, target } of e.files) {
129
- if (source) {
130
- if (this.uriIdentityService.extUri.isEqual(source, target)) {
131
- continue;
132
- }
133
- const sourceModels = [];
134
- for (const model of this.models) {
135
- if (this.uriIdentityService.extUri.isEqualOrParent(model.resource, source)) {
136
- sourceModels.push(model);
137
- }
138
- }
139
- for (const sourceModel of sourceModels) {
140
- const sourceModelResource = sourceModel.resource;
141
- let targetModelResource;
142
- if (this.uriIdentityService.extUri.isEqual(sourceModelResource, source)) {
143
- targetModelResource = target;
144
- }
145
- else {
146
- targetModelResource = joinPath(target, sourceModelResource.path.substr(source.path.length + 1));
147
- }
148
- modelsToRestore.push({
149
- source: sourceModelResource,
150
- target: targetModelResource,
151
- languageId: sourceModel.getLanguageId(),
152
- encoding: sourceModel.getEncoding(),
153
- snapshot: sourceModel.isDirty() ? sourceModel.createSnapshot() : undefined
154
- });
155
- }
156
- }
157
- }
158
- this.mapCorrelationIdToModelsToRestore.set(e.correlationId, modelsToRestore);
159
- }
160
- }
161
- onDidFailWorkingCopyFileOperation(e) {
162
- if (((e.operation === 2 || e.operation === 3) )) {
163
- const modelsToRestore = this.mapCorrelationIdToModelsToRestore.get(e.correlationId);
164
- if (modelsToRestore) {
165
- this.mapCorrelationIdToModelsToRestore.delete(e.correlationId);
166
- modelsToRestore.forEach(model => {
167
- if (model.snapshot) {
168
- this.get(model.source)?.setDirty(true);
169
- }
170
- });
171
- }
172
- }
173
- }
174
- onDidRunWorkingCopyFileOperation(e) {
175
- switch (e.operation) {
176
- case 0 :
177
- e.waitUntil((async () => {
178
- for (const { target } of e.files) {
179
- const model = this.get(target);
180
- if (model && !model.isDisposed()) {
181
- await model.revert();
182
- }
183
- }
184
- })());
185
- break;
186
- case 2 :
187
- case 3 :
188
- e.waitUntil((async () => {
189
- const modelsToRestore = this.mapCorrelationIdToModelsToRestore.get(e.correlationId);
190
- if (modelsToRestore) {
191
- this.mapCorrelationIdToModelsToRestore.delete(e.correlationId);
192
- await Promises.settled(( modelsToRestore.map(async (modelToRestore) => {
193
- const restoredModel = await this.resolve(modelToRestore.target, {
194
- reload: { async: false },
195
- contents: modelToRestore.snapshot ? createTextBufferFactoryFromSnapshot(modelToRestore.snapshot) : undefined,
196
- encoding: modelToRestore.encoding
197
- });
198
- if (modelToRestore.languageId &&
199
- modelToRestore.languageId !== PLAINTEXT_LANGUAGE_ID &&
200
- restoredModel.getLanguageId() === PLAINTEXT_LANGUAGE_ID &&
201
- extname(modelToRestore.target) !== PLAINTEXT_EXTENSION) {
202
- restoredModel.updateTextEditorModel(undefined, modelToRestore.languageId);
203
- }
204
- })));
205
- }
206
- })());
207
- break;
208
- }
209
- }
210
- get(resource) {
211
- return this.mapResourceToModel.get(resource);
212
- }
213
- has(resource) {
214
- return ( this.mapResourceToModel.has(resource));
215
- }
216
- async reload(model) {
217
- await this.joinPendingResolves(model.resource);
218
- if (model.isDirty() || model.isDisposed() || !( this.has(model.resource))) {
219
- return;
220
- }
221
- await this.doResolve(model, { reload: { async: false } });
222
- }
223
- async resolve(resource, options) {
224
- const pendingResolve = this.joinPendingResolves(resource);
225
- if (pendingResolve) {
226
- await pendingResolve;
227
- }
228
- return this.doResolve(resource, options);
229
- }
230
- async doResolve(resourceOrModel, options) {
231
- let model;
232
- let resource;
233
- if (URI.isUri(resourceOrModel)) {
234
- resource = resourceOrModel;
235
- model = this.get(resource);
236
- }
237
- else {
238
- resource = resourceOrModel.resource;
239
- model = resourceOrModel;
240
- }
241
- let modelResolve;
242
- let didCreateModel = false;
243
- if (model) {
244
- if (options?.contents) {
245
- modelResolve = model.resolve(options);
246
- }
247
- else if (options?.reload) {
248
- if (options.reload.async) {
249
- modelResolve = Promise.resolve();
250
- (async () => {
251
- try {
252
- await model.resolve(options);
253
- }
254
- catch (error) {
255
- onUnexpectedError(error);
256
- }
257
- })();
258
- }
259
- else {
260
- modelResolve = model.resolve(options);
261
- }
262
- }
263
- else {
264
- modelResolve = Promise.resolve();
265
- }
266
- }
267
- else {
268
- didCreateModel = true;
269
- const newModel = model = this.instantiationService.createInstance(TextFileEditorModel, resource, options ? options.encoding : undefined, options ? options.languageId : undefined);
270
- modelResolve = model.resolve(options);
271
- this.registerModel(newModel);
272
- }
273
- this.mapResourceToPendingModelResolvers.set(resource, modelResolve);
274
- this.add(resource, model);
275
- if (didCreateModel) {
276
- this._onDidCreate.fire(model);
277
- if (model.isDirty()) {
278
- this._onDidChangeDirty.fire(model);
279
- }
280
- }
281
- try {
282
- await modelResolve;
283
- }
284
- catch (error) {
285
- if (didCreateModel) {
286
- model.dispose();
287
- }
288
- throw error;
289
- }
290
- finally {
291
- this.mapResourceToPendingModelResolvers.delete(resource);
292
- }
293
- if (options?.languageId) {
294
- model.setLanguageId(options.languageId);
295
- }
296
- if (didCreateModel && model.isDirty()) {
297
- this._onDidChangeDirty.fire(model);
298
- }
299
- return model;
300
- }
301
- joinPendingResolves(resource) {
302
- const pendingModelResolve = this.mapResourceToPendingModelResolvers.get(resource);
303
- if (!pendingModelResolve) {
304
- return;
305
- }
306
- return this.doJoinPendingResolves(resource);
307
- }
308
- async doJoinPendingResolves(resource) {
309
- let currentModelCopyResolve;
310
- while (( this.mapResourceToPendingModelResolvers.has(resource))) {
311
- const nextPendingModelResolve = this.mapResourceToPendingModelResolvers.get(resource);
312
- if (nextPendingModelResolve === currentModelCopyResolve) {
313
- return;
314
- }
315
- currentModelCopyResolve = nextPendingModelResolve;
316
- try {
317
- await nextPendingModelResolve;
318
- }
319
- catch (error) {
320
- }
321
- }
322
- }
323
- registerModel(model) {
324
- const modelListeners = ( new DisposableStore());
325
- modelListeners.add(model.onDidResolve(reason => this._onDidResolve.fire({ model, reason })));
326
- modelListeners.add(model.onDidChangeDirty(() => this._onDidChangeDirty.fire(model)));
327
- modelListeners.add(model.onDidChangeReadonly(() => this._onDidChangeReadonly.fire(model)));
328
- modelListeners.add(model.onDidChangeOrphaned(() => this._onDidChangeOrphaned.fire(model)));
329
- modelListeners.add(model.onDidSaveError(() => this._onDidSaveError.fire(model)));
330
- modelListeners.add(model.onDidSave(e => this._onDidSave.fire({ model, ...e })));
331
- modelListeners.add(model.onDidRevert(() => this._onDidRevert.fire(model)));
332
- modelListeners.add(model.onDidChangeEncoding(() => this._onDidChangeEncoding.fire(model)));
333
- this.mapResourceToModelListeners.set(model.resource, modelListeners);
334
- }
335
- add(resource, model) {
336
- const knownModel = this.mapResourceToModel.get(resource);
337
- if (knownModel === model) {
338
- return;
339
- }
340
- const disposeListener = this.mapResourceToDisposeListener.get(resource);
341
- disposeListener?.dispose();
342
- this.mapResourceToModel.set(resource, model);
343
- this.mapResourceToDisposeListener.set(resource, model.onWillDispose(() => this.remove(resource)));
344
- }
345
- remove(resource) {
346
- const removed = this.mapResourceToModel.delete(resource);
347
- const disposeListener = this.mapResourceToDisposeListener.get(resource);
348
- if (disposeListener) {
349
- dispose(disposeListener);
350
- this.mapResourceToDisposeListener.delete(resource);
351
- }
352
- const modelListener = this.mapResourceToModelListeners.get(resource);
353
- if (modelListener) {
354
- dispose(modelListener);
355
- this.mapResourceToModelListeners.delete(resource);
356
- }
357
- if (removed) {
358
- this._onDidRemove.fire(resource);
359
- }
360
- }
361
- addSaveParticipant(participant) {
362
- return this.saveParticipants.addSaveParticipant(participant);
363
- }
364
- runSaveParticipants(model, context, token) {
365
- return this.saveParticipants.participate(model, context, token);
366
- }
367
- canDispose(model) {
368
- if (model.isDisposed() ||
369
- (!( this.mapResourceToPendingModelResolvers.has(model.resource)) && !model.isDirty())) {
370
- return true;
371
- }
372
- return this.doCanDispose(model);
373
- }
374
- async doCanDispose(model) {
375
- const pendingResolve = this.joinPendingResolves(model.resource);
376
- if (pendingResolve) {
377
- await pendingResolve;
378
- return this.canDispose(model);
379
- }
380
- if (model.isDirty()) {
381
- await Event.toPromise(model.onDidChangeDirty);
382
- return this.canDispose(model);
383
- }
384
- return true;
385
- }
386
- dispose() {
387
- super.dispose();
388
- this.mapResourceToModel.clear();
389
- this.mapResourceToPendingModelResolvers.clear();
390
- dispose(( this.mapResourceToDisposeListener.values()));
391
- this.mapResourceToDisposeListener.clear();
392
- dispose(( this.mapResourceToModelListeners.values()));
393
- this.mapResourceToModelListeners.clear();
394
- }
395
- };
396
- TextFileEditorModelManager = ( __decorate([
397
- ( __param(0, IInstantiationService)),
398
- ( __param(1, IFileService)),
399
- ( __param(2, INotificationService)),
400
- ( __param(3, IWorkingCopyFileService)),
401
- ( __param(4, IUriIdentityService))
402
- ], TextFileEditorModelManager));
403
-
404
- export { TextFileEditorModelManager };
@@ -1,64 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
3
- import { raceCancellation } from 'vscode/vscode/vs/base/common/async';
4
- import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
5
- import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
6
- import { IProgressService } from 'vscode/vscode/vs/platform/progress/common/progress';
7
- import { Disposable, toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
8
- import { insert } from 'vscode/vscode/vs/base/common/arrays';
9
-
10
- let TextFileSaveParticipant = class TextFileSaveParticipant extends Disposable {
11
- constructor(progressService, logService) {
12
- super();
13
- this.progressService = progressService;
14
- this.logService = logService;
15
- this.saveParticipants = [];
16
- }
17
- addSaveParticipant(participant) {
18
- const remove = insert(this.saveParticipants, participant);
19
- return toDisposable(() => remove());
20
- }
21
- participate(model, context, token) {
22
- const cts = ( new CancellationTokenSource(token));
23
- return this.progressService.withProgress({
24
- title: ( localizeWithPath(
25
- 'vs/workbench/services/textfile/common/textFileSaveParticipant',
26
- 'saveParticipants',
27
- "Saving '{0}'",
28
- model.name
29
- )),
30
- location: 15 ,
31
- cancellable: true,
32
- delay: model.isDirty() ? 3000 : 5000
33
- }, async (progress) => {
34
- model.textEditorModel?.pushStackElement();
35
- for (const saveParticipant of this.saveParticipants) {
36
- if (cts.token.isCancellationRequested || !model.textEditorModel ) {
37
- break;
38
- }
39
- try {
40
- const promise = saveParticipant.participate(model, context, progress, cts.token);
41
- await raceCancellation(promise, cts.token);
42
- }
43
- catch (err) {
44
- this.logService.error(err);
45
- }
46
- }
47
- model.textEditorModel?.pushStackElement();
48
- }, () => {
49
- cts.cancel();
50
- }).finally(() => {
51
- cts.dispose();
52
- });
53
- }
54
- dispose() {
55
- this.saveParticipants.splice(0, this.saveParticipants.length);
56
- super.dispose();
57
- }
58
- };
59
- TextFileSaveParticipant = ( __decorate([
60
- ( __param(0, IProgressService)),
61
- ( __param(1, ILogService))
62
- ], TextFileSaveParticipant));
63
-
64
- export { TextFileSaveParticipant };