@codingame/monaco-vscode-api 1.69.5 → 1.69.8

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.
package/dist/services2.js CHANGED
@@ -1,151 +1,305 @@
1
- import { createDecorator } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
1
+ import { createDecorator, IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
2
2
  import { IEnvironmentService } from 'monaco-editor/esm/vs/platform/environment/common/environment.js';
3
+ import { b as __decorate, d as __param, i as insert } from './contextkey.js';
4
+ import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
5
+ import { isWindows, OS } from 'monaco-editor/esm/vs/base/common/platform.js';
6
+ import { IWorkspaceContextService } from 'monaco-editor/esm/vs/platform/workspace/common/workspace.js';
7
+ import { basename } from 'monaco-editor/esm/vs/base/common/resources.js';
8
+ import { win32, posix } from 'monaco-editor/esm/vs/base/common/path.js';
9
+ import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
10
+ import { DisposableStore, SafeDisposable, Disposable, toDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
11
+ import { LinkedList } from 'monaco-editor/esm/vs/base/common/linkedList.js';
12
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
13
+ import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
3
14
  import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js';
4
15
  import { localize } from 'monaco-editor/esm/vs/nls.js';
16
+ import { raceCancellation, Promises } from 'monaco-editor/esm/vs/base/common/async.js';
17
+ import { IProgressService } from 'monaco-editor/esm/vs/platform/progress/common/progress.js';
5
18
  import { TernarySearchTree } from 'monaco-editor/esm/vs/base/common/map.js';
6
- import { Event } from 'monaco-editor/esm/vs/base/common/event.js';
7
- function refineServiceDecorator(serviceIdentifier) {
8
- return serviceIdentifier;
9
- }
10
- const CancellationTokenSource = monaco.CancellationTokenSource;
11
- function sortedDiff(before, after, compare) {
12
- const result = [];
13
- function pushSplice(start, deleteCount, toInsert) {
14
- if (deleteCount === 0 && toInsert.length === 0) {
15
- return;
16
- }
17
- const latest = result[result.length - 1];
18
- if (latest && latest.start + latest.deleteCount === start) {
19
- latest.deleteCount += deleteCount;
20
- latest.toInsert.push(...toInsert);
19
+ import { onUnexpectedError } from 'monaco-editor/esm/vs/base/common/errors.js';
20
+ import { StopWatch } from 'monaco-editor/esm/vs/base/common/stopwatch.js';
21
+ import { CancellationToken } from 'monaco-editor/esm/vs/base/common/cancellation.js';
22
+ import 'monaco-editor/esm/vs/editor/standalone/browser/standaloneServices.js';
23
+ import 'monaco-editor/esm/vs/platform/commands/common/commands.js';
24
+ import 'monaco-editor/esm/vs/platform/notification/common/notification.js';
25
+ import 'monaco-editor/esm/vs/editor/browser/services/bulkEditService.js';
26
+ import 'monaco-editor/esm/vs/editor/browser/services/codeEditorService.js';
27
+ import 'monaco-editor/esm/vs/editor/common/languages/language.js';
28
+ import 'monaco-editor/esm/vs/editor/common/languages/languageConfigurationRegistry.js';
29
+ import 'monaco-editor/esm/vs/editor/common/services/editorWorker.js';
30
+ import 'monaco-editor/esm/vs/editor/common/services/languageFeatures.js';
31
+ import 'monaco-editor/esm/vs/editor/common/services/model.js';
32
+ import 'monaco-editor/esm/vs/editor/common/services/resolverService.js';
33
+ import 'monaco-editor/esm/vs/platform/clipboard/common/clipboardService.js';
34
+ import 'monaco-editor/esm/vs/platform/dialogs/common/dialogs.js';
35
+ import 'monaco-editor/esm/vs/platform/markers/common/markers.js';
36
+ import 'monaco-editor/esm/vs/platform/opener/common/opener.js';
37
+ import 'monaco-editor/esm/vs/platform/quickinput/common/quickInput.js';
38
+ import 'monaco-editor/esm/vs/platform/telemetry/common/telemetry.js';
39
+ import 'monaco-editor/esm/vs/platform/theme/common/themeService.js';
40
+ import 'monaco-editor/esm/vs/base/common/severity.js';
41
+ class EventProfiling {
42
+ constructor(name) {
43
+ this._listenerCount = 0;
44
+ this._invocationCount = 0;
45
+ this._elapsedOverall = 0;
46
+ this._name = `${name}_${EventProfiling._idPool++}`;
47
+ }
48
+ start(listenerCount) {
49
+ this._stopWatch = ( new StopWatch(true));
50
+ this._listenerCount = listenerCount;
51
+ }
52
+ stop() {
53
+ if (this._stopWatch) {
54
+ const elapsed = this._stopWatch.elapsed();
55
+ this._elapsedOverall += elapsed;
56
+ this._invocationCount += 1;
57
+ console.info(`did FIRE ${this._name}: elapsed_ms: ${elapsed.toFixed(5)}, listener: ${this._listenerCount} (elapsed_overall: ${this._elapsedOverall.toFixed(2)}, invocations: ${this._invocationCount})`);
58
+ this._stopWatch = undefined;
21
59
  }
22
- else {
23
- result.push({ start, deleteCount, toInsert });
60
+ }
61
+ }
62
+ EventProfiling._idPool = 0;
63
+ class Stacktrace {
64
+ constructor(value) {
65
+ this.value = value;
66
+ }
67
+ static create() {
68
+ return ( new Stacktrace(( new Error()).stack ?? ''));
69
+ }
70
+ print() {
71
+ console.warn(this.value.split('\n').slice(2).join('\n'));
72
+ }
73
+ }
74
+ class Listener {
75
+ constructor(callback, callbackThis, stack) {
76
+ this.callback = callback;
77
+ this.callbackThis = callbackThis;
78
+ this.stack = stack;
79
+ this.subscription = ( new SafeDisposable());
80
+ }
81
+ invoke(e) {
82
+ this.callback.call(this.callbackThis, e);
83
+ }
84
+ }
85
+ class Emitter {
86
+ constructor(options) {
87
+ this._disposed = false;
88
+ this._options = options;
89
+ this._leakageMon = undefined;
90
+ this._perfMon = this._options?._profName ? ( new EventProfiling(this._options._profName)) : undefined;
91
+ this._deliveryQueue = this._options?.deliveryQueue;
92
+ }
93
+ dispose() {
94
+ if (!this._disposed) {
95
+ this._disposed = true;
96
+ if (this._listeners) {
97
+ this._listeners.clear();
98
+ }
99
+ this._deliveryQueue?.clear(this);
100
+ this._options?.onLastListenerRemove?.();
101
+ this._leakageMon?.dispose();
24
102
  }
25
103
  }
26
- let beforeIdx = 0;
27
- let afterIdx = 0;
28
- while (true) {
29
- if (beforeIdx === before.length) {
30
- pushSplice(beforeIdx, 0, after.slice(afterIdx));
31
- break;
104
+ get event() {
105
+ if (!this._event) {
106
+ this._event = (callback, thisArgs, disposables) => {
107
+ if (!this._listeners) {
108
+ this._listeners = ( new LinkedList());
109
+ }
110
+ const firstListener = this._listeners.isEmpty();
111
+ if (firstListener && this._options?.onFirstListenerAdd) {
112
+ this._options.onFirstListenerAdd(this);
113
+ }
114
+ let removeMonitor;
115
+ let stack;
116
+ if (this._leakageMon && this._listeners.size >= 30) {
117
+ stack = Stacktrace.create();
118
+ removeMonitor = this._leakageMon.check(stack, this._listeners.size + 1);
119
+ }
120
+ const listener = ( new Listener(callback, thisArgs, stack));
121
+ const removeListener = this._listeners.push(listener);
122
+ if (firstListener && this._options?.onFirstListenerDidAdd) {
123
+ this._options.onFirstListenerDidAdd(this);
124
+ }
125
+ if (this._options?.onListenerDidAdd) {
126
+ this._options.onListenerDidAdd(this, callback, thisArgs);
127
+ }
128
+ const result = listener.subscription.set(() => {
129
+ removeMonitor?.();
130
+ if (!this._disposed) {
131
+ removeListener();
132
+ if (this._options && this._options.onLastListenerRemove) {
133
+ const hasListeners = (this._listeners && !this._listeners.isEmpty());
134
+ if (!hasListeners) {
135
+ this._options.onLastListenerRemove(this);
136
+ }
137
+ }
138
+ }
139
+ });
140
+ if (disposables instanceof DisposableStore) {
141
+ disposables.add(result);
142
+ }
143
+ else if (Array.isArray(disposables)) {
144
+ disposables.push(result);
145
+ }
146
+ return result;
147
+ };
32
148
  }
33
- if (afterIdx === after.length) {
34
- pushSplice(beforeIdx, before.length - beforeIdx, []);
35
- break;
149
+ return this._event;
150
+ }
151
+ fire(event) {
152
+ if (this._listeners) {
153
+ if (!this._deliveryQueue) {
154
+ this._deliveryQueue = ( new PrivateEventDeliveryQueue());
155
+ }
156
+ for (const listener of this._listeners) {
157
+ this._deliveryQueue.push(this, listener, event);
158
+ }
159
+ this._perfMon?.start(this._deliveryQueue.size);
160
+ this._deliveryQueue.deliver();
161
+ this._perfMon?.stop();
36
162
  }
37
- const beforeElement = before[beforeIdx];
38
- const afterElement = after[afterIdx];
39
- const n = compare(beforeElement, afterElement);
40
- if (n === 0) {
41
- beforeIdx += 1;
42
- afterIdx += 1;
163
+ }
164
+ hasListeners() {
165
+ if (!this._listeners) {
166
+ return false;
43
167
  }
44
- else if (n < 0) {
45
- pushSplice(beforeIdx, 1, []);
46
- beforeIdx += 1;
168
+ return (!this._listeners.isEmpty());
169
+ }
170
+ }
171
+ class EventDeliveryQueue {
172
+ constructor() {
173
+ this._queue = ( new LinkedList());
174
+ }
175
+ get size() {
176
+ return this._queue.size;
177
+ }
178
+ push(emitter, listener, event) {
179
+ this._queue.push(( new EventDeliveryQueueElement(emitter, listener, event)));
180
+ }
181
+ clear(emitter) {
182
+ const newQueue = ( new LinkedList());
183
+ for (const element of this._queue) {
184
+ if (element.emitter !== emitter) {
185
+ newQueue.push(element);
186
+ }
47
187
  }
48
- else if (n > 0) {
49
- pushSplice(beforeIdx, 0, [afterElement]);
50
- afterIdx += 1;
188
+ this._queue = newQueue;
189
+ }
190
+ deliver() {
191
+ while (this._queue.size > 0) {
192
+ const element = this._queue.shift();
193
+ try {
194
+ element.listener.invoke(element.event);
195
+ }
196
+ catch (e) {
197
+ onUnexpectedError(e);
198
+ }
51
199
  }
52
200
  }
53
- return result;
54
201
  }
55
- function delta(before, after, compare) {
56
- const splices = sortedDiff(before, after, compare);
57
- const removed = [];
58
- const added = [];
59
- for (const splice of splices) {
60
- removed.push(...before.slice(splice.start, splice.start + splice.deleteCount));
61
- added.push(...splice.toInsert);
202
+ class PrivateEventDeliveryQueue extends EventDeliveryQueue {
203
+ clear(emitter) {
204
+ this._queue.clear();
62
205
  }
63
- return { removed, added };
64
206
  }
65
- function coalesceInPlace(array) {
66
- let to = 0;
67
- for (let i = 0; i < array.length; i++) {
68
- if (!!array[i]) {
69
- array[to] = array[i];
70
- to += 1;
71
- }
207
+ class EventDeliveryQueueElement {
208
+ constructor(emitter, listener, event) {
209
+ this.emitter = emitter;
210
+ this.listener = listener;
211
+ this.event = event;
72
212
  }
73
- array.length = to;
74
213
  }
75
- function flatten(arr) {
76
- return [].concat(...arr);
214
+ class AsyncEmitter extends Emitter {
215
+ async fireAsync(data, token, promiseJoin) {
216
+ if (!this._listeners) {
217
+ return;
218
+ }
219
+ if (!this._asyncDeliveryQueue) {
220
+ this._asyncDeliveryQueue = ( new LinkedList());
221
+ }
222
+ for (const listener of this._listeners) {
223
+ this._asyncDeliveryQueue.push([listener, data]);
224
+ }
225
+ while (this._asyncDeliveryQueue.size > 0 && !token.isCancellationRequested) {
226
+ const [listener, data] = this._asyncDeliveryQueue.shift();
227
+ const thenables = [];
228
+ const event = {
229
+ ...data,
230
+ token,
231
+ waitUntil: (p) => {
232
+ if (Object.isFrozen(thenables)) {
233
+ throw new Error('waitUntil can NOT be called asynchronous');
234
+ }
235
+ if (promiseJoin) {
236
+ p = promiseJoin(p, listener.callback);
237
+ }
238
+ thenables.push(p);
239
+ }
240
+ };
241
+ try {
242
+ listener.invoke(event);
243
+ }
244
+ catch (e) {
245
+ onUnexpectedError(e);
246
+ continue;
247
+ }
248
+ await Promise.allSettled(thenables).then(values => {
249
+ for (const value of values) {
250
+ if (value.status === 'rejected') {
251
+ onUnexpectedError(value.reason);
252
+ }
253
+ }
254
+ });
255
+ }
256
+ }
77
257
  }
78
- function index(array, indexer, mapper) {
79
- return array.reduce((r, t) => {
80
- r[indexer(t)] = mapper ? mapper(t) : t;
81
- return r;
82
- }, Object.create(null));
258
+ function refineServiceDecorator(serviceIdentifier) {
259
+ return serviceIdentifier;
83
260
  }
84
- function shuffle(array, _seed) {
85
- let rand;
86
- if (typeof _seed === 'number') {
87
- let seed = _seed;
88
- rand = () => {
89
- const x = Math.sin(seed++) * 179426549;
90
- return x - Math.floor(x);
91
- };
261
+ const CancellationTokenSource = monaco.CancellationTokenSource;
262
+ const WINDOWS_INVALID_FILE_CHARS = /[\\/:\*\?"<>\|]/g;
263
+ const UNIX_INVALID_FILE_CHARS = /[\\/]/g;
264
+ const WINDOWS_FORBIDDEN_NAMES = /^(con|prn|aux|clock\$|nul|lpt[0-9]|com[0-9])(\.(.*?))?$/i;
265
+ function isValidBasename(name, isWindowsOS = isWindows) {
266
+ const invalidFileChars = isWindowsOS ? WINDOWS_INVALID_FILE_CHARS : UNIX_INVALID_FILE_CHARS;
267
+ if (!name || name.length === 0 || /^\s+$/.test(name)) {
268
+ return false;
92
269
  }
93
- else {
94
- rand = Math.random;
95
- }
96
- for (let i = array.length - 1; i > 0; i -= 1) {
97
- const j = Math.floor(rand() * (i + 1));
98
- const temp = array[i];
99
- array[i] = array[j];
100
- array[j] = temp;
101
- }
102
- }
103
- function mapArrayOrNot(items, fn) {
104
- return Array.isArray(items) ?
105
- items.map(fn) :
106
- fn(items);
107
- }
108
- var NeverShowAgainScope;
109
- ( ((function(NeverShowAgainScope) {
110
- NeverShowAgainScope[NeverShowAgainScope["WORKSPACE"] = 0] = "WORKSPACE";
111
- NeverShowAgainScope[NeverShowAgainScope["PROFILE"] = 1] = "PROFILE";
112
- NeverShowAgainScope[NeverShowAgainScope["APPLICATION"] = 2] = "APPLICATION";
113
- })(NeverShowAgainScope || (NeverShowAgainScope = {}))));
114
- var NotificationsFilter;
115
- ( ((function(NotificationsFilter) {
116
- NotificationsFilter[NotificationsFilter["OFF"] = 0] = "OFF";
117
- NotificationsFilter[NotificationsFilter["SILENT"] = 1] = "SILENT";
118
- NotificationsFilter[NotificationsFilter["ERROR"] = 2] = "ERROR";
119
- })(NotificationsFilter || (NotificationsFilter = {}))));
120
- class NoOpNotification {
121
- constructor() {
122
- this.progress = ( (new NoOpProgress()));
123
- this.onDidClose = Event.None;
124
- this.onDidChangeVisibility = Event.None;
125
- }
126
- updateSeverity(severity) { }
127
- updateMessage(message) { }
128
- updateActions(actions) { }
129
- close() { }
130
- }
131
- class NoOpProgress {
132
- infinite() { }
133
- done() { }
134
- total(value) { }
135
- worked(value) { }
136
- }
137
- const IFileService = ( (createDecorator('fileService')));
270
+ invalidFileChars.lastIndex = 0;
271
+ if (invalidFileChars.test(name)) {
272
+ return false;
273
+ }
274
+ if (isWindowsOS && WINDOWS_FORBIDDEN_NAMES.test(name)) {
275
+ return false;
276
+ }
277
+ if (name === '.' || name === '..') {
278
+ return false;
279
+ }
280
+ if (isWindowsOS && name[name.length - 1] === '.') {
281
+ return false;
282
+ }
283
+ if (isWindowsOS && name.length !== name.trim().length) {
284
+ return false;
285
+ }
286
+ if (name.length > 255) {
287
+ return false;
288
+ }
289
+ return true;
290
+ }
291
+ const IFileService = ( createDecorator('fileService'));
138
292
  var FileType;
139
- ( ((function(FileType) {
293
+ ( (function(FileType) {
140
294
  FileType[FileType["Unknown"] = 0] = "Unknown";
141
295
  FileType[FileType["File"] = 1] = "File";
142
296
  FileType[FileType["Directory"] = 2] = "Directory";
143
297
  FileType[FileType["SymbolicLink"] = 64] = "SymbolicLink";
144
- })(FileType || (FileType = {}))));
298
+ })(FileType || (FileType = {})));
145
299
  var FilePermission;
146
- ( ((function(FilePermission) {
300
+ ( (function(FilePermission) {
147
301
  FilePermission[FilePermission["Readonly"] = 1] = "Readonly";
148
- })(FilePermission || (FilePermission = {}))));
302
+ })(FilePermission || (FilePermission = {})));
149
303
  function hasReadWriteCapability(provider) {
150
304
  return !!((provider.capabilities & 2) );
151
305
  }
@@ -168,7 +322,7 @@ function hasFileAtomicReadCapability(provider) {
168
322
  return !!((provider.capabilities & 16384) );
169
323
  }
170
324
  var FileSystemProviderErrorCode;
171
- ( ((function(FileSystemProviderErrorCode) {
325
+ ( (function(FileSystemProviderErrorCode) {
172
326
  FileSystemProviderErrorCode["FileExists"] = "EntryExists";
173
327
  FileSystemProviderErrorCode["FileNotFound"] = "EntryNotFound";
174
328
  FileSystemProviderErrorCode["FileNotADirectory"] = "EntryNotADirectory";
@@ -179,7 +333,7 @@ var FileSystemProviderErrorCode;
179
333
  FileSystemProviderErrorCode["NoPermissions"] = "NoPermissions";
180
334
  FileSystemProviderErrorCode["Unavailable"] = "Unavailable";
181
335
  FileSystemProviderErrorCode["Unknown"] = "Unknown";
182
- })(FileSystemProviderErrorCode || (FileSystemProviderErrorCode = {}))));
336
+ })(FileSystemProviderErrorCode || (FileSystemProviderErrorCode = {})));
183
337
  class FileSystemProviderError extends Error {
184
338
  constructor(message, code) {
185
339
  super(message);
@@ -187,13 +341,13 @@ class FileSystemProviderError extends Error {
187
341
  }
188
342
  }
189
343
  function createFileSystemProviderError(error, code) {
190
- const providerError = ( (new FileSystemProviderError( (error.toString()), code)));
344
+ const providerError = ( new FileSystemProviderError(( error.toString()), code));
191
345
  markAsFileSystemProviderError(providerError, code);
192
346
  return providerError;
193
347
  }
194
348
  function ensureFileSystemProviderError(error) {
195
349
  if (!error) {
196
- return createFileSystemProviderError(( (localize('unknownError', "Unknown Error"))), FileSystemProviderErrorCode.Unknown);
350
+ return createFileSystemProviderError(( localize('unknownError', "Unknown Error")), FileSystemProviderErrorCode.Unknown);
197
351
  }
198
352
  return error;
199
353
  }
@@ -270,7 +424,7 @@ class FileChangesEvent {
270
424
  this.rawUpdated = [];
271
425
  this.rawDeleted = [];
272
426
  this.rawChanges = changes;
273
- const entriesByType = ( (new Map()));
427
+ const entriesByType = ( new Map());
274
428
  for (const change of changes) {
275
429
  const array = entriesByType.get(change.type);
276
430
  if (array) {
@@ -374,34 +528,386 @@ function etag(stat) {
374
528
  if (typeof stat.size !== 'number' || typeof stat.mtime !== 'number') {
375
529
  return undefined;
376
530
  }
377
- return ( (stat.mtime.toString(29))) + ( (stat.size.toString(31)));
531
+ return ( stat.mtime.toString(29)) + ( stat.size.toString(31));
378
532
  }
379
- const IUriIdentityService = ( (createDecorator('IUriIdentityService')));
380
- const IEditorGroupsService = ( (createDecorator('editorGroupsService')));
533
+ const IUriIdentityService = ( createDecorator('IUriIdentityService'));
534
+ const IEditorGroupsService = ( createDecorator('editorGroupsService'));
381
535
  function isEditorGroup(obj) {
382
536
  const group = obj;
383
537
  return !!group && typeof group.id === 'number' && Array.isArray(group.editors);
384
538
  }
385
- const IEditorService = ( (createDecorator('editorService')));
539
+ const IEditorService = ( createDecorator('editorService'));
386
540
  const ACTIVE_GROUP = -1;
387
541
  const SIDE_GROUP = -2;
388
542
  function isPreferredGroup(obj) {
389
543
  const candidate = obj;
390
544
  return typeof obj === 'number' || isEditorGroup(candidate);
391
545
  }
392
- const ITextFileService = ( (createDecorator('textFileService')));
546
+ const ITextFileService = ( createDecorator('textFileService'));
393
547
  const IWorkbenchEnvironmentService = refineServiceDecorator(IEnvironmentService);
394
- const IWorkingCopyFileService = ( (createDecorator('workingCopyFileService')));
395
- const IPathService = ( (createDecorator('pathService')));
396
- const IPaneCompositePartService = ( (createDecorator('paneCompositePartService')));
397
- const IProductService = ( (createDecorator('productService')));
548
+ const IWorkingCopyService = ( createDecorator('workingCopyService'));
549
+ let WorkingCopyFileOperationParticipant = class WorkingCopyFileOperationParticipant extends Disposable {
550
+ constructor(logService, configurationService) {
551
+ super();
552
+ this.logService = logService;
553
+ this.configurationService = configurationService;
554
+ this.participants = ( new LinkedList());
555
+ }
556
+ addFileOperationParticipant(participant) {
557
+ const remove = this.participants.push(participant);
558
+ return toDisposable(() => remove());
559
+ }
560
+ async participate(files, operation, undoInfo, token) {
561
+ const timeout = this.configurationService.getValue('files.participants.timeout');
562
+ if (typeof timeout !== 'number' || timeout <= 0) {
563
+ return;
564
+ }
565
+ for (const participant of this.participants) {
566
+ try {
567
+ await participant.participate(files, operation, undoInfo, timeout, token);
568
+ }
569
+ catch (err) {
570
+ this.logService.warn(err);
571
+ }
572
+ }
573
+ }
574
+ dispose() {
575
+ this.participants.clear();
576
+ }
577
+ };
578
+ WorkingCopyFileOperationParticipant = ( __decorate([
579
+ ( __param(0, ILogService)),
580
+ ( __param(1, IConfigurationService))
581
+ ], WorkingCopyFileOperationParticipant));
582
+ let StoredFileWorkingCopySaveParticipant = class StoredFileWorkingCopySaveParticipant extends Disposable {
583
+ constructor(progressService, logService) {
584
+ super();
585
+ this.progressService = progressService;
586
+ this.logService = logService;
587
+ this.saveParticipants = [];
588
+ }
589
+ get length() { return this.saveParticipants.length; }
590
+ addSaveParticipant(participant) {
591
+ const remove = insert(this.saveParticipants, participant);
592
+ return toDisposable(() => remove());
593
+ }
594
+ participate(workingCopy, context, token) {
595
+ const cts = ( new CancellationTokenSource(token));
596
+ return this.progressService.withProgress({
597
+ title: ( localize('saveParticipants', "Saving '{0}'", workingCopy.name)),
598
+ location: 15 ,
599
+ cancellable: true,
600
+ delay: workingCopy.isDirty() ? 3000 : 5000
601
+ }, async (progress) => {
602
+ workingCopy.model?.pushStackElement();
603
+ for (const saveParticipant of this.saveParticipants) {
604
+ if (cts.token.isCancellationRequested || workingCopy.isDisposed()) {
605
+ break;
606
+ }
607
+ try {
608
+ const promise = saveParticipant.participate(workingCopy, context, progress, cts.token);
609
+ await raceCancellation(promise, cts.token);
610
+ }
611
+ catch (err) {
612
+ this.logService.warn(err);
613
+ }
614
+ }
615
+ workingCopy.model?.pushStackElement();
616
+ }, () => {
617
+ cts.dispose(true);
618
+ });
619
+ }
620
+ dispose() {
621
+ this.saveParticipants.splice(0, this.saveParticipants.length);
622
+ }
623
+ };
624
+ StoredFileWorkingCopySaveParticipant = ( __decorate([
625
+ ( __param(0, IProgressService)),
626
+ ( __param(1, ILogService))
627
+ ], StoredFileWorkingCopySaveParticipant));
628
+ const IWorkingCopyFileService = ( createDecorator('workingCopyFileService'));
629
+ let WorkingCopyFileService = class WorkingCopyFileService extends Disposable {
630
+ constructor(fileService, workingCopyService, instantiationService, uriIdentityService) {
631
+ super();
632
+ this.fileService = fileService;
633
+ this.workingCopyService = workingCopyService;
634
+ this.instantiationService = instantiationService;
635
+ this.uriIdentityService = uriIdentityService;
636
+ this._onWillRunWorkingCopyFileOperation = this._register(( new AsyncEmitter()));
637
+ this.onWillRunWorkingCopyFileOperation = this._onWillRunWorkingCopyFileOperation.event;
638
+ this._onDidFailWorkingCopyFileOperation = this._register(( new AsyncEmitter()));
639
+ this.onDidFailWorkingCopyFileOperation = this._onDidFailWorkingCopyFileOperation.event;
640
+ this._onDidRunWorkingCopyFileOperation = this._register(( new AsyncEmitter()));
641
+ this.onDidRunWorkingCopyFileOperation = this._onDidRunWorkingCopyFileOperation.event;
642
+ this.correlationIds = 0;
643
+ this.fileOperationParticipants = this._register(this.instantiationService.createInstance(WorkingCopyFileOperationParticipant));
644
+ this.saveParticipants = this._register(this.instantiationService.createInstance(StoredFileWorkingCopySaveParticipant));
645
+ this.workingCopyProviders = [];
646
+ this._register(this.registerWorkingCopyProvider(resource => {
647
+ return this.workingCopyService.workingCopies.filter(workingCopy => {
648
+ if (this.fileService.hasProvider(resource)) {
649
+ return this.uriIdentityService.extUri.isEqualOrParent(workingCopy.resource, resource);
650
+ }
651
+ return this.uriIdentityService.extUri.isEqual(workingCopy.resource, resource);
652
+ });
653
+ }));
654
+ }
655
+ create(operations, token, undoInfo) {
656
+ return this.doCreateFileOrFolder(operations, true, token, undoInfo);
657
+ }
658
+ createFolder(operations, token, undoInfo) {
659
+ return this.doCreateFileOrFolder(operations, false, token, undoInfo);
660
+ }
661
+ async doCreateFileOrFolder(operations, isFile, token, undoInfo) {
662
+ if (operations.length === 0) {
663
+ return [];
664
+ }
665
+ if (isFile) {
666
+ const validateCreates = await Promises.settled(operations.map(operation => this.fileService.canCreateFile(operation.resource, { overwrite: operation.overwrite })));
667
+ const error = validateCreates.find(validateCreate => validateCreate instanceof Error);
668
+ if (error instanceof Error) {
669
+ throw error;
670
+ }
671
+ }
672
+ const files = operations.map(operation => ({ target: operation.resource }));
673
+ await this.runFileOperationParticipants(files, 0 , undoInfo, token);
674
+ const event = { correlationId: this.correlationIds++, operation: 0 , files };
675
+ await this._onWillRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
676
+ let stats;
677
+ try {
678
+ if (isFile) {
679
+ stats = await Promises.settled(operations.map(operation => this.fileService.createFile(operation.resource, operation.contents, { overwrite: operation.overwrite })));
680
+ }
681
+ else {
682
+ stats = await Promises.settled(operations.map(operation => this.fileService.createFolder(operation.resource)));
683
+ }
684
+ }
685
+ catch (error) {
686
+ await this._onDidFailWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
687
+ throw error;
688
+ }
689
+ await this._onDidRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
690
+ return stats;
691
+ }
692
+ async move(operations, token, undoInfo) {
693
+ return this.doMoveOrCopy(operations, true, token, undoInfo);
694
+ }
695
+ async copy(operations, token, undoInfo) {
696
+ return this.doMoveOrCopy(operations, false, token, undoInfo);
697
+ }
698
+ async doMoveOrCopy(operations, move, token, undoInfo) {
699
+ const stats = [];
700
+ for (const { file: { source, target }, overwrite } of operations) {
701
+ const validateMoveOrCopy = await (move ? this.fileService.canMove(source, target, overwrite) : this.fileService.canCopy(source, target, overwrite));
702
+ if (validateMoveOrCopy instanceof Error) {
703
+ throw validateMoveOrCopy;
704
+ }
705
+ }
706
+ const files = operations.map(o => o.file);
707
+ await this.runFileOperationParticipants(files, move ? 2 : 3 , undoInfo, token);
708
+ const event = { correlationId: this.correlationIds++, operation: move ? 2 : 3 , files };
709
+ await this._onWillRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
710
+ try {
711
+ for (const { file: { source, target }, overwrite } of operations) {
712
+ if (!this.uriIdentityService.extUri.isEqual(source, target)) {
713
+ const dirtyWorkingCopies = (move ? [...this.getDirty(source), ...this.getDirty(target)] : this.getDirty(target));
714
+ await Promises.settled(dirtyWorkingCopies.map(dirtyWorkingCopy => dirtyWorkingCopy.revert({ soft: true })));
715
+ }
716
+ if (move) {
717
+ stats.push(await this.fileService.move(source, target, overwrite));
718
+ }
719
+ else {
720
+ stats.push(await this.fileService.copy(source, target, overwrite));
721
+ }
722
+ }
723
+ }
724
+ catch (error) {
725
+ await this._onDidFailWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
726
+ throw error;
727
+ }
728
+ await this._onDidRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
729
+ return stats;
730
+ }
731
+ async delete(operations, token, undoInfo) {
732
+ for (const operation of operations) {
733
+ const validateDelete = await this.fileService.canDelete(operation.resource, { recursive: operation.recursive, useTrash: operation.useTrash });
734
+ if (validateDelete instanceof Error) {
735
+ throw validateDelete;
736
+ }
737
+ }
738
+ const files = operations.map(operation => ({ target: operation.resource }));
739
+ await this.runFileOperationParticipants(files, 1 , undoInfo, token);
740
+ const event = { correlationId: this.correlationIds++, operation: 1 , files };
741
+ await this._onWillRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
742
+ for (const operation of operations) {
743
+ const dirtyWorkingCopies = this.getDirty(operation.resource);
744
+ await Promises.settled(dirtyWorkingCopies.map(dirtyWorkingCopy => dirtyWorkingCopy.revert({ soft: true })));
745
+ }
746
+ try {
747
+ for (const operation of operations) {
748
+ await this.fileService.del(operation.resource, { recursive: operation.recursive, useTrash: operation.useTrash });
749
+ }
750
+ }
751
+ catch (error) {
752
+ await this._onDidFailWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
753
+ throw error;
754
+ }
755
+ await this._onDidRunWorkingCopyFileOperation.fireAsync(event, CancellationToken.None );
756
+ }
757
+ addFileOperationParticipant(participant) {
758
+ return this.fileOperationParticipants.addFileOperationParticipant(participant);
759
+ }
760
+ runFileOperationParticipants(files, operation, undoInfo, token) {
761
+ return this.fileOperationParticipants.participate(files, operation, undoInfo, token);
762
+ }
763
+ get hasSaveParticipants() { return this.saveParticipants.length > 0; }
764
+ addSaveParticipant(participant) {
765
+ return this.saveParticipants.addSaveParticipant(participant);
766
+ }
767
+ runSaveParticipants(workingCopy, context, token) {
768
+ return this.saveParticipants.participate(workingCopy, context, token);
769
+ }
770
+ registerWorkingCopyProvider(provider) {
771
+ const remove = insert(this.workingCopyProviders, provider);
772
+ return toDisposable(remove);
773
+ }
774
+ getDirty(resource) {
775
+ const dirtyWorkingCopies = ( new Set());
776
+ for (const provider of this.workingCopyProviders) {
777
+ for (const workingCopy of provider(resource)) {
778
+ if (workingCopy.isDirty()) {
779
+ dirtyWorkingCopies.add(workingCopy);
780
+ }
781
+ }
782
+ }
783
+ return Array.from(dirtyWorkingCopies);
784
+ }
785
+ };
786
+ WorkingCopyFileService = ( __decorate([
787
+ ( __param(0, IFileService)),
788
+ ( __param(1, IWorkingCopyService)),
789
+ ( __param(2, IInstantiationService)),
790
+ ( __param(3, IUriIdentityService))
791
+ ], WorkingCopyFileService));
792
+ function isVirtualResource(resource) {
793
+ return resource.scheme !== Schemas.file && resource.scheme !== Schemas.vscodeRemote;
794
+ }
795
+ function getVirtualWorkspaceLocation(workspace) {
796
+ if (workspace.folders.length) {
797
+ return workspace.folders.every(f => isVirtualResource(f.uri)) ? workspace.folders[0].uri : undefined;
798
+ }
799
+ else if (workspace.configuration && isVirtualResource(workspace.configuration)) {
800
+ return workspace.configuration;
801
+ }
802
+ return undefined;
803
+ }
804
+ function getVirtualWorkspaceScheme(workspace) {
805
+ return getVirtualWorkspaceLocation(workspace)?.scheme;
806
+ }
807
+ const IRemoteAgentService = ( createDecorator('remoteAgentService'));
808
+ const IPathService = ( createDecorator('pathService'));
809
+ let AbstractPathService = class AbstractPathService {
810
+ constructor(localUserHome, remoteAgentService, environmentService, contextService) {
811
+ this.localUserHome = localUserHome;
812
+ this.remoteAgentService = remoteAgentService;
813
+ this.environmentService = environmentService;
814
+ this.contextService = contextService;
815
+ this.resolveOS = (async () => {
816
+ const env = await this.remoteAgentService.getEnvironment();
817
+ return env?.os || OS;
818
+ })();
819
+ this.resolveUserHome = (async () => {
820
+ const env = await this.remoteAgentService.getEnvironment();
821
+ const userHome = this.maybeUnresolvedUserHome = env?.userHome ?? localUserHome;
822
+ return userHome;
823
+ })();
824
+ }
825
+ hasValidBasename(resource, arg2, basename) {
826
+ if (typeof arg2 === 'string' || typeof arg2 === 'undefined') {
827
+ return this.resolveOS.then(os => this.doHasValidBasename(resource, os, arg2));
828
+ }
829
+ return this.doHasValidBasename(resource, arg2, basename);
830
+ }
831
+ doHasValidBasename(resource, os, name) {
832
+ if (resource.scheme === Schemas.file || resource.scheme === Schemas.vscodeRemote) {
833
+ return isValidBasename(name ?? basename(resource), os === 1 );
834
+ }
835
+ return true;
836
+ }
837
+ get defaultUriScheme() {
838
+ return AbstractPathService.findDefaultUriScheme(this.environmentService, this.contextService);
839
+ }
840
+ static findDefaultUriScheme(environmentService, contextService) {
841
+ if (environmentService.remoteAuthority) {
842
+ return Schemas.vscodeRemote;
843
+ }
844
+ const virtualWorkspace = getVirtualWorkspaceScheme(contextService.getWorkspace());
845
+ if (virtualWorkspace) {
846
+ return virtualWorkspace;
847
+ }
848
+ const firstFolder = contextService.getWorkspace().folders[0];
849
+ if (firstFolder) {
850
+ return firstFolder.uri.scheme;
851
+ }
852
+ const configuration = contextService.getWorkspace().configuration;
853
+ if (configuration) {
854
+ return configuration.scheme;
855
+ }
856
+ return Schemas.file;
857
+ }
858
+ userHome(options) {
859
+ return options?.preferLocal ? this.localUserHome : this.resolveUserHome;
860
+ }
861
+ get resolvedUserHome() {
862
+ return this.maybeUnresolvedUserHome;
863
+ }
864
+ get path() {
865
+ return this.resolveOS.then(os => {
866
+ return os === 1 ?
867
+ win32 :
868
+ posix;
869
+ });
870
+ }
871
+ async fileURI(_path) {
872
+ let authority = '';
873
+ const os = await this.resolveOS;
874
+ if (os === 1 ) {
875
+ _path = _path.replace(/\\/g, '/');
876
+ }
877
+ if (_path[0] === '/' && _path[1] === '/') {
878
+ const idx = _path.indexOf('/', 2);
879
+ if (idx === -1) {
880
+ authority = _path.substring(2);
881
+ _path = '/';
882
+ }
883
+ else {
884
+ authority = _path.substring(2, idx);
885
+ _path = _path.substring(idx) || '/';
886
+ }
887
+ }
888
+ return ( URI.from({
889
+ scheme: Schemas.file,
890
+ authority,
891
+ path: _path,
892
+ query: '',
893
+ fragment: ''
894
+ }));
895
+ }
896
+ };
897
+ AbstractPathService = ( __decorate([
898
+ ( __param(1, IRemoteAgentService)),
899
+ ( __param(2, IWorkbenchEnvironmentService)),
900
+ ( __param(3, IWorkspaceContextService))
901
+ ], AbstractPathService));
902
+ const IPaneCompositePartService = ( createDecorator('paneCompositePartService'));
903
+ const IProductService = ( createDecorator('productService'));
398
904
  const productSchemaId = 'vscode://schemas/vscode-product';
399
- const ILanguageStatusService = ( (createDecorator('ILanguageStatusService')));
400
- const IHostService = ( (createDecorator('hostService')));
401
- const ISnippetsService = ( (createDecorator('snippetService')));
905
+ const ILanguageStatusService = ( createDecorator('ILanguageStatusService'));
906
+ const IHostService = ( createDecorator('hostService'));
907
+ const ISnippetsService = ( createDecorator('snippetService'));
402
908
  let services;
403
909
  var Services;
404
- ( (function(Services) {
910
+ (function (Services) {
405
911
  Services.get = () => {
406
912
  return services ?? {};
407
913
  };
@@ -419,5 +925,5 @@ var Services;
419
925
  };
420
926
  }
421
927
  Services.install = install;
422
- })(Services || (Services = {})));
423
- export { ACTIVE_GROUP as A, FileChangesEvent as B, CancellationTokenSource as C, FileOperationError as D, hasOpenReadWriteCloseCapability as E, FileType as F, hasReadWriteCapability as G, hasFileReadStreamCapability as H, IFileService as I, toFileSystemProviderErrorCode as J, ensureFileSystemProviderError as K, etag as L, FileOperationEvent as M, NoOpNotification as N, toFileOperationResult as O, ETAG_DISABLED as P, hasFileAtomicReadCapability as Q, NotModifiedSinceFileOperationError as R, Services as S, hasFileFolderCopyCapability as T, hasFileCloneCapability as U, createFileSystemProviderError as V, index as W, flatten as X, FILES_ASSOCIATIONS_CONFIG as Y, FilePermission as a, IUriIdentityService as b, IEditorService as c, IPaneCompositePartService as d, ITextFileService as e, IEditorGroupsService as f, IWorkbenchEnvironmentService as g, IWorkingCopyFileService as h, IPathService as i, IProductService as j, ILanguageStatusService as k, IHostService as l, ISnippetsService as m, coalesceInPlace as n, markAsFileSystemProviderError as o, productSchemaId as p, FileSystemProviderErrorCode as q, refineServiceDecorator as r, shuffle as s, mapArrayOrNot as t, SIDE_GROUP as u, delta as v, NotificationsFilter as w, NeverShowAgainScope as x, isPreferredGroup as y, FileSystemProviderError as z };
928
+ })(Services || (Services = {}));
929
+ export { ACTIVE_GROUP as A, hasReadWriteCapability as B, CancellationTokenSource as C, hasFileReadStreamCapability as D, toFileSystemProviderErrorCode as E, FileType as F, etag as G, FileOperationEvent as H, ITextFileService as I, toFileOperationResult as J, ETAG_DISABLED as K, hasFileAtomicReadCapability as L, hasFileFolderCopyCapability as M, NotModifiedSinceFileOperationError as N, hasFileCloneCapability as O, FILES_ASSOCIATIONS_CONFIG as P, Services as S, FilePermission as a, FileSystemProviderErrorCode as b, SIDE_GROUP as c, IFileService as d, IWorkbenchEnvironmentService as e, IUriIdentityService as f, IWorkingCopyFileService as g, IPathService as h, IEditorService as i, IEditorGroupsService as j, IPaneCompositePartService as k, IProductService as l, markAsFileSystemProviderError as m, ILanguageStatusService as n, IHostService as o, FileOperationError as p, productSchemaId as q, refineServiceDecorator as r, IRemoteAgentService as s, ISnippetsService as t, isPreferredGroup as u, FileSystemProviderError as v, ensureFileSystemProviderError as w, createFileSystemProviderError as x, FileChangesEvent as y, hasOpenReadWriteCloseCapability as z };