@codingame/monaco-vscode-api 1.67.7 → 1.67.9

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.
@@ -0,0 +1,747 @@
1
+ import { createDecorator, IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
2
+ import { IEnvironmentService } from 'monaco-editor/esm/vs/platform/environment/common/environment.js';
3
+ import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
4
+ import { isWindows, OS } from 'monaco-editor/esm/vs/base/common/platform.js';
5
+ import { IWorkspaceContextService } from 'monaco-editor/esm/vs/platform/workspace/common/workspace.js';
6
+ import { basename } from 'monaco-editor/esm/vs/base/common/resources.js';
7
+ import { win32, posix } from 'monaco-editor/esm/vs/base/common/path.js';
8
+ import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
9
+ import { DisposableStore, SafeDisposable, Disposable, toDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
10
+ import { LinkedList } from 'monaco-editor/esm/vs/base/common/linkedList.js';
11
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
12
+ import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
13
+ import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js';
14
+ import { localize } from 'monaco-editor/esm/vs/nls.js';
15
+ import { raceCancellation, Promises } from 'monaco-editor/esm/vs/base/common/async.js';
16
+ import { onUnexpectedError } from 'monaco-editor/esm/vs/base/common/errors.js';
17
+ import { StopWatch } from 'monaco-editor/esm/vs/base/common/stopwatch.js';
18
+ import { CancellationToken } from 'monaco-editor/esm/vs/base/common/cancellation.js';
19
+ import 'monaco-editor/esm/vs/editor/standalone/browser/standaloneServices.js';
20
+ import 'monaco-editor/esm/vs/platform/commands/common/commands.js';
21
+ import 'monaco-editor/esm/vs/platform/notification/common/notification.js';
22
+ import 'monaco-editor/esm/vs/editor/browser/services/bulkEditService.js';
23
+ import 'monaco-editor/esm/vs/editor/browser/services/codeEditorService.js';
24
+ import 'monaco-editor/esm/vs/editor/common/languages/language.js';
25
+ import 'monaco-editor/esm/vs/editor/common/languages/languageConfigurationRegistry.js';
26
+ import 'monaco-editor/esm/vs/editor/common/services/editorWorker.js';
27
+ import 'monaco-editor/esm/vs/editor/common/services/languageFeatures.js';
28
+ import 'monaco-editor/esm/vs/editor/common/services/model.js';
29
+ import 'monaco-editor/esm/vs/editor/common/services/resolverService.js';
30
+ import 'monaco-editor/esm/vs/platform/clipboard/common/clipboardService.js';
31
+ import 'monaco-editor/esm/vs/platform/dialogs/common/dialogs.js';
32
+ import 'monaco-editor/esm/vs/platform/markers/common/markers.js';
33
+ import 'monaco-editor/esm/vs/platform/opener/common/opener.js';
34
+ import 'monaco-editor/esm/vs/platform/quickinput/common/quickInput.js';
35
+ import 'monaco-editor/esm/vs/platform/telemetry/common/telemetry.js';
36
+ import 'monaco-editor/esm/vs/base/common/severity.js';
37
+ function readonly(name) {
38
+ return name
39
+ ? new Error(`readonly property '${name} cannot be changed'`)
40
+ : new Error('readonly property cannot be changed');
41
+ }
42
+ function disposed(what) {
43
+ const result = new Error(`${what} has been disposed`);
44
+ result.name = 'DISPOSED';
45
+ return result;
46
+ }
47
+ class ErrorNoTelemetry extends Error {
48
+ constructor() {
49
+ super(...arguments);
50
+ this.logTelemetry = false;
51
+ }
52
+ }
53
+ class EventProfiling {
54
+ constructor(name) {
55
+ this._listenerCount = 0;
56
+ this._invocationCount = 0;
57
+ this._elapsedOverall = 0;
58
+ this._name = `${name}_${EventProfiling._idPool++}`;
59
+ }
60
+ start(listenerCount) {
61
+ this._stopWatch = new StopWatch(true);
62
+ this._listenerCount = listenerCount;
63
+ }
64
+ stop() {
65
+ if (this._stopWatch) {
66
+ const elapsed = this._stopWatch.elapsed();
67
+ this._elapsedOverall += elapsed;
68
+ this._invocationCount += 1;
69
+ console.info(`did FIRE ${this._name}: elapsed_ms: ${elapsed.toFixed(5)}, listener: ${this._listenerCount} (elapsed_overall: ${this._elapsedOverall.toFixed(2)}, invocations: ${this._invocationCount})`);
70
+ this._stopWatch = undefined;
71
+ }
72
+ }
73
+ }
74
+ EventProfiling._idPool = 0;
75
+ class Stacktrace {
76
+ constructor(value) {
77
+ this.value = value;
78
+ }
79
+ static create() {
80
+ return (
81
+ new Stacktrace( new Error().stack ?? '')
82
+ );
83
+ }
84
+ print() {
85
+ console.warn(this.value.split('\n').slice(2).join('\n'));
86
+ }
87
+ }
88
+ class Listener {
89
+ constructor(callback, callbackThis, stack) {
90
+ this.callback = callback;
91
+ this.callbackThis = callbackThis;
92
+ this.stack = stack;
93
+ this.subscription = new SafeDisposable();
94
+ }
95
+ invoke(e) {
96
+ this.callback.call(this.callbackThis, e);
97
+ }
98
+ }
99
+ class Emitter {
100
+ constructor(options) {
101
+ this._disposed = false;
102
+ this._options = options;
103
+ this._leakageMon = undefined;
104
+ this._perfMon = this._options?._profName ? new EventProfiling(this._options._profName) : undefined;
105
+ }
106
+ dispose() {
107
+ if (!this._disposed) {
108
+ this._disposed = true;
109
+ if (this._listeners) {
110
+ this._listeners.clear();
111
+ }
112
+ this._deliveryQueue?.clear();
113
+ this._options?.onLastListenerRemove?.();
114
+ this._leakageMon?.dispose();
115
+ }
116
+ }
117
+ get event() {
118
+ if (!this._event) {
119
+ this._event = (callback, thisArgs, disposables) => {
120
+ if (!this._listeners) {
121
+ this._listeners = new LinkedList();
122
+ }
123
+ const firstListener = this._listeners.isEmpty();
124
+ if (firstListener && this._options?.onFirstListenerAdd) {
125
+ this._options.onFirstListenerAdd(this);
126
+ }
127
+ let removeMonitor;
128
+ let stack;
129
+ if (this._leakageMon && this._listeners.size >= 30) {
130
+ stack = Stacktrace.create();
131
+ removeMonitor = this._leakageMon.check(stack, this._listeners.size + 1);
132
+ }
133
+ const listener = new Listener(callback, thisArgs, stack);
134
+ const removeListener = this._listeners.push(listener);
135
+ if (firstListener && this._options?.onFirstListenerDidAdd) {
136
+ this._options.onFirstListenerDidAdd(this);
137
+ }
138
+ if (this._options?.onListenerDidAdd) {
139
+ this._options.onListenerDidAdd(this, callback, thisArgs);
140
+ }
141
+ const result = listener.subscription.set(() => {
142
+ if (removeMonitor) {
143
+ removeMonitor();
144
+ }
145
+ if (!this._disposed) {
146
+ removeListener();
147
+ if (this._options && this._options.onLastListenerRemove) {
148
+ const hasListeners = (this._listeners && !this._listeners.isEmpty());
149
+ if (!hasListeners) {
150
+ this._options.onLastListenerRemove(this);
151
+ }
152
+ }
153
+ }
154
+ });
155
+ if (disposables instanceof DisposableStore) {
156
+ disposables.add(result);
157
+ }
158
+ else if (Array.isArray(disposables)) {
159
+ disposables.push(result);
160
+ }
161
+ return result;
162
+ };
163
+ }
164
+ return this._event;
165
+ }
166
+ fire(event) {
167
+ if (this._listeners) {
168
+ if (!this._deliveryQueue) {
169
+ this._deliveryQueue = new LinkedList();
170
+ }
171
+ for (let listener of this._listeners) {
172
+ this._deliveryQueue.push([listener, event]);
173
+ }
174
+ this._perfMon?.start(this._deliveryQueue.size);
175
+ while (this._deliveryQueue.size > 0) {
176
+ const [listener, event] = this._deliveryQueue.shift();
177
+ try {
178
+ listener.invoke(event);
179
+ }
180
+ catch (e) {
181
+ onUnexpectedError(e);
182
+ }
183
+ }
184
+ this._perfMon?.stop();
185
+ }
186
+ }
187
+ hasListeners() {
188
+ if (!this._listeners) {
189
+ return false;
190
+ }
191
+ return (!this._listeners.isEmpty());
192
+ }
193
+ }
194
+ class AsyncEmitter extends Emitter {
195
+ async fireAsync(data, token, promiseJoin) {
196
+ if (!this._listeners) {
197
+ return;
198
+ }
199
+ if (!this._asyncDeliveryQueue) {
200
+ this._asyncDeliveryQueue = new LinkedList();
201
+ }
202
+ for (const listener of this._listeners) {
203
+ this._asyncDeliveryQueue.push([listener, data]);
204
+ }
205
+ while (this._asyncDeliveryQueue.size > 0 && !token.isCancellationRequested) {
206
+ const [listener, data] = this._asyncDeliveryQueue.shift();
207
+ const thenables = [];
208
+ const event = {
209
+ ...data,
210
+ token,
211
+ waitUntil: (p) => {
212
+ if (Object.isFrozen(thenables)) {
213
+ throw new Error('waitUntil can NOT be called asynchronous');
214
+ }
215
+ if (promiseJoin) {
216
+ p = promiseJoin(p, listener.callback);
217
+ }
218
+ thenables.push(p);
219
+ }
220
+ };
221
+ try {
222
+ listener.invoke(event);
223
+ }
224
+ catch (e) {
225
+ onUnexpectedError(e);
226
+ continue;
227
+ }
228
+ await Promise.allSettled(thenables).then(values => {
229
+ for (const value of values) {
230
+ if (value.status === 'rejected') {
231
+ onUnexpectedError(value.reason);
232
+ }
233
+ }
234
+ });
235
+ }
236
+ }
237
+ }
238
+ function refineServiceDecorator(serviceIdentifier) {
239
+ return serviceIdentifier;
240
+ }
241
+ const CancellationTokenSource = monaco.CancellationTokenSource;
242
+ const WINDOWS_INVALID_FILE_CHARS = /[\\/:\*\?"<>\|]/g;
243
+ const UNIX_INVALID_FILE_CHARS = /[\\/]/g;
244
+ const WINDOWS_FORBIDDEN_NAMES = /^(con|prn|aux|clock\$|nul|lpt[0-9]|com[0-9])(\.(.*?))?$/i;
245
+ function isValidBasename(name, isWindowsOS = isWindows) {
246
+ const invalidFileChars = isWindowsOS ? WINDOWS_INVALID_FILE_CHARS : UNIX_INVALID_FILE_CHARS;
247
+ if (!name || name.length === 0 || /^\s+$/.test(name)) {
248
+ return false;
249
+ }
250
+ invalidFileChars.lastIndex = 0;
251
+ if (invalidFileChars.test(name)) {
252
+ return false;
253
+ }
254
+ if (isWindowsOS && WINDOWS_FORBIDDEN_NAMES.test(name)) {
255
+ return false;
256
+ }
257
+ if (name === '.' || name === '..') {
258
+ return false;
259
+ }
260
+ if (isWindowsOS && name[name.length - 1] === '.') {
261
+ return false;
262
+ }
263
+ if (isWindowsOS && name.length !== name.trim().length) {
264
+ return false;
265
+ }
266
+ if (name.length > 255) {
267
+ return false;
268
+ }
269
+ return true;
270
+ }
271
+ function __decorate(decorators, target, key, desc) {
272
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
273
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
274
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
275
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
276
+ }
277
+ function __param(paramIndex, decorator) {
278
+ return function (target, key) { decorator(target, key, paramIndex); }
279
+ }
280
+ function __classPrivateFieldGet(receiver, state, kind, f) {
281
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
282
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
283
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
284
+ }
285
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
286
+ if (kind === "m") throw new TypeError("Private method is not writable");
287
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
288
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
289
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
290
+ }
291
+ function coalesceInPlace(array) {
292
+ let to = 0;
293
+ for (let i = 0; i < array.length; i++) {
294
+ if (!!array[i]) {
295
+ array[to] = array[i];
296
+ to += 1;
297
+ }
298
+ }
299
+ array.length = to;
300
+ }
301
+ function insert(array, element) {
302
+ array.push(element);
303
+ return () => remove(array, element);
304
+ }
305
+ function remove(array, element) {
306
+ const index = array.indexOf(element);
307
+ if (index > -1) {
308
+ array.splice(index, 1);
309
+ return element;
310
+ }
311
+ return undefined;
312
+ }
313
+ const IFileService = createDecorator('fileService');
314
+ var FileType;
315
+ (function(FileType) {
316
+ FileType[FileType["Unknown"] = 0] = "Unknown";
317
+ FileType[FileType["File"] = 1] = "File";
318
+ FileType[FileType["Directory"] = 2] = "Directory";
319
+ FileType[FileType["SymbolicLink"] = 64] = "SymbolicLink";
320
+ })(FileType || (FileType = {}));
321
+ var FilePermission;
322
+ (function(FilePermission) {
323
+ FilePermission[FilePermission["Readonly"] = 1] = "Readonly";
324
+ })(FilePermission || (FilePermission = {}));
325
+ var FileSystemProviderErrorCode;
326
+ (function(FileSystemProviderErrorCode) {
327
+ FileSystemProviderErrorCode["FileExists"] = "EntryExists";
328
+ FileSystemProviderErrorCode["FileNotFound"] = "EntryNotFound";
329
+ FileSystemProviderErrorCode["FileNotADirectory"] = "EntryNotADirectory";
330
+ FileSystemProviderErrorCode["FileIsADirectory"] = "EntryIsADirectory";
331
+ FileSystemProviderErrorCode["FileExceedsMemoryLimit"] = "EntryExceedsMemoryLimit";
332
+ FileSystemProviderErrorCode["FileTooLarge"] = "EntryTooLarge";
333
+ FileSystemProviderErrorCode["FileWriteLocked"] = "EntryWriteLocked";
334
+ FileSystemProviderErrorCode["NoPermissions"] = "NoPermissions";
335
+ FileSystemProviderErrorCode["Unavailable"] = "Unavailable";
336
+ FileSystemProviderErrorCode["Unknown"] = "Unknown";
337
+ })(FileSystemProviderErrorCode || (FileSystemProviderErrorCode = {}));
338
+ function markAsFileSystemProviderError(error, code) {
339
+ error.name = code ? `${code} (FileSystemError)` : `FileSystemError`;
340
+ return error;
341
+ }
342
+ class FileOperationError extends ErrorNoTelemetry {
343
+ constructor(message, fileOperationResult, options) {
344
+ super(message);
345
+ this.fileOperationResult = fileOperationResult;
346
+ this.options = options;
347
+ }
348
+ }
349
+ const IEditorGroupsService = createDecorator('editorGroupsService');
350
+ function isEditorGroup(obj) {
351
+ const group = obj;
352
+ return !!group && typeof group.id === 'number' && Array.isArray(group.editors);
353
+ }
354
+ const IEditorService = createDecorator('editorService');
355
+ const ACTIVE_GROUP = -1;
356
+ const SIDE_GROUP = -2;
357
+ function isPreferredGroup(obj) {
358
+ const candidate = obj;
359
+ return typeof obj === 'number' || isEditorGroup(candidate);
360
+ }
361
+ const IProgressService = createDecorator('progressService');
362
+ const ITextFileService = createDecorator('textFileService');
363
+ const IWorkbenchEnvironmentService = refineServiceDecorator(IEnvironmentService);
364
+ const IWorkingCopyService = createDecorator('workingCopyService');
365
+ const IUriIdentityService = createDecorator('IUriIdentityService');
366
+ let WorkingCopyFileOperationParticipant = class WorkingCopyFileOperationParticipant extends Disposable {
367
+ constructor(logService, configurationService) {
368
+ super();
369
+ this.logService = logService;
370
+ this.configurationService = configurationService;
371
+ this.participants = new LinkedList();
372
+ }
373
+ addFileOperationParticipant(participant) {
374
+ const remove = this.participants.push(participant);
375
+ return toDisposable(() => remove());
376
+ }
377
+ async participate(files, operation, undoInfo, token) {
378
+ const timeout = this.configurationService.getValue('files.participants.timeout');
379
+ if (typeof timeout !== 'number' || timeout <= 0) {
380
+ return;
381
+ }
382
+ for (const participant of this.participants) {
383
+ try {
384
+ await participant.participate(files, operation, undoInfo, timeout, token);
385
+ }
386
+ catch (err) {
387
+ this.logService.warn(err);
388
+ }
389
+ }
390
+ }
391
+ dispose() {
392
+ this.participants.clear();
393
+ }
394
+ };
395
+ WorkingCopyFileOperationParticipant = __decorate([
396
+ __param(0, ILogService),
397
+ __param(1, IConfigurationService)
398
+ ], WorkingCopyFileOperationParticipant);
399
+ let StoredFileWorkingCopySaveParticipant = class StoredFileWorkingCopySaveParticipant extends Disposable {
400
+ constructor(progressService, logService) {
401
+ super();
402
+ this.progressService = progressService;
403
+ this.logService = logService;
404
+ this.saveParticipants = [];
405
+ }
406
+ get length() { return this.saveParticipants.length; }
407
+ addSaveParticipant(participant) {
408
+ const remove = insert(this.saveParticipants, participant);
409
+ return toDisposable(() => remove());
410
+ }
411
+ participate(workingCopy, context, token) {
412
+ const cts = new CancellationTokenSource(token);
413
+ return this.progressService.withProgress({
414
+ title: localize('saveParticipants', "Saving '{0}'", workingCopy.name),
415
+ location: 15 ,
416
+ cancellable: true,
417
+ delay: workingCopy.isDirty() ? 3000 : 5000
418
+ }, async (progress) => {
419
+ workingCopy.model?.pushStackElement();
420
+ for (const saveParticipant of this.saveParticipants) {
421
+ if (cts.token.isCancellationRequested || workingCopy.isDisposed()) {
422
+ break;
423
+ }
424
+ try {
425
+ const promise = saveParticipant.participate(workingCopy, context, progress, cts.token);
426
+ await raceCancellation(promise, cts.token);
427
+ }
428
+ catch (err) {
429
+ this.logService.warn(err);
430
+ }
431
+ }
432
+ workingCopy.model?.pushStackElement();
433
+ }, () => {
434
+ cts.dispose(true);
435
+ });
436
+ }
437
+ dispose() {
438
+ this.saveParticipants.splice(0, this.saveParticipants.length);
439
+ }
440
+ };
441
+ StoredFileWorkingCopySaveParticipant = __decorate([
442
+ __param(0, IProgressService),
443
+ __param(1, ILogService)
444
+ ], StoredFileWorkingCopySaveParticipant);
445
+ const IWorkingCopyFileService = createDecorator('workingCopyFileService');
446
+ let WorkingCopyFileService = class WorkingCopyFileService extends Disposable {
447
+ constructor(fileService, workingCopyService, instantiationService, uriIdentityService) {
448
+ super();
449
+ this.fileService = fileService;
450
+ this.workingCopyService = workingCopyService;
451
+ this.instantiationService = instantiationService;
452
+ this.uriIdentityService = uriIdentityService;
453
+ this._onWillRunWorkingCopyFileOperation = this._register( new AsyncEmitter());
454
+ this.onWillRunWorkingCopyFileOperation = this._onWillRunWorkingCopyFileOperation.event;
455
+ this._onDidFailWorkingCopyFileOperation = this._register( new AsyncEmitter());
456
+ this.onDidFailWorkingCopyFileOperation = this._onDidFailWorkingCopyFileOperation.event;
457
+ this._onDidRunWorkingCopyFileOperation = this._register( new AsyncEmitter());
458
+ this.onDidRunWorkingCopyFileOperation = this._onDidRunWorkingCopyFileOperation.event;
459
+ this.correlationIds = 0;
460
+ this.fileOperationParticipants = this._register(this.instantiationService.createInstance(WorkingCopyFileOperationParticipant));
461
+ this.saveParticipants = this._register(this.instantiationService.createInstance(StoredFileWorkingCopySaveParticipant));
462
+ this.workingCopyProviders = [];
463
+ this._register(this.registerWorkingCopyProvider(resource => {
464
+ return this.workingCopyService.workingCopies.filter(workingCopy => {
465
+ if (this.fileService.hasProvider(resource)) {
466
+ return this.uriIdentityService.extUri.isEqualOrParent(workingCopy.resource, resource);
467
+ }
468
+ return this.uriIdentityService.extUri.isEqual(workingCopy.resource, resource);
469
+ });
470
+ }));
471
+ }
472
+ create(operations, token, undoInfo) {
473
+ return this.doCreateFileOrFolder(operations, true, token, undoInfo);
474
+ }
475
+ createFolder(operations, token, undoInfo) {
476
+ return this.doCreateFileOrFolder(operations, false, token, undoInfo);
477
+ }
478
+ async doCreateFileOrFolder(operations, isFile, token, undoInfo) {
479
+ if (operations.length === 0) {
480
+ return [];
481
+ }
482
+ if (isFile) {
483
+ const validateCreates = await Promises.settled(operations.map(operation => this.fileService.canCreateFile(operation.resource, { overwrite: operation.overwrite })));
484
+ const error = validateCreates.find(validateCreate => validateCreate instanceof Error);
485
+ if (error instanceof Error) {
486
+ throw error;
487
+ }
488
+ }
489
+ const files = operations.map(operation => ({ target: operation.resource }));
490
+ await this.runFileOperationParticipants(files, 0 , undoInfo, token);
491
+ const event = { correlationId: this.correlationIds++, operation: 0 , files };
492
+ await this._onWillRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
493
+ let stats;
494
+ try {
495
+ if (isFile) {
496
+ stats = await Promises.settled(operations.map(operation => this.fileService.createFile(operation.resource, operation.contents, { overwrite: operation.overwrite })));
497
+ }
498
+ else {
499
+ stats = await Promises.settled(operations.map(operation => this.fileService.createFolder(operation.resource)));
500
+ }
501
+ }
502
+ catch (error) {
503
+ await this._onDidFailWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
504
+ throw error;
505
+ }
506
+ await this._onDidRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
507
+ return stats;
508
+ }
509
+ async move(operations, token, undoInfo) {
510
+ return this.doMoveOrCopy(operations, true, token, undoInfo);
511
+ }
512
+ async copy(operations, token, undoInfo) {
513
+ return this.doMoveOrCopy(operations, false, token, undoInfo);
514
+ }
515
+ async doMoveOrCopy(operations, move, token, undoInfo) {
516
+ const stats = [];
517
+ for (const { file: { source, target }, overwrite } of operations) {
518
+ const validateMoveOrCopy = await (move ? this.fileService.canMove(source, target, overwrite) : this.fileService.canCopy(source, target, overwrite));
519
+ if (validateMoveOrCopy instanceof Error) {
520
+ throw validateMoveOrCopy;
521
+ }
522
+ }
523
+ const files = operations.map(o => o.file);
524
+ await this.runFileOperationParticipants(files, move ? 2 : 3 , undoInfo, token);
525
+ const event = { correlationId: this.correlationIds++, operation: move ? 2 : 3 , files };
526
+ await this._onWillRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
527
+ try {
528
+ for (const { file: { source, target }, overwrite } of operations) {
529
+ if (!this.uriIdentityService.extUri.isEqual(source, target)) {
530
+ const dirtyWorkingCopies = (move ? [...this.getDirty(source), ...this.getDirty(target)] : this.getDirty(target));
531
+ await Promises.settled(dirtyWorkingCopies.map(dirtyWorkingCopy => dirtyWorkingCopy.revert({ soft: true })));
532
+ }
533
+ if (move) {
534
+ stats.push(await this.fileService.move(source, target, overwrite));
535
+ }
536
+ else {
537
+ stats.push(await this.fileService.copy(source, target, overwrite));
538
+ }
539
+ }
540
+ }
541
+ catch (error) {
542
+ await this._onDidFailWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
543
+ throw error;
544
+ }
545
+ await this._onDidRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
546
+ return stats;
547
+ }
548
+ async delete(operations, token, undoInfo) {
549
+ for (const operation of operations) {
550
+ const validateDelete = await this.fileService.canDelete(operation.resource, { recursive: operation.recursive, useTrash: operation.useTrash });
551
+ if (validateDelete instanceof Error) {
552
+ throw validateDelete;
553
+ }
554
+ }
555
+ const files = operations.map(operation => ({ target: operation.resource }));
556
+ await this.runFileOperationParticipants(files, 1 , undoInfo, token);
557
+ const event = { correlationId: this.correlationIds++, operation: 1 , files };
558
+ await this._onWillRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
559
+ for (const operation of operations) {
560
+ const dirtyWorkingCopies = this.getDirty(operation.resource);
561
+ await Promises.settled(dirtyWorkingCopies.map(dirtyWorkingCopy => dirtyWorkingCopy.revert({ soft: true })));
562
+ }
563
+ try {
564
+ for (const operation of operations) {
565
+ await this.fileService.del(operation.resource, { recursive: operation.recursive, useTrash: operation.useTrash });
566
+ }
567
+ }
568
+ catch (error) {
569
+ await this._onDidFailWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
570
+ throw error;
571
+ }
572
+ await this._onDidRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
573
+ }
574
+ addFileOperationParticipant(participant) {
575
+ return this.fileOperationParticipants.addFileOperationParticipant(participant);
576
+ }
577
+ runFileOperationParticipants(files, operation, undoInfo, token) {
578
+ return this.fileOperationParticipants.participate(files, operation, undoInfo, token);
579
+ }
580
+ get hasSaveParticipants() { return this.saveParticipants.length > 0; }
581
+ addSaveParticipant(participant) {
582
+ return this.saveParticipants.addSaveParticipant(participant);
583
+ }
584
+ runSaveParticipants(workingCopy, context, token) {
585
+ return this.saveParticipants.participate(workingCopy, context, token);
586
+ }
587
+ registerWorkingCopyProvider(provider) {
588
+ const remove = insert(this.workingCopyProviders, provider);
589
+ return toDisposable(remove);
590
+ }
591
+ getDirty(resource) {
592
+ const dirtyWorkingCopies = new Set();
593
+ for (const provider of this.workingCopyProviders) {
594
+ for (const workingCopy of provider(resource)) {
595
+ if (workingCopy.isDirty()) {
596
+ dirtyWorkingCopies.add(workingCopy);
597
+ }
598
+ }
599
+ }
600
+ return Array.from(dirtyWorkingCopies);
601
+ }
602
+ };
603
+ WorkingCopyFileService = __decorate([
604
+ __param(0, IFileService),
605
+ __param(1, IWorkingCopyService),
606
+ __param(2, IInstantiationService),
607
+ __param(3, IUriIdentityService)
608
+ ], WorkingCopyFileService);
609
+ function isVirtualResource(resource) {
610
+ return resource.scheme !== Schemas.file && resource.scheme !== Schemas.vscodeRemote;
611
+ }
612
+ function getVirtualWorkspaceLocation(workspace) {
613
+ if (workspace.folders.length) {
614
+ return workspace.folders.every(f => isVirtualResource(f.uri)) ? workspace.folders[0].uri : undefined;
615
+ }
616
+ else if (workspace.configuration && isVirtualResource(workspace.configuration)) {
617
+ return workspace.configuration;
618
+ }
619
+ return undefined;
620
+ }
621
+ function getVirtualWorkspaceScheme(workspace) {
622
+ return getVirtualWorkspaceLocation(workspace)?.scheme;
623
+ }
624
+ const IRemoteAgentService = createDecorator('remoteAgentService');
625
+ const IPathService = createDecorator('pathService');
626
+ let AbstractPathService = class AbstractPathService {
627
+ constructor(localUserHome, remoteAgentService, environmentService, contextService) {
628
+ this.localUserHome = localUserHome;
629
+ this.remoteAgentService = remoteAgentService;
630
+ this.environmentService = environmentService;
631
+ this.contextService = contextService;
632
+ this.resolveOS = (async () => {
633
+ const env = await this.remoteAgentService.getEnvironment();
634
+ return env?.os || OS;
635
+ })();
636
+ this.resolveUserHome = (async () => {
637
+ const env = await this.remoteAgentService.getEnvironment();
638
+ const userHome = this.maybeUnresolvedUserHome = env?.userHome || localUserHome;
639
+ return userHome;
640
+ })();
641
+ }
642
+ hasValidBasename(resource, arg2, basename) {
643
+ if (typeof arg2 === 'string' || typeof arg2 === 'undefined') {
644
+ return this.resolveOS.then(os => this.doHasValidBasename(resource, os, arg2));
645
+ }
646
+ return this.doHasValidBasename(resource, arg2, basename);
647
+ }
648
+ doHasValidBasename(resource, os, name) {
649
+ if (resource.scheme === Schemas.file || resource.scheme === Schemas.vscodeRemote) {
650
+ return isValidBasename(name ?? basename(resource), os === 1 );
651
+ }
652
+ return true;
653
+ }
654
+ get defaultUriScheme() {
655
+ return AbstractPathService.findDefaultUriScheme(this.environmentService, this.contextService);
656
+ }
657
+ static findDefaultUriScheme(environmentService, contextService) {
658
+ if (environmentService.remoteAuthority) {
659
+ return Schemas.vscodeRemote;
660
+ }
661
+ const virtualWorkspace = getVirtualWorkspaceScheme(contextService.getWorkspace());
662
+ if (virtualWorkspace) {
663
+ return virtualWorkspace;
664
+ }
665
+ const firstFolder = contextService.getWorkspace().folders[0];
666
+ if (firstFolder) {
667
+ return firstFolder.uri.scheme;
668
+ }
669
+ const configuration = contextService.getWorkspace().configuration;
670
+ if (configuration) {
671
+ return configuration.scheme;
672
+ }
673
+ return Schemas.file;
674
+ }
675
+ async userHome(options) {
676
+ return options?.preferLocal ? this.localUserHome : this.resolveUserHome;
677
+ }
678
+ get resolvedUserHome() {
679
+ return this.maybeUnresolvedUserHome;
680
+ }
681
+ get path() {
682
+ return this.resolveOS.then(os => {
683
+ return os === 1 ?
684
+ win32 :
685
+ posix;
686
+ });
687
+ }
688
+ async fileURI(_path) {
689
+ let authority = '';
690
+ const os = await this.resolveOS;
691
+ if (os === 1 ) {
692
+ _path = _path.replace(/\\/g, '/');
693
+ }
694
+ if (_path[0] === '/' && _path[1] === '/') {
695
+ const idx = _path.indexOf('/', 2);
696
+ if (idx === -1) {
697
+ authority = _path.substring(2);
698
+ _path = '/';
699
+ }
700
+ else {
701
+ authority = _path.substring(2, idx);
702
+ _path = _path.substring(idx) || '/';
703
+ }
704
+ }
705
+ return URI.from({
706
+ scheme: Schemas.file,
707
+ authority,
708
+ path: _path,
709
+ query: '',
710
+ fragment: ''
711
+ });
712
+ }
713
+ };
714
+ AbstractPathService = __decorate([
715
+ __param(1, IRemoteAgentService),
716
+ __param(2, IWorkbenchEnvironmentService),
717
+ __param(3, IWorkspaceContextService)
718
+ ], AbstractPathService);
719
+ const IPaneCompositePartService = createDecorator('paneCompositePartService');
720
+ const IProductService = createDecorator('productService');
721
+ const ILanguageStatusService = createDecorator('ILanguageStatusService');
722
+ const IHostService = createDecorator('hostService');
723
+ let services;
724
+ var Services;
725
+ (function (Services) {
726
+ Services.get = () => {
727
+ if (services == null) {
728
+ throw new Error('Services has not been installed');
729
+ }
730
+ return services;
731
+ };
732
+ function install(_services) {
733
+ if (services != null) {
734
+ console.warn('Services have been overridden');
735
+ }
736
+ services = _services;
737
+ return {
738
+ dispose: () => {
739
+ if (services === _services) {
740
+ services = undefined;
741
+ }
742
+ }
743
+ };
744
+ }
745
+ Services.install = install;
746
+ })(Services || (Services = {}));
747
+ export { ACTIVE_GROUP as A, CancellationTokenSource as C, FileSystemProviderErrorCode as F, IProgressService as I, SIDE_GROUP as S, __classPrivateFieldSet as _, __classPrivateFieldGet as a, __decorate as b, coalesceInPlace as c, __param as d, ITextFileService as e, IFileService as f, IWorkbenchEnvironmentService as g, IUriIdentityService as h, IWorkingCopyFileService as i, IPathService as j, disposed as k, IEditorService as l, markAsFileSystemProviderError as m, IEditorGroupsService as n, IPaneCompositePartService as o, IProductService as p, ILanguageStatusService as q, readonly as r, IHostService as s, Services as t, FileType as u, FilePermission as v, refineServiceDecorator as w, isPreferredGroup as x };