@codingame/monaco-vscode-api 1.67.13 → 1.67.16

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,2069 @@
1
+ import { E as Emitter, i as isReadableStream, p as peekStream, b as peekReadable, c as bufferToReadable, s as streamToBuffer, d as consumeStream, t as transform, e as isReadableBufferedStream, l as listenStream, f as bufferedStreamToBuffer, r as readableToBuffer, n as newWriteableBufferStream, g as newWriteableStream, u as unsupported } from './missing-services-8687ea11.js';
2
+ import { Disposable, toDisposable, dispose, DisposableStore } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
3
+ import { Event } from 'monaco-editor/esm/vs/base/common/event.js';
4
+ import { getConfigurationValue, addToValueTree, removeFromValueTree, toValuesTree, IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
5
+ import { distinct, equals, coalesce } from 'monaco-editor/esm/vs/base/common/arrays.js';
6
+ import { deepClone, deepFreeze } from 'monaco-editor/esm/vs/base/common/objects.js';
7
+ import { isObject, isUndefinedOrNull } from 'monaco-editor/esm/vs/base/common/types.js';
8
+ import { OVERRIDE_PROPERTY_REGEX, overrideIdentifiersFromKey, Extensions } from 'monaco-editor/esm/vs/platform/configuration/common/configurationRegistry.js';
9
+ import { Registry } from 'monaco-editor/esm/vs/platform/registry/common/platform.js';
10
+ import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
11
+ import { extUriBiasedIgnorePathCase, isAbsolutePath, extUri, extUriIgnorePathCase } from 'monaco-editor/esm/vs/base/common/resources.js';
12
+ import { Configuration, DefaultConfigurationModel, ConfigurationModel as ConfigurationModel$1, ConfigurationChangeEvent } from 'monaco-editor/esm/vs/platform/configuration/common/configurationModels.js';
13
+ import { RunOnceScheduler, Promises } from 'monaco-editor/esm/vs/base/common/async.js';
14
+ import { E as ensureFileSystemProviderError, G as createFileSystemProviderError, F as FileSystemProviderErrorCode, H as FileChangesEvent, J as FileOperationError, K as hasOpenReadWriteCloseCapability, L as hasReadWriteCapability, M as hasFileReadStreamCapability, O as toFileSystemProviderErrorCode, w as FileType, x as FilePermission, P as etag, Q as FileOperationEvent, R as toFileOperationResult, T as ETAG_DISABLED, U as hasFileAtomicReadCapability, V as NotModifiedSinceFileOperationError, W as hasFileFolderCopyCapability, b as __decorate, d as __param, C as CancellationTokenSource } from './services-7a462d46.js';
15
+ import { VSBuffer } from 'monaco-editor/esm/vs/base/common/buffer.js';
16
+ import { canceled } from 'monaco-editor/esm/vs/base/common/errors.js';
17
+ import { localize } from 'monaco-editor/esm/vs/nls.js';
18
+ import { R as ResourceQueue } from './async-f842d13c.js';
19
+ import { Iterable } from 'monaco-editor/esm/vs/base/common/iterator.js';
20
+ import { TernarySearchTree } from 'monaco-editor/esm/vs/base/common/map.js';
21
+ import { hash } from 'monaco-editor/esm/vs/base/common/hash.js';
22
+ import { CancellationToken } from 'monaco-editor/esm/vs/base/common/cancellation.js';
23
+ import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
24
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
25
+ import { StandaloneServices } from 'monaco-editor/esm/vs/editor/standalone/browser/standaloneServices.js';
26
+ import 'monaco-editor/esm/vs/platform/theme/common/themeService.js';
27
+ import 'monaco-editor/esm/vs/base/browser/ui/progressbar/progressbar.js';
28
+ import 'monaco-editor/esm/vs/base/browser/dom.js';
29
+ import 'monaco-editor/esm/vs/base/common/color.js';
30
+ import 'monaco-editor/esm/vs/editor/common/services/languageService.js';
31
+ import 'monaco-editor/esm/vs/editor/common/services/languagesRegistry.js';
32
+ import 'monaco-editor/esm/vs/editor/common/languages/modesRegistry.js';
33
+ import 'monaco-editor/esm/vs/editor/common/languages.js';
34
+ import 'monaco-editor/esm/vs/platform/notification/common/notification.js';
35
+ import 'monaco-editor/esm/vs/base/parts/quickinput/browser/quickInput.js';
36
+ import 'monaco-editor/esm/vs/platform/instantiation/common/extensions.js';
37
+ import 'monaco-editor/esm/vs/platform/label/common/label.js';
38
+ import 'monaco-editor/esm/vs/editor/editor.api.js';
39
+ import 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
40
+ import 'monaco-editor/esm/vs/editor/common/languageFeatureRegistry.js';
41
+ import 'monaco-editor/esm/vs/base/common/strings.js';
42
+ import 'monaco-editor/esm/vs/base/browser/event.js';
43
+ import 'monaco-editor/esm/vs/platform/environment/common/environment.js';
44
+ import 'monaco-editor/esm/vs/base/common/platform.js';
45
+ import 'monaco-editor/esm/vs/platform/workspace/common/workspace.js';
46
+ import 'monaco-editor/esm/vs/base/common/path.js';
47
+ import 'monaco-editor/esm/vs/base/common/linkedList.js';
48
+ import 'monaco-editor/esm/vs/base/common/stopwatch.js';
49
+ import 'monaco-editor/esm/vs/platform/commands/common/commands.js';
50
+ import 'monaco-editor/esm/vs/editor/browser/services/bulkEditService.js';
51
+ import 'monaco-editor/esm/vs/editor/browser/services/codeEditorService.js';
52
+ import 'monaco-editor/esm/vs/editor/common/languages/language.js';
53
+ import 'monaco-editor/esm/vs/editor/common/languages/languageConfigurationRegistry.js';
54
+ import 'monaco-editor/esm/vs/editor/common/services/editorWorker.js';
55
+ import 'monaco-editor/esm/vs/editor/common/services/languageFeatures.js';
56
+ import 'monaco-editor/esm/vs/editor/common/services/model.js';
57
+ import 'monaco-editor/esm/vs/editor/common/services/resolverService.js';
58
+ import 'monaco-editor/esm/vs/platform/clipboard/common/clipboardService.js';
59
+ import 'monaco-editor/esm/vs/platform/dialogs/common/dialogs.js';
60
+ import 'monaco-editor/esm/vs/platform/markers/common/markers.js';
61
+ import 'monaco-editor/esm/vs/platform/opener/common/opener.js';
62
+ import 'monaco-editor/esm/vs/platform/quickinput/common/quickInput.js';
63
+ import 'monaco-editor/esm/vs/platform/telemetry/common/telemetry.js';
64
+ import 'monaco-editor/esm/vs/base/common/severity.js';
65
+ function isConfigurationOverrides(thing) {
66
+ return thing
67
+ && typeof thing === 'object'
68
+ && (!thing.overrideIdentifier || typeof thing.overrideIdentifier === 'string')
69
+ && (!thing.resource || thing.resource instanceof URI);
70
+ }
71
+ var ParseOptions;
72
+ (function(ParseOptions) {
73
+ ParseOptions.DEFAULT = {
74
+ allowTrailingComma: true
75
+ };
76
+ })(ParseOptions || (ParseOptions = {}));
77
+ function createScanner(text, ignoreTrivia = false) {
78
+ let pos = 0, len = text.length, value = '', tokenOffset = 0, token = 16 , scanError = 0 ;
79
+ function scanHexDigits(count) {
80
+ let digits = 0;
81
+ let hexValue = 0;
82
+ while (digits < count) {
83
+ const ch = text.charCodeAt(pos);
84
+ if (ch >= 48 && ch <= 57 ) {
85
+ hexValue = hexValue * 16 + ch - 48 ;
86
+ }
87
+ else if (ch >= 65 && ch <= 70 ) {
88
+ hexValue = hexValue * 16 + ch - 65 + 10;
89
+ }
90
+ else if (ch >= 97 && ch <= 102 ) {
91
+ hexValue = hexValue * 16 + ch - 97 + 10;
92
+ }
93
+ else {
94
+ break;
95
+ }
96
+ pos++;
97
+ digits++;
98
+ }
99
+ if (digits < count) {
100
+ hexValue = -1;
101
+ }
102
+ return hexValue;
103
+ }
104
+ function setPosition(newPosition) {
105
+ pos = newPosition;
106
+ value = '';
107
+ tokenOffset = 0;
108
+ token = 16 ;
109
+ scanError = 0 ;
110
+ }
111
+ function scanNumber() {
112
+ const start = pos;
113
+ if (text.charCodeAt(pos) === 48 ) {
114
+ pos++;
115
+ }
116
+ else {
117
+ pos++;
118
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
119
+ pos++;
120
+ }
121
+ }
122
+ if (pos < text.length && text.charCodeAt(pos) === 46 ) {
123
+ pos++;
124
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
125
+ pos++;
126
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
127
+ pos++;
128
+ }
129
+ }
130
+ else {
131
+ scanError = 3 ;
132
+ return text.substring(start, pos);
133
+ }
134
+ }
135
+ let end = pos;
136
+ if (pos < text.length && ((text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101) )) {
137
+ pos++;
138
+ if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45 ) {
139
+ pos++;
140
+ }
141
+ if (pos < text.length && isDigit(text.charCodeAt(pos))) {
142
+ pos++;
143
+ while (pos < text.length && isDigit(text.charCodeAt(pos))) {
144
+ pos++;
145
+ }
146
+ end = pos;
147
+ }
148
+ else {
149
+ scanError = 3 ;
150
+ }
151
+ }
152
+ return text.substring(start, end);
153
+ }
154
+ function scanString() {
155
+ let result = '', start = pos;
156
+ while (true) {
157
+ if (pos >= len) {
158
+ result += text.substring(start, pos);
159
+ scanError = 2 ;
160
+ break;
161
+ }
162
+ const ch = text.charCodeAt(pos);
163
+ if (ch === 34 ) {
164
+ result += text.substring(start, pos);
165
+ pos++;
166
+ break;
167
+ }
168
+ if (ch === 92 ) {
169
+ result += text.substring(start, pos);
170
+ pos++;
171
+ if (pos >= len) {
172
+ scanError = 2 ;
173
+ break;
174
+ }
175
+ const ch2 = text.charCodeAt(pos++);
176
+ switch (ch2) {
177
+ case 34 :
178
+ result += '\"';
179
+ break;
180
+ case 92 :
181
+ result += '\\';
182
+ break;
183
+ case 47 :
184
+ result += '/';
185
+ break;
186
+ case 98 :
187
+ result += '\b';
188
+ break;
189
+ case 102 :
190
+ result += '\f';
191
+ break;
192
+ case 110 :
193
+ result += '\n';
194
+ break;
195
+ case 114 :
196
+ result += '\r';
197
+ break;
198
+ case 116 :
199
+ result += '\t';
200
+ break;
201
+ case 117 : {
202
+ const ch3 = scanHexDigits(4);
203
+ if (ch3 >= 0) {
204
+ result += String.fromCharCode(ch3);
205
+ }
206
+ else {
207
+ scanError = 4 ;
208
+ }
209
+ break;
210
+ }
211
+ default:
212
+ scanError = 5 ;
213
+ }
214
+ start = pos;
215
+ continue;
216
+ }
217
+ if (ch >= 0 && ch <= 0x1F) {
218
+ if (isLineBreak(ch)) {
219
+ result += text.substring(start, pos);
220
+ scanError = 2 ;
221
+ break;
222
+ }
223
+ else {
224
+ scanError = 6 ;
225
+ }
226
+ }
227
+ pos++;
228
+ }
229
+ return result;
230
+ }
231
+ function scanNext() {
232
+ value = '';
233
+ scanError = 0 ;
234
+ tokenOffset = pos;
235
+ if (pos >= len) {
236
+ tokenOffset = len;
237
+ return token = 17 ;
238
+ }
239
+ let code = text.charCodeAt(pos);
240
+ if (isWhitespace(code)) {
241
+ do {
242
+ pos++;
243
+ value += String.fromCharCode(code);
244
+ code = text.charCodeAt(pos);
245
+ } while (isWhitespace(code));
246
+ return token = 15 ;
247
+ }
248
+ if (isLineBreak(code)) {
249
+ pos++;
250
+ value += String.fromCharCode(code);
251
+ if (code === 13 && text.charCodeAt(pos) === 10 ) {
252
+ pos++;
253
+ value += '\n';
254
+ }
255
+ return token = 14 ;
256
+ }
257
+ switch (code) {
258
+ case 123 :
259
+ pos++;
260
+ return token = 1 ;
261
+ case 125 :
262
+ pos++;
263
+ return token = 2 ;
264
+ case 91 :
265
+ pos++;
266
+ return token = 3 ;
267
+ case 93 :
268
+ pos++;
269
+ return token = 4 ;
270
+ case 58 :
271
+ pos++;
272
+ return token = 6 ;
273
+ case 44 :
274
+ pos++;
275
+ return token = 5 ;
276
+ case 34 :
277
+ pos++;
278
+ value = scanString();
279
+ return token = 10 ;
280
+ case 47 : {
281
+ const start = pos - 1;
282
+ if (text.charCodeAt(pos + 1) === 47 ) {
283
+ pos += 2;
284
+ while (pos < len) {
285
+ if (isLineBreak(text.charCodeAt(pos))) {
286
+ break;
287
+ }
288
+ pos++;
289
+ }
290
+ value = text.substring(start, pos);
291
+ return token = 12 ;
292
+ }
293
+ if (text.charCodeAt(pos + 1) === 42 ) {
294
+ pos += 2;
295
+ const safeLength = len - 1;
296
+ let commentClosed = false;
297
+ while (pos < safeLength) {
298
+ const ch = text.charCodeAt(pos);
299
+ if (ch === 42 && text.charCodeAt(pos + 1) === 47 ) {
300
+ pos += 2;
301
+ commentClosed = true;
302
+ break;
303
+ }
304
+ pos++;
305
+ }
306
+ if (!commentClosed) {
307
+ pos++;
308
+ scanError = 1 ;
309
+ }
310
+ value = text.substring(start, pos);
311
+ return token = 13 ;
312
+ }
313
+ value += String.fromCharCode(code);
314
+ pos++;
315
+ return token = 16 ;
316
+ }
317
+ case 45 :
318
+ value += String.fromCharCode(code);
319
+ pos++;
320
+ if (pos === len || !isDigit(text.charCodeAt(pos))) {
321
+ return token = 16 ;
322
+ }
323
+ case 48 :
324
+ case 49 :
325
+ case 50 :
326
+ case 51 :
327
+ case 52 :
328
+ case 53 :
329
+ case 54 :
330
+ case 55 :
331
+ case 56 :
332
+ case 57 :
333
+ value += scanNumber();
334
+ return token = 11 ;
335
+ default:
336
+ while (pos < len && isUnknownContentCharacter(code)) {
337
+ pos++;
338
+ code = text.charCodeAt(pos);
339
+ }
340
+ if (tokenOffset !== pos) {
341
+ value = text.substring(tokenOffset, pos);
342
+ switch (value) {
343
+ case 'true': return token = 8 ;
344
+ case 'false': return token = 9 ;
345
+ case 'null': return token = 7 ;
346
+ }
347
+ return token = 16 ;
348
+ }
349
+ value += String.fromCharCode(code);
350
+ pos++;
351
+ return token = 16 ;
352
+ }
353
+ }
354
+ function isUnknownContentCharacter(code) {
355
+ if (isWhitespace(code) || isLineBreak(code)) {
356
+ return false;
357
+ }
358
+ switch (code) {
359
+ case 125 :
360
+ case 93 :
361
+ case 123 :
362
+ case 91 :
363
+ case 34 :
364
+ case 58 :
365
+ case 44 :
366
+ case 47 :
367
+ return false;
368
+ }
369
+ return true;
370
+ }
371
+ function scanNextNonTrivia() {
372
+ let result;
373
+ do {
374
+ result = scanNext();
375
+ } while (result >= 12 && result <= 15 );
376
+ return result;
377
+ }
378
+ return {
379
+ setPosition: setPosition,
380
+ getPosition: () => pos,
381
+ scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
382
+ getToken: () => token,
383
+ getTokenValue: () => value,
384
+ getTokenOffset: () => tokenOffset,
385
+ getTokenLength: () => pos - tokenOffset,
386
+ getTokenError: () => scanError
387
+ };
388
+ }
389
+ function isWhitespace(ch) {
390
+ return ch === 32 || ch === 9 || ch === 11 || ch === 12 ||
391
+ ch === 160 || ch === 5760 || ch >= 8192 && ch <= 8203 ||
392
+ ch === 8239 || ch === 8287 || ch === 12288 || ch === 65279 ;
393
+ }
394
+ function isLineBreak(ch) {
395
+ return ch === 10 || ch === 13 || ch === 8232 || ch === 8233 ;
396
+ }
397
+ function isDigit(ch) {
398
+ return ch >= 48 && ch <= 57 ;
399
+ }
400
+ function visit(text, visitor, options = ParseOptions.DEFAULT) {
401
+ const _scanner = createScanner(text, false);
402
+ function toNoArgVisit(visitFunction) {
403
+ return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength()) : () => true;
404
+ }
405
+ function toOneArgVisit(visitFunction) {
406
+ return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength()) : () => true;
407
+ }
408
+ const onObjectBegin = toNoArgVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisit(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisit(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisit(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
409
+ const disallowComments = options && options.disallowComments;
410
+ const allowTrailingComma = options && options.allowTrailingComma;
411
+ function scanNext() {
412
+ while (true) {
413
+ const token = _scanner.scan();
414
+ switch (_scanner.getTokenError()) {
415
+ case 4 :
416
+ handleError(14 );
417
+ break;
418
+ case 5 :
419
+ handleError(15 );
420
+ break;
421
+ case 3 :
422
+ handleError(13 );
423
+ break;
424
+ case 1 :
425
+ if (!disallowComments) {
426
+ handleError(11 );
427
+ }
428
+ break;
429
+ case 2 :
430
+ handleError(12 );
431
+ break;
432
+ case 6 :
433
+ handleError(16 );
434
+ break;
435
+ }
436
+ switch (token) {
437
+ case 12 :
438
+ case 13 :
439
+ if (disallowComments) {
440
+ handleError(10 );
441
+ }
442
+ else {
443
+ onComment();
444
+ }
445
+ break;
446
+ case 16 :
447
+ handleError(1 );
448
+ break;
449
+ case 15 :
450
+ case 14 :
451
+ break;
452
+ default:
453
+ return token;
454
+ }
455
+ }
456
+ }
457
+ function handleError(error, skipUntilAfter = [], skipUntil = []) {
458
+ onError(error);
459
+ if (skipUntilAfter.length + skipUntil.length > 0) {
460
+ let token = _scanner.getToken();
461
+ while (token !== 17 ) {
462
+ if (skipUntilAfter.indexOf(token) !== -1) {
463
+ scanNext();
464
+ break;
465
+ }
466
+ else if (skipUntil.indexOf(token) !== -1) {
467
+ break;
468
+ }
469
+ token = scanNext();
470
+ }
471
+ }
472
+ }
473
+ function parseString(isValue) {
474
+ const value = _scanner.getTokenValue();
475
+ if (isValue) {
476
+ onLiteralValue(value);
477
+ }
478
+ else {
479
+ onObjectProperty(value);
480
+ }
481
+ scanNext();
482
+ return true;
483
+ }
484
+ function parseLiteral() {
485
+ switch (_scanner.getToken()) {
486
+ case 11 : {
487
+ let value = 0;
488
+ try {
489
+ value = JSON.parse(_scanner.getTokenValue());
490
+ if (typeof value !== 'number') {
491
+ handleError(2 );
492
+ value = 0;
493
+ }
494
+ }
495
+ catch (e) {
496
+ handleError(2 );
497
+ }
498
+ onLiteralValue(value);
499
+ break;
500
+ }
501
+ case 7 :
502
+ onLiteralValue(null);
503
+ break;
504
+ case 8 :
505
+ onLiteralValue(true);
506
+ break;
507
+ case 9 :
508
+ onLiteralValue(false);
509
+ break;
510
+ default:
511
+ return false;
512
+ }
513
+ scanNext();
514
+ return true;
515
+ }
516
+ function parseProperty() {
517
+ if (_scanner.getToken() !== 10 ) {
518
+ handleError(3 , [], [2 , 5 ]);
519
+ return false;
520
+ }
521
+ parseString(false);
522
+ if (_scanner.getToken() === 6 ) {
523
+ onSeparator(':');
524
+ scanNext();
525
+ if (!parseValue()) {
526
+ handleError(4 , [], [2 , 5 ]);
527
+ }
528
+ }
529
+ else {
530
+ handleError(5 , [], [2 , 5 ]);
531
+ }
532
+ return true;
533
+ }
534
+ function parseObject() {
535
+ onObjectBegin();
536
+ scanNext();
537
+ let needsComma = false;
538
+ while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17 ) {
539
+ if (_scanner.getToken() === 5 ) {
540
+ if (!needsComma) {
541
+ handleError(4 , [], []);
542
+ }
543
+ onSeparator(',');
544
+ scanNext();
545
+ if (_scanner.getToken() === 2 && allowTrailingComma) {
546
+ break;
547
+ }
548
+ }
549
+ else if (needsComma) {
550
+ handleError(6 , [], []);
551
+ }
552
+ if (!parseProperty()) {
553
+ handleError(4 , [], [2 , 5 ]);
554
+ }
555
+ needsComma = true;
556
+ }
557
+ onObjectEnd();
558
+ if (_scanner.getToken() !== 2 ) {
559
+ handleError(7 , [2 ], []);
560
+ }
561
+ else {
562
+ scanNext();
563
+ }
564
+ return true;
565
+ }
566
+ function parseArray() {
567
+ onArrayBegin();
568
+ scanNext();
569
+ let needsComma = false;
570
+ while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17 ) {
571
+ if (_scanner.getToken() === 5 ) {
572
+ if (!needsComma) {
573
+ handleError(4 , [], []);
574
+ }
575
+ onSeparator(',');
576
+ scanNext();
577
+ if (_scanner.getToken() === 4 && allowTrailingComma) {
578
+ break;
579
+ }
580
+ }
581
+ else if (needsComma) {
582
+ handleError(6 , [], []);
583
+ }
584
+ if (!parseValue()) {
585
+ handleError(4 , [], [4 , 5 ]);
586
+ }
587
+ needsComma = true;
588
+ }
589
+ onArrayEnd();
590
+ if (_scanner.getToken() !== 4 ) {
591
+ handleError(8 , [4 ], []);
592
+ }
593
+ else {
594
+ scanNext();
595
+ }
596
+ return true;
597
+ }
598
+ function parseValue() {
599
+ switch (_scanner.getToken()) {
600
+ case 3 :
601
+ return parseArray();
602
+ case 1 :
603
+ return parseObject();
604
+ case 10 :
605
+ return parseString(true);
606
+ default:
607
+ return parseLiteral();
608
+ }
609
+ }
610
+ scanNext();
611
+ if (_scanner.getToken() === 17 ) {
612
+ if (options.allowEmptyContent) {
613
+ return true;
614
+ }
615
+ handleError(4 , [], []);
616
+ return false;
617
+ }
618
+ if (!parseValue()) {
619
+ handleError(4 , [], []);
620
+ return false;
621
+ }
622
+ if (_scanner.getToken() !== 17 ) {
623
+ handleError(9 , [], []);
624
+ }
625
+ return true;
626
+ }
627
+ class ConfigurationModel {
628
+ constructor(_contents = {}, _keys = [], _overrides = []) {
629
+ this._contents = _contents;
630
+ this._keys = _keys;
631
+ this._overrides = _overrides;
632
+ this.isFrozen = false;
633
+ this.overrideConfigurations = new Map();
634
+ }
635
+ get contents() {
636
+ return this.checkAndFreeze(this._contents);
637
+ }
638
+ get overrides() {
639
+ return this.checkAndFreeze(this._overrides);
640
+ }
641
+ get keys() {
642
+ return this.checkAndFreeze(this._keys);
643
+ }
644
+ isEmpty() {
645
+ return this._keys.length === 0 && Object.keys(this._contents).length === 0 && this._overrides.length === 0;
646
+ }
647
+ getValue(section) {
648
+ return section ? getConfigurationValue(this.contents, section) : this.contents;
649
+ }
650
+ getOverrideValue(section, overrideIdentifier) {
651
+ const overrideContents = this.getContentsForOverrideIdentifer(overrideIdentifier);
652
+ return overrideContents
653
+ ? section ? getConfigurationValue(overrideContents, section) : overrideContents
654
+ : undefined;
655
+ }
656
+ getKeysForOverrideIdentifier(identifier) {
657
+ const keys = [];
658
+ for (const override of this.overrides) {
659
+ if (override.identifiers.includes(identifier)) {
660
+ keys.push(...override.keys);
661
+ }
662
+ }
663
+ return distinct(keys);
664
+ }
665
+ getAllOverrideIdentifiers() {
666
+ const result = [];
667
+ for (const override of this.overrides) {
668
+ result.push(...override.identifiers);
669
+ }
670
+ return distinct(result);
671
+ }
672
+ override(identifier) {
673
+ let overrideConfigurationModel = this.overrideConfigurations.get(identifier);
674
+ if (!overrideConfigurationModel) {
675
+ overrideConfigurationModel = this.createOverrideConfigurationModel(identifier);
676
+ this.overrideConfigurations.set(identifier, overrideConfigurationModel);
677
+ }
678
+ return overrideConfigurationModel;
679
+ }
680
+ merge(...others) {
681
+ const contents = deepClone(this.contents);
682
+ const overrides = deepClone(this.overrides);
683
+ const keys = [...this.keys];
684
+ for (const other of others) {
685
+ this.mergeContents(contents, other.contents);
686
+ for (const otherOverride of other.overrides) {
687
+ const [override] = overrides.filter(o => equals(o.identifiers, otherOverride.identifiers));
688
+ if (override) {
689
+ this.mergeContents(override.contents, otherOverride.contents);
690
+ override.keys.push(...otherOverride.keys);
691
+ override.keys = distinct(override.keys);
692
+ }
693
+ else {
694
+ overrides.push(deepClone(otherOverride));
695
+ }
696
+ }
697
+ for (const key of other.keys) {
698
+ if (keys.indexOf(key) === -1) {
699
+ keys.push(key);
700
+ }
701
+ }
702
+ }
703
+ return (
704
+ new ConfigurationModel(contents, keys, overrides)
705
+ );
706
+ }
707
+ freeze() {
708
+ this.isFrozen = true;
709
+ return this;
710
+ }
711
+ createOverrideConfigurationModel(identifier) {
712
+ const overrideContents = this.getContentsForOverrideIdentifer(identifier);
713
+ if (!overrideContents || typeof overrideContents !== 'object' || !Object.keys(overrideContents).length) {
714
+ return this;
715
+ }
716
+ let contents = {};
717
+ for (const key of distinct([...Object.keys(this.contents), ...Object.keys(overrideContents)])) {
718
+ let contentsForKey = this.contents[key];
719
+ let overrideContentsForKey = overrideContents[key];
720
+ if (overrideContentsForKey) {
721
+ if (typeof contentsForKey === 'object' && typeof overrideContentsForKey === 'object') {
722
+ contentsForKey = deepClone(contentsForKey);
723
+ this.mergeContents(contentsForKey, overrideContentsForKey);
724
+ }
725
+ else {
726
+ contentsForKey = overrideContentsForKey;
727
+ }
728
+ }
729
+ contents[key] = contentsForKey;
730
+ }
731
+ return (
732
+ new ConfigurationModel(contents, this.keys, this.overrides)
733
+ );
734
+ }
735
+ mergeContents(source, target) {
736
+ for (const key of Object.keys(target)) {
737
+ if (key in source) {
738
+ if (isObject(source[key]) && isObject(target[key])) {
739
+ this.mergeContents(source[key], target[key]);
740
+ continue;
741
+ }
742
+ }
743
+ source[key] = deepClone(target[key]);
744
+ }
745
+ }
746
+ checkAndFreeze(data) {
747
+ if (this.isFrozen && !Object.isFrozen(data)) {
748
+ return deepFreeze(data);
749
+ }
750
+ return data;
751
+ }
752
+ getContentsForOverrideIdentifer(identifier) {
753
+ let contentsForIdentifierOnly = null;
754
+ let contents = null;
755
+ const mergeContents = (contentsToMerge) => {
756
+ if (contentsToMerge) {
757
+ if (contents) {
758
+ this.mergeContents(contents, contentsToMerge);
759
+ }
760
+ else {
761
+ contents = deepClone(contentsToMerge);
762
+ }
763
+ }
764
+ };
765
+ for (const override of this.overrides) {
766
+ if (equals(override.identifiers, [identifier])) {
767
+ contentsForIdentifierOnly = override.contents;
768
+ }
769
+ else if (override.identifiers.includes(identifier)) {
770
+ mergeContents(override.contents);
771
+ }
772
+ }
773
+ mergeContents(contentsForIdentifierOnly);
774
+ return contents;
775
+ }
776
+ toJSON() {
777
+ return {
778
+ contents: this.contents,
779
+ overrides: this.overrides,
780
+ keys: this.keys
781
+ };
782
+ }
783
+ setValue(key, value) {
784
+ this.addKey(key);
785
+ addToValueTree(this.contents, key, value, e => { throw new Error(e); });
786
+ }
787
+ removeValue(key) {
788
+ if (this.removeKey(key)) {
789
+ removeFromValueTree(this.contents, key);
790
+ }
791
+ }
792
+ addKey(key) {
793
+ let index = this.keys.length;
794
+ for (let i = 0; i < index; i++) {
795
+ if (key.indexOf(this.keys[i]) === 0) {
796
+ index = i;
797
+ }
798
+ }
799
+ this.keys.splice(index, 1, key);
800
+ }
801
+ removeKey(key) {
802
+ let index = this.keys.indexOf(key);
803
+ if (index !== -1) {
804
+ this.keys.splice(index, 1);
805
+ return true;
806
+ }
807
+ return false;
808
+ }
809
+ }
810
+ class ConfigurationModelParser {
811
+ constructor(_name) {
812
+ this._name = _name;
813
+ this._raw = null;
814
+ this._configurationModel = null;
815
+ this._restrictedConfigurations = [];
816
+ this._parseErrors = [];
817
+ }
818
+ get configurationModel() {
819
+ return this._configurationModel || new ConfigurationModel();
820
+ }
821
+ get restrictedConfigurations() {
822
+ return this._restrictedConfigurations;
823
+ }
824
+ get errors() {
825
+ return this._parseErrors;
826
+ }
827
+ parse(content, options) {
828
+ if (!isUndefinedOrNull(content)) {
829
+ const raw = this.doParseContent(content);
830
+ this.parseRaw(raw, options);
831
+ }
832
+ }
833
+ reparse(options) {
834
+ if (this._raw) {
835
+ this.parseRaw(this._raw, options);
836
+ }
837
+ }
838
+ parseRaw(raw, options) {
839
+ this._raw = raw;
840
+ const { contents, keys, overrides, restricted } = this.doParseRaw(raw, options);
841
+ this._configurationModel = new ConfigurationModel(contents, keys, overrides);
842
+ this._restrictedConfigurations = restricted || [];
843
+ }
844
+ doParseContent(content) {
845
+ let raw = {};
846
+ let currentProperty = null;
847
+ let currentParent = [];
848
+ let previousParents = [];
849
+ function onValue(value) {
850
+ if (Array.isArray(currentParent)) {
851
+ currentParent.push(value);
852
+ }
853
+ else if (currentProperty !== null) {
854
+ currentParent[currentProperty] = value;
855
+ }
856
+ }
857
+ let visitor = {
858
+ onObjectBegin: () => {
859
+ let object = {};
860
+ onValue(object);
861
+ previousParents.push(currentParent);
862
+ currentParent = object;
863
+ currentProperty = null;
864
+ },
865
+ onObjectProperty: (name) => {
866
+ currentProperty = name;
867
+ },
868
+ onObjectEnd: () => {
869
+ currentParent = previousParents.pop();
870
+ },
871
+ onArrayBegin: () => {
872
+ let array = [];
873
+ onValue(array);
874
+ previousParents.push(currentParent);
875
+ currentParent = array;
876
+ currentProperty = null;
877
+ },
878
+ onArrayEnd: () => {
879
+ currentParent = previousParents.pop();
880
+ },
881
+ onLiteralValue: onValue,
882
+ onError: (error, offset, length) => {
883
+ }
884
+ };
885
+ if (content) {
886
+ try {
887
+ visit(content, visitor);
888
+ raw = currentParent[0] || {};
889
+ }
890
+ catch (e) {
891
+ console.error(`Error while parsing settings file ${this._name}: ${e}`);
892
+ this._parseErrors = [e];
893
+ }
894
+ }
895
+ return raw;
896
+ }
897
+ doParseRaw(raw, options) {
898
+ const configurationProperties = Registry.as(Extensions.Configuration).getConfigurationProperties();
899
+ const filtered = this.filter(raw, configurationProperties, true, options);
900
+ raw = filtered.raw;
901
+ const contents = toValuesTree(raw, message => console.error(`Conflict in settings file ${this._name}: ${message}`));
902
+ const keys = Object.keys(raw);
903
+ const overrides = this.toOverrides(raw, message => console.error(`Conflict in settings file ${this._name}: ${message}`));
904
+ return { contents, keys, overrides, restricted: filtered.restricted };
905
+ }
906
+ filter(properties, configurationProperties, filterOverriddenProperties, options) {
907
+ if (!options?.scopes && !options?.skipRestricted) {
908
+ return { raw: properties, restricted: [] };
909
+ }
910
+ const raw = {};
911
+ const restricted = [];
912
+ for (let key in properties) {
913
+ if (OVERRIDE_PROPERTY_REGEX.test(key) && filterOverriddenProperties) {
914
+ const result = this.filter(properties[key], configurationProperties, false, options);
915
+ raw[key] = result.raw;
916
+ restricted.push(...result.restricted);
917
+ }
918
+ else {
919
+ const propertySchema = configurationProperties[key];
920
+ const scope = propertySchema ? typeof propertySchema.scope !== 'undefined' ? propertySchema.scope : 3 : undefined;
921
+ if (propertySchema?.restricted) {
922
+ restricted.push(key);
923
+ }
924
+ if (scope === undefined || options.scopes === undefined || options.scopes.includes(scope)) {
925
+ if (!(options.skipRestricted && propertySchema?.restricted)) {
926
+ raw[key] = properties[key];
927
+ }
928
+ }
929
+ }
930
+ }
931
+ return { raw, restricted };
932
+ }
933
+ toOverrides(raw, conflictReporter) {
934
+ const overrides = [];
935
+ for (const key of Object.keys(raw)) {
936
+ if (OVERRIDE_PROPERTY_REGEX.test(key)) {
937
+ const overrideRaw = {};
938
+ for (const keyInOverrideRaw in raw[key]) {
939
+ overrideRaw[keyInOverrideRaw] = raw[key][keyInOverrideRaw];
940
+ }
941
+ overrides.push({
942
+ identifiers: overrideIdentifiersFromKey(key),
943
+ keys: Object.keys(overrideRaw),
944
+ contents: toValuesTree(overrideRaw, conflictReporter)
945
+ });
946
+ }
947
+ }
948
+ return overrides;
949
+ }
950
+ }
951
+ class UserSettings extends Disposable {
952
+ constructor(userSettingsResource, scopes, extUri, fileService) {
953
+ super();
954
+ this.userSettingsResource = userSettingsResource;
955
+ this.scopes = scopes;
956
+ this.fileService = fileService;
957
+ this._onDidChange = this._register( new Emitter());
958
+ this.onDidChange = this._onDidChange.event;
959
+ this.parser = new ConfigurationModelParser(this.userSettingsResource.toString());
960
+ this.parseOptions = { scopes: this.scopes };
961
+ this._register(this.fileService.watch(extUri.dirname(this.userSettingsResource)));
962
+ this._register(this.fileService.watch(this.userSettingsResource));
963
+ this._register(Event.any(Event.filter(this.fileService.onDidFilesChange, e => e.contains(this.userSettingsResource)), Event.filter(this.fileService.onDidRunOperation, e => (e.isOperation(0 ) || e.isOperation(1 ) || e.isOperation(4 )) && extUri.isEqual(e.resource, userSettingsResource)))(() => this._onDidChange.fire()));
964
+ }
965
+ async loadConfiguration() {
966
+ try {
967
+ const content = await this.fileService.readFile(this.userSettingsResource);
968
+ this.parser.parse(content.value.toString() || '{}', this.parseOptions);
969
+ return this.parser.configurationModel;
970
+ }
971
+ catch (e) {
972
+ return (
973
+ new ConfigurationModel()
974
+ );
975
+ }
976
+ }
977
+ reparse() {
978
+ this.parser.reparse(this.parseOptions);
979
+ return this.parser.configurationModel;
980
+ }
981
+ getRestrictedSettings() {
982
+ return this.parser.restrictedConfigurations;
983
+ }
984
+ }
985
+ class ConfigurationService extends Disposable {
986
+ constructor(settingsResource, fileService) {
987
+ super();
988
+ this.settingsResource = settingsResource;
989
+ this._onDidChangeConfiguration = this._register( new Emitter());
990
+ this.onDidChangeConfiguration = this._onDidChangeConfiguration.event;
991
+ this.userConfiguration = this._register( new UserSettings(this.settingsResource, undefined, extUriBiasedIgnorePathCase, fileService));
992
+ this.configuration = new Configuration( new DefaultConfigurationModel(), new ConfigurationModel$1());
993
+ this.reloadConfigurationScheduler = this._register( new RunOnceScheduler(() => this.reloadConfiguration(), 50));
994
+ this._register( Registry.as(Extensions.Configuration).onDidUpdateConfiguration(({ properties }) => this.onDidDefaultConfigurationChange(properties)));
995
+ this._register(this.userConfiguration.onDidChange(() => this.reloadConfigurationScheduler.schedule()));
996
+ }
997
+ async initialize() {
998
+ const userConfiguration = await this.userConfiguration.loadConfiguration();
999
+ this.configuration = new Configuration( new DefaultConfigurationModel(), userConfiguration);
1000
+ }
1001
+ getConfigurationData() {
1002
+ return this.configuration.toData();
1003
+ }
1004
+ getValue(arg1, arg2) {
1005
+ const section = typeof arg1 === 'string' ? arg1 : undefined;
1006
+ const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
1007
+ return this.configuration.getValue(section, overrides, undefined);
1008
+ }
1009
+ updateValue(key, value, arg3, arg4) {
1010
+ return Promise.reject( new Error('not supported'));
1011
+ }
1012
+ inspect(key) {
1013
+ return this.configuration.inspect(key, {}, undefined);
1014
+ }
1015
+ keys() {
1016
+ return this.configuration.keys(undefined);
1017
+ }
1018
+ async reloadConfiguration() {
1019
+ const configurationModel = await this.userConfiguration.loadConfiguration();
1020
+ this.onDidChangeUserConfiguration(configurationModel);
1021
+ }
1022
+ onDidChangeUserConfiguration(userConfigurationModel) {
1023
+ const previous = this.configuration.toData();
1024
+ const change = this.configuration.compareAndUpdateLocalUserConfiguration(userConfigurationModel);
1025
+ this.trigger(change, previous, 1 );
1026
+ }
1027
+ onDidDefaultConfigurationChange(properties) {
1028
+ const previous = this.configuration.toData();
1029
+ const change = this.configuration.compareAndUpdateDefaultConfiguration( new DefaultConfigurationModel(), properties);
1030
+ this.trigger(change, previous, 6 );
1031
+ }
1032
+ trigger(configurationChange, previous, source) {
1033
+ const event = new ConfigurationChangeEvent(configurationChange, { data: previous }, this.configuration);
1034
+ event.source = source;
1035
+ event.sourceConfig = this.getTargetConfiguration(source);
1036
+ this._onDidChangeConfiguration.fire(event);
1037
+ }
1038
+ getTargetConfiguration(target) {
1039
+ switch (target) {
1040
+ case 6 :
1041
+ return this.configuration.defaults.contents;
1042
+ case 1 :
1043
+ return this.configuration.localUserConfiguration.contents;
1044
+ }
1045
+ return {};
1046
+ }
1047
+ }
1048
+ async function readFileIntoStream(provider, resource, target, transformer, options, token) {
1049
+ let error = undefined;
1050
+ try {
1051
+ await doReadFileIntoStream(provider, resource, target, transformer, options, token);
1052
+ }
1053
+ catch (err) {
1054
+ error = err;
1055
+ }
1056
+ finally {
1057
+ if (error && options.errorTransformer) {
1058
+ error = options.errorTransformer(error);
1059
+ }
1060
+ if (typeof error !== 'undefined') {
1061
+ target.error(error);
1062
+ }
1063
+ target.end();
1064
+ }
1065
+ }
1066
+ async function doReadFileIntoStream(provider, resource, target, transformer, options, token) {
1067
+ throwIfCancelled(token);
1068
+ const handle = await provider.open(resource, { create: false });
1069
+ try {
1070
+ throwIfCancelled(token);
1071
+ let totalBytesRead = 0;
1072
+ let bytesRead = 0;
1073
+ let allowedRemainingBytes = (options && typeof options.length === 'number') ? options.length : undefined;
1074
+ let buffer = VSBuffer.alloc(Math.min(options.bufferSize, typeof allowedRemainingBytes === 'number' ? allowedRemainingBytes : options.bufferSize));
1075
+ let posInFile = options && typeof options.position === 'number' ? options.position : 0;
1076
+ let posInBuffer = 0;
1077
+ do {
1078
+ bytesRead = await provider.read(handle, posInFile, buffer.buffer, posInBuffer, buffer.byteLength - posInBuffer);
1079
+ posInFile += bytesRead;
1080
+ posInBuffer += bytesRead;
1081
+ totalBytesRead += bytesRead;
1082
+ if (typeof allowedRemainingBytes === 'number') {
1083
+ allowedRemainingBytes -= bytesRead;
1084
+ }
1085
+ if (posInBuffer === buffer.byteLength) {
1086
+ await target.write(transformer(buffer));
1087
+ buffer = VSBuffer.alloc(Math.min(options.bufferSize, typeof allowedRemainingBytes === 'number' ? allowedRemainingBytes : options.bufferSize));
1088
+ posInBuffer = 0;
1089
+ }
1090
+ } while (bytesRead > 0 && (typeof allowedRemainingBytes !== 'number' || allowedRemainingBytes > 0) && throwIfCancelled(token) && throwIfTooLarge(totalBytesRead, options));
1091
+ if (posInBuffer > 0) {
1092
+ let lastChunkLength = posInBuffer;
1093
+ if (typeof allowedRemainingBytes === 'number') {
1094
+ lastChunkLength = Math.min(posInBuffer, allowedRemainingBytes);
1095
+ }
1096
+ target.write(transformer(buffer.slice(0, lastChunkLength)));
1097
+ }
1098
+ }
1099
+ catch (error) {
1100
+ throw ensureFileSystemProviderError(error);
1101
+ }
1102
+ finally {
1103
+ await provider.close(handle);
1104
+ }
1105
+ }
1106
+ function throwIfCancelled(token) {
1107
+ if (token.isCancellationRequested) {
1108
+ throw canceled();
1109
+ }
1110
+ return true;
1111
+ }
1112
+ function throwIfTooLarge(totalBytesRead, options) {
1113
+ if (options?.limits) {
1114
+ if (typeof options.limits.memory === 'number' && totalBytesRead > options.limits.memory) {
1115
+ throw createFileSystemProviderError(localize('fileTooLargeForHeapError', "To open a file of this size, you need to restart and allow to use more memory"), FileSystemProviderErrorCode.FileExceedsMemoryLimit);
1116
+ }
1117
+ if (typeof options.limits.size === 'number' && totalBytesRead > options.limits.size) {
1118
+ throw createFileSystemProviderError(localize('fileTooLargeError', "File is too large to open"), FileSystemProviderErrorCode.FileTooLarge);
1119
+ }
1120
+ }
1121
+ return true;
1122
+ }
1123
+ let FileService = class FileService extends Disposable {
1124
+ constructor(logService) {
1125
+ super();
1126
+ this.logService = logService;
1127
+ this.BUFFER_SIZE = 256 * 1024;
1128
+ this._onDidChangeFileSystemProviderRegistrations = this._register( new Emitter());
1129
+ this.onDidChangeFileSystemProviderRegistrations = this._onDidChangeFileSystemProviderRegistrations.event;
1130
+ this._onWillActivateFileSystemProvider = this._register( new Emitter());
1131
+ this.onWillActivateFileSystemProvider = this._onWillActivateFileSystemProvider.event;
1132
+ this._onDidChangeFileSystemProviderCapabilities = this._register( new Emitter());
1133
+ this.onDidChangeFileSystemProviderCapabilities = this._onDidChangeFileSystemProviderCapabilities.event;
1134
+ this.provider = new Map();
1135
+ this._onDidRunOperation = this._register( new Emitter());
1136
+ this.onDidRunOperation = this._onDidRunOperation.event;
1137
+ this._onDidFilesChange = this._register( new Emitter());
1138
+ this.onDidFilesChange = this._onDidFilesChange.event;
1139
+ this._onDidWatchError = this._register( new Emitter());
1140
+ this.onDidWatchError = this._onDidWatchError.event;
1141
+ this.activeWatchers = new Map();
1142
+ this.writeQueue = this._register( new ResourceQueue());
1143
+ }
1144
+ registerProvider(scheme, provider) {
1145
+ if (this.provider.has(scheme)) {
1146
+ throw new Error(`A filesystem provider for the scheme '${scheme}' is already registered.`);
1147
+ }
1148
+ const providerDisposables = new DisposableStore();
1149
+ this.provider.set(scheme, provider);
1150
+ this._onDidChangeFileSystemProviderRegistrations.fire({ added: true, scheme, provider });
1151
+ providerDisposables.add(provider.onDidChangeFile(changes => this._onDidFilesChange.fire( new FileChangesEvent(changes, !this.isPathCaseSensitive(provider)))));
1152
+ if (typeof provider.onDidWatchError === 'function') {
1153
+ providerDisposables.add(provider.onDidWatchError(error => this._onDidWatchError.fire( new Error(error))));
1154
+ }
1155
+ providerDisposables.add(provider.onDidChangeCapabilities(() => this._onDidChangeFileSystemProviderCapabilities.fire({ provider, scheme })));
1156
+ return toDisposable(() => {
1157
+ this._onDidChangeFileSystemProviderRegistrations.fire({ added: false, scheme, provider });
1158
+ this.provider.delete(scheme);
1159
+ dispose(providerDisposables);
1160
+ });
1161
+ }
1162
+ getProvider(scheme) {
1163
+ return this.provider.get(scheme);
1164
+ }
1165
+ async activateProvider(scheme) {
1166
+ const joiners = [];
1167
+ this._onWillActivateFileSystemProvider.fire({
1168
+ scheme,
1169
+ join(promise) {
1170
+ joiners.push(promise);
1171
+ },
1172
+ });
1173
+ if (this.provider.has(scheme)) {
1174
+ return;
1175
+ }
1176
+ await Promises.settled(joiners);
1177
+ }
1178
+ async canHandleResource(resource) {
1179
+ await this.activateProvider(resource.scheme);
1180
+ return this.hasProvider(resource);
1181
+ }
1182
+ hasProvider(resource) {
1183
+ return this.provider.has(resource.scheme);
1184
+ }
1185
+ hasCapability(resource, capability) {
1186
+ const provider = this.provider.get(resource.scheme);
1187
+ return !!(provider && (provider.capabilities & capability));
1188
+ }
1189
+ listCapabilities() {
1190
+ return Iterable.map(this.provider, ([scheme, provider]) => ({ scheme, capabilities: provider.capabilities }));
1191
+ }
1192
+ async withProvider(resource) {
1193
+ if (!isAbsolutePath(resource)) {
1194
+ throw new FileOperationError(localize('invalidPath', "Unable to resolve filesystem provider with relative file path '{0}'", this.resourceForError(resource)), 8 );
1195
+ }
1196
+ await this.activateProvider(resource.scheme);
1197
+ const provider = this.provider.get(resource.scheme);
1198
+ if (!provider) {
1199
+ const error = new Error();
1200
+ error.name = 'ENOPRO';
1201
+ error.message = localize(
1202
+ 'noProviderFound',
1203
+ "No file system provider found for resource '{0}'",
1204
+ resource.toString()
1205
+ );
1206
+ throw error;
1207
+ }
1208
+ return provider;
1209
+ }
1210
+ async withReadProvider(resource) {
1211
+ const provider = await this.withProvider(resource);
1212
+ if (hasOpenReadWriteCloseCapability(provider) || hasReadWriteCapability(provider) || hasFileReadStreamCapability(provider)) {
1213
+ return provider;
1214
+ }
1215
+ throw new Error(`Filesystem provider for scheme '${resource.scheme}' neither has FileReadWrite, FileReadStream nor FileOpenReadWriteClose capability which is needed for the read operation.`);
1216
+ }
1217
+ async withWriteProvider(resource) {
1218
+ const provider = await this.withProvider(resource);
1219
+ if (hasOpenReadWriteCloseCapability(provider) || hasReadWriteCapability(provider)) {
1220
+ return provider;
1221
+ }
1222
+ throw new Error(`Filesystem provider for scheme '${resource.scheme}' neither has FileReadWrite nor FileOpenReadWriteClose capability which is needed for the write operation.`);
1223
+ }
1224
+ async resolve(resource, options) {
1225
+ try {
1226
+ return await this.doResolveFile(resource, options);
1227
+ }
1228
+ catch (error) {
1229
+ if (toFileSystemProviderErrorCode(error) === FileSystemProviderErrorCode.FileNotFound) {
1230
+ throw new FileOperationError(localize('fileNotFoundError', "Unable to resolve nonexistent file '{0}'", this.resourceForError(resource)), 1 );
1231
+ }
1232
+ throw ensureFileSystemProviderError(error);
1233
+ }
1234
+ }
1235
+ async doResolveFile(resource, options) {
1236
+ const provider = await this.withProvider(resource);
1237
+ const isPathCaseSensitive = this.isPathCaseSensitive(provider);
1238
+ const resolveTo = options?.resolveTo;
1239
+ const resolveSingleChildDescendants = options?.resolveSingleChildDescendants;
1240
+ const resolveMetadata = options?.resolveMetadata;
1241
+ const stat = await provider.stat(resource);
1242
+ let trie;
1243
+ return this.toFileStat(provider, resource, stat, undefined, !!resolveMetadata, (stat, siblings) => {
1244
+ if (!trie) {
1245
+ trie = TernarySearchTree.forUris(() => !isPathCaseSensitive);
1246
+ trie.set(resource, true);
1247
+ if (resolveTo) {
1248
+ trie.fill(true, resolveTo);
1249
+ }
1250
+ }
1251
+ if (trie.get(stat.resource) || trie.findSuperstr(stat.resource.with({ query: null, fragment: null } ))) {
1252
+ return true;
1253
+ }
1254
+ if (stat.isDirectory && resolveSingleChildDescendants) {
1255
+ return siblings === 1;
1256
+ }
1257
+ return false;
1258
+ });
1259
+ }
1260
+ async toFileStat(provider, resource, stat, siblings, resolveMetadata, recurse) {
1261
+ const { providerExtUri } = this.getExtUri(provider);
1262
+ const fileStat = {
1263
+ resource,
1264
+ name: providerExtUri.basename(resource),
1265
+ isFile: (stat.type & FileType.File) !== 0,
1266
+ isDirectory: (stat.type & FileType.Directory) !== 0,
1267
+ isSymbolicLink: (stat.type & FileType.SymbolicLink) !== 0,
1268
+ mtime: stat.mtime,
1269
+ ctime: stat.ctime,
1270
+ size: stat.size,
1271
+ readonly: Boolean((stat.permissions ?? 0) & FilePermission.Readonly) || Boolean(provider.capabilities & 2048 ),
1272
+ etag: etag({ mtime: stat.mtime, size: stat.size }),
1273
+ children: undefined
1274
+ };
1275
+ if (fileStat.isDirectory && recurse(fileStat, siblings)) {
1276
+ try {
1277
+ const entries = await provider.readdir(resource);
1278
+ const resolvedEntries = await Promises.settled(entries.map(async ([name, type]) => {
1279
+ try {
1280
+ const childResource = providerExtUri.joinPath(resource, name);
1281
+ const childStat = resolveMetadata ? await provider.stat(childResource) : { type };
1282
+ return await this.toFileStat(provider, childResource, childStat, entries.length, resolveMetadata, recurse);
1283
+ }
1284
+ catch (error) {
1285
+ this.logService.trace(error);
1286
+ return null;
1287
+ }
1288
+ }));
1289
+ fileStat.children = coalesce(resolvedEntries);
1290
+ }
1291
+ catch (error) {
1292
+ this.logService.trace(error);
1293
+ fileStat.children = [];
1294
+ }
1295
+ return fileStat;
1296
+ }
1297
+ return fileStat;
1298
+ }
1299
+ async resolveAll(toResolve) {
1300
+ return Promises.settled(toResolve.map(async (entry) => {
1301
+ try {
1302
+ return { stat: await this.doResolveFile(entry.resource, entry.options), success: true };
1303
+ }
1304
+ catch (error) {
1305
+ this.logService.trace(error);
1306
+ return { stat: undefined, success: false };
1307
+ }
1308
+ }));
1309
+ }
1310
+ async stat(resource) {
1311
+ const provider = await this.withProvider(resource);
1312
+ const stat = await provider.stat(resource);
1313
+ return this.toFileStat(provider, resource, stat, undefined, true, () => false );
1314
+ }
1315
+ async exists(resource) {
1316
+ const provider = await this.withProvider(resource);
1317
+ try {
1318
+ const stat = await provider.stat(resource);
1319
+ return !!stat;
1320
+ }
1321
+ catch (error) {
1322
+ return false;
1323
+ }
1324
+ }
1325
+ async canCreateFile(resource, options) {
1326
+ try {
1327
+ await this.doValidateCreateFile(resource, options);
1328
+ }
1329
+ catch (error) {
1330
+ return error;
1331
+ }
1332
+ return true;
1333
+ }
1334
+ async doValidateCreateFile(resource, options) {
1335
+ if (!options?.overwrite && (await this.exists(resource))) {
1336
+ throw new FileOperationError(localize('fileExists', "Unable to create file '{0}' that already exists when overwrite flag is not set", this.resourceForError(resource)), 3 , options);
1337
+ }
1338
+ }
1339
+ async createFile(resource, bufferOrReadableOrStream = VSBuffer.fromString(''), options) {
1340
+ await this.doValidateCreateFile(resource, options);
1341
+ const fileStat = await this.writeFile(resource, bufferOrReadableOrStream);
1342
+ this._onDidRunOperation.fire( new FileOperationEvent(resource, 0 , fileStat));
1343
+ return fileStat;
1344
+ }
1345
+ async writeFile(resource, bufferOrReadableOrStream, options) {
1346
+ const provider = this.throwIfFileSystemIsReadonly(await this.withWriteProvider(resource), resource);
1347
+ const { providerExtUri } = this.getExtUri(provider);
1348
+ try {
1349
+ const stat = await this.validateWriteFile(provider, resource, options);
1350
+ if (!stat) {
1351
+ await this.mkdirp(provider, providerExtUri.dirname(resource));
1352
+ }
1353
+ let bufferOrReadableOrStreamOrBufferedStream;
1354
+ if (hasReadWriteCapability(provider) && !(bufferOrReadableOrStream instanceof VSBuffer)) {
1355
+ if (isReadableStream(bufferOrReadableOrStream)) {
1356
+ const bufferedStream = await peekStream(bufferOrReadableOrStream, 3);
1357
+ if (bufferedStream.ended) {
1358
+ bufferOrReadableOrStreamOrBufferedStream = VSBuffer.concat(bufferedStream.buffer);
1359
+ }
1360
+ else {
1361
+ bufferOrReadableOrStreamOrBufferedStream = bufferedStream;
1362
+ }
1363
+ }
1364
+ else {
1365
+ bufferOrReadableOrStreamOrBufferedStream = peekReadable(bufferOrReadableOrStream, data => VSBuffer.concat(data), 3);
1366
+ }
1367
+ }
1368
+ else {
1369
+ bufferOrReadableOrStreamOrBufferedStream = bufferOrReadableOrStream;
1370
+ }
1371
+ if (!hasOpenReadWriteCloseCapability(provider) || (hasReadWriteCapability(provider) && bufferOrReadableOrStreamOrBufferedStream instanceof VSBuffer)) {
1372
+ await this.doWriteUnbuffered(provider, resource, options, bufferOrReadableOrStreamOrBufferedStream);
1373
+ }
1374
+ else {
1375
+ await this.doWriteBuffered(provider, resource, options, bufferOrReadableOrStreamOrBufferedStream instanceof VSBuffer ? bufferToReadable(bufferOrReadableOrStreamOrBufferedStream) : bufferOrReadableOrStreamOrBufferedStream);
1376
+ }
1377
+ this._onDidRunOperation.fire( new FileOperationEvent(resource, 4 ));
1378
+ }
1379
+ catch (error) {
1380
+ throw new FileOperationError(localize('err.write', "Unable to write file '{0}' ({1})", this.resourceForError(resource), ensureFileSystemProviderError(error).toString()), toFileOperationResult(error), options);
1381
+ }
1382
+ return this.resolve(resource, { resolveMetadata: true });
1383
+ }
1384
+ async validateWriteFile(provider, resource, options) {
1385
+ const unlock = !!options?.unlock;
1386
+ if (unlock && !((provider.capabilities & 8192) )) {
1387
+ throw new Error(localize('writeFailedUnlockUnsupported', "Unable to unlock file '{0}' because provider does not support it.", this.resourceForError(resource)));
1388
+ }
1389
+ let stat = undefined;
1390
+ try {
1391
+ stat = await provider.stat(resource);
1392
+ }
1393
+ catch (error) {
1394
+ return undefined;
1395
+ }
1396
+ if ((stat.type & FileType.Directory) !== 0) {
1397
+ throw new FileOperationError(localize('fileIsDirectoryWriteError', "Unable to write file '{0}' that is actually a directory", this.resourceForError(resource)), 0 , options);
1398
+ }
1399
+ this.throwIfFileIsReadonly(resource, stat);
1400
+ if (typeof options?.mtime === 'number' && typeof options.etag === 'string' && options.etag !== ETAG_DISABLED &&
1401
+ typeof stat.mtime === 'number' && typeof stat.size === 'number' &&
1402
+ options.mtime < stat.mtime && options.etag !== etag({ mtime: options.mtime , size: stat.size })) {
1403
+ throw new FileOperationError(localize('fileModifiedError', "File Modified Since"), 3 , options);
1404
+ }
1405
+ return stat;
1406
+ }
1407
+ async readFile(resource, options, token) {
1408
+ const provider = await this.withReadProvider(resource);
1409
+ if (options?.atomic) {
1410
+ return this.doReadFileAtomic(provider, resource, options, token);
1411
+ }
1412
+ return this.doReadFile(provider, resource, options, token);
1413
+ }
1414
+ async doReadFileAtomic(provider, resource, options, token) {
1415
+ return (
1416
+ new Promise((resolve, reject) => {
1417
+ this.writeQueue.queueFor(resource, this.getExtUri(provider).providerExtUri).queue(async () => {
1418
+ try {
1419
+ const content = await this.doReadFile(provider, resource, options, token);
1420
+ resolve(content);
1421
+ }
1422
+ catch (error) {
1423
+ reject(error);
1424
+ }
1425
+ });
1426
+ })
1427
+ );
1428
+ }
1429
+ async doReadFile(provider, resource, options, token) {
1430
+ const stream = await this.doReadFileStream(provider, resource, {
1431
+ ...options,
1432
+ preferUnbuffered: true
1433
+ }, token);
1434
+ return {
1435
+ ...stream,
1436
+ value: await streamToBuffer(stream.value)
1437
+ };
1438
+ }
1439
+ async readFileStream(resource, options, token) {
1440
+ const provider = await this.withReadProvider(resource);
1441
+ return this.doReadFileStream(provider, resource, options, token);
1442
+ }
1443
+ async doReadFileStream(provider, resource, options, token) {
1444
+ const cancellableSource = new CancellationTokenSource(token);
1445
+ const statPromise = this.validateReadFile(resource, options).then(stat => stat, error => {
1446
+ cancellableSource.cancel();
1447
+ throw error;
1448
+ });
1449
+ let fileStream = undefined;
1450
+ try {
1451
+ if (typeof options?.etag === 'string' && options.etag !== ETAG_DISABLED) {
1452
+ await statPromise;
1453
+ }
1454
+ if ((options?.atomic && hasFileAtomicReadCapability(provider)) ||
1455
+ !(hasOpenReadWriteCloseCapability(provider) || hasFileReadStreamCapability(provider)) ||
1456
+ (hasReadWriteCapability(provider) && options?.preferUnbuffered)
1457
+ ) {
1458
+ fileStream = this.readFileUnbuffered(provider, resource, options);
1459
+ }
1460
+ else if (hasFileReadStreamCapability(provider)) {
1461
+ fileStream = this.readFileStreamed(provider, resource, cancellableSource.token, options);
1462
+ }
1463
+ else {
1464
+ fileStream = this.readFileBuffered(provider, resource, cancellableSource.token, options);
1465
+ }
1466
+ const fileStat = await statPromise;
1467
+ return {
1468
+ ...fileStat,
1469
+ value: fileStream
1470
+ };
1471
+ }
1472
+ catch (error) {
1473
+ if (fileStream) {
1474
+ await consumeStream(fileStream);
1475
+ }
1476
+ const message = localize(
1477
+ 'err.read',
1478
+ "Unable to read file '{0}' ({1})",
1479
+ this.resourceForError(resource),
1480
+ ensureFileSystemProviderError(error).toString()
1481
+ );
1482
+ if (error instanceof NotModifiedSinceFileOperationError) {
1483
+ throw new NotModifiedSinceFileOperationError(message, error.stat, options);
1484
+ }
1485
+ else {
1486
+ throw new FileOperationError(message, toFileOperationResult(error), options);
1487
+ }
1488
+ }
1489
+ }
1490
+ readFileStreamed(provider, resource, token, options = Object.create(null)) {
1491
+ const fileStream = provider.readFileStream(resource, options, token);
1492
+ return transform(fileStream, {
1493
+ data: data => data instanceof VSBuffer ? data : VSBuffer.wrap(data),
1494
+ error: error => new FileOperationError( localize(
1495
+ 'err.read',
1496
+ "Unable to read file '{0}' ({1})",
1497
+ this.resourceForError(resource),
1498
+ ensureFileSystemProviderError(error).toString()
1499
+ ), toFileOperationResult(error), options)
1500
+ }, data => VSBuffer.concat(data));
1501
+ }
1502
+ readFileBuffered(provider, resource, token, options = Object.create(null)) {
1503
+ const stream = newWriteableBufferStream();
1504
+ readFileIntoStream(provider, resource, stream, data => data, {
1505
+ ...options,
1506
+ bufferSize: this.BUFFER_SIZE,
1507
+ errorTransformer: error => new FileOperationError( localize(
1508
+ 'err.read',
1509
+ "Unable to read file '{0}' ({1})",
1510
+ this.resourceForError(resource),
1511
+ ensureFileSystemProviderError(error).toString()
1512
+ ), toFileOperationResult(error), options)
1513
+ }, token);
1514
+ return stream;
1515
+ }
1516
+ readFileUnbuffered(provider, resource, options) {
1517
+ const stream = newWriteableStream(data => VSBuffer.concat(data));
1518
+ (async () => {
1519
+ try {
1520
+ let buffer;
1521
+ if (options?.atomic && hasFileAtomicReadCapability(provider)) {
1522
+ buffer = await provider.readFile(resource, { atomic: true });
1523
+ }
1524
+ else {
1525
+ buffer = await provider.readFile(resource);
1526
+ }
1527
+ if (typeof options?.position === 'number') {
1528
+ buffer = buffer.slice(options.position);
1529
+ }
1530
+ if (typeof options?.length === 'number') {
1531
+ buffer = buffer.slice(0, options.length);
1532
+ }
1533
+ this.validateReadFileLimits(resource, buffer.byteLength, options);
1534
+ stream.end(VSBuffer.wrap(buffer));
1535
+ }
1536
+ catch (err) {
1537
+ stream.error(err);
1538
+ stream.end();
1539
+ }
1540
+ })();
1541
+ return stream;
1542
+ }
1543
+ async validateReadFile(resource, options) {
1544
+ const stat = await this.resolve(resource, { resolveMetadata: true });
1545
+ if (stat.isDirectory) {
1546
+ throw new FileOperationError(localize('fileIsDirectoryReadError', "Unable to read file '{0}' that is actually a directory", this.resourceForError(resource)), 0 , options);
1547
+ }
1548
+ if (typeof options?.etag === 'string' && options.etag !== ETAG_DISABLED && options.etag === stat.etag) {
1549
+ throw new NotModifiedSinceFileOperationError(localize('fileNotModifiedError', "File not modified since"), stat, options);
1550
+ }
1551
+ this.validateReadFileLimits(resource, stat.size, options);
1552
+ return stat;
1553
+ }
1554
+ validateReadFileLimits(resource, size, options) {
1555
+ if (options?.limits) {
1556
+ let tooLargeErrorResult = undefined;
1557
+ if (typeof options.limits.memory === 'number' && size > options.limits.memory) {
1558
+ tooLargeErrorResult = 9 ;
1559
+ }
1560
+ if (typeof options.limits.size === 'number' && size > options.limits.size) {
1561
+ tooLargeErrorResult = 7 ;
1562
+ }
1563
+ if (typeof tooLargeErrorResult === 'number') {
1564
+ throw new FileOperationError(localize('fileTooLargeError', "Unable to read file '{0}' that is too large to open", this.resourceForError(resource)), tooLargeErrorResult);
1565
+ }
1566
+ }
1567
+ }
1568
+ async canMove(source, target, overwrite) {
1569
+ return this.doCanMoveCopy(source, target, 'move', overwrite);
1570
+ }
1571
+ async canCopy(source, target, overwrite) {
1572
+ return this.doCanMoveCopy(source, target, 'copy', overwrite);
1573
+ }
1574
+ async doCanMoveCopy(source, target, mode, overwrite) {
1575
+ if (source.toString() !== target.toString()) {
1576
+ try {
1577
+ const sourceProvider = mode === 'move' ? this.throwIfFileSystemIsReadonly(await this.withWriteProvider(source), source) : await this.withReadProvider(source);
1578
+ const targetProvider = this.throwIfFileSystemIsReadonly(await this.withWriteProvider(target), target);
1579
+ await this.doValidateMoveCopy(sourceProvider, source, targetProvider, target, mode, overwrite);
1580
+ }
1581
+ catch (error) {
1582
+ return error;
1583
+ }
1584
+ }
1585
+ return true;
1586
+ }
1587
+ async move(source, target, overwrite) {
1588
+ const sourceProvider = this.throwIfFileSystemIsReadonly(await this.withWriteProvider(source), source);
1589
+ const targetProvider = this.throwIfFileSystemIsReadonly(await this.withWriteProvider(target), target);
1590
+ const mode = await this.doMoveCopy(sourceProvider, source, targetProvider, target, 'move', !!overwrite);
1591
+ const fileStat = await this.resolve(target, { resolveMetadata: true });
1592
+ this._onDidRunOperation.fire( new FileOperationEvent(
1593
+ source,
1594
+ mode === 'move' ? 2 : 3 ,
1595
+ fileStat
1596
+ ));
1597
+ return fileStat;
1598
+ }
1599
+ async copy(source, target, overwrite) {
1600
+ const sourceProvider = await this.withReadProvider(source);
1601
+ const targetProvider = this.throwIfFileSystemIsReadonly(await this.withWriteProvider(target), target);
1602
+ const mode = await this.doMoveCopy(sourceProvider, source, targetProvider, target, 'copy', !!overwrite);
1603
+ const fileStat = await this.resolve(target, { resolveMetadata: true });
1604
+ this._onDidRunOperation.fire( new FileOperationEvent(
1605
+ source,
1606
+ mode === 'copy' ? 3 : 2 ,
1607
+ fileStat
1608
+ ));
1609
+ return fileStat;
1610
+ }
1611
+ async doMoveCopy(sourceProvider, source, targetProvider, target, mode, overwrite) {
1612
+ if (source.toString() === target.toString()) {
1613
+ return mode;
1614
+ }
1615
+ const { exists, isSameResourceWithDifferentPathCase } = await this.doValidateMoveCopy(sourceProvider, source, targetProvider, target, mode, overwrite);
1616
+ if (exists && !isSameResourceWithDifferentPathCase && overwrite) {
1617
+ await this.del(target, { recursive: true });
1618
+ }
1619
+ await this.mkdirp(targetProvider, this.getExtUri(targetProvider).providerExtUri.dirname(target));
1620
+ if (mode === 'copy') {
1621
+ if (sourceProvider === targetProvider && hasFileFolderCopyCapability(sourceProvider)) {
1622
+ await sourceProvider.copy(source, target, { overwrite });
1623
+ }
1624
+ else {
1625
+ const sourceFile = await this.resolve(source);
1626
+ if (sourceFile.isDirectory) {
1627
+ await this.doCopyFolder(sourceProvider, sourceFile, targetProvider, target);
1628
+ }
1629
+ else {
1630
+ await this.doCopyFile(sourceProvider, source, targetProvider, target);
1631
+ }
1632
+ }
1633
+ return mode;
1634
+ }
1635
+ else {
1636
+ if (sourceProvider === targetProvider) {
1637
+ await sourceProvider.rename(source, target, { overwrite });
1638
+ return mode;
1639
+ }
1640
+ else {
1641
+ await this.doMoveCopy(sourceProvider, source, targetProvider, target, 'copy', overwrite);
1642
+ await this.del(source, { recursive: true });
1643
+ return 'copy';
1644
+ }
1645
+ }
1646
+ }
1647
+ async doCopyFile(sourceProvider, source, targetProvider, target) {
1648
+ if (hasOpenReadWriteCloseCapability(sourceProvider) && hasOpenReadWriteCloseCapability(targetProvider)) {
1649
+ return this.doPipeBuffered(sourceProvider, source, targetProvider, target);
1650
+ }
1651
+ if (hasOpenReadWriteCloseCapability(sourceProvider) && hasReadWriteCapability(targetProvider)) {
1652
+ return this.doPipeBufferedToUnbuffered(sourceProvider, source, targetProvider, target);
1653
+ }
1654
+ if (hasReadWriteCapability(sourceProvider) && hasOpenReadWriteCloseCapability(targetProvider)) {
1655
+ return this.doPipeUnbufferedToBuffered(sourceProvider, source, targetProvider, target);
1656
+ }
1657
+ if (hasReadWriteCapability(sourceProvider) && hasReadWriteCapability(targetProvider)) {
1658
+ return this.doPipeUnbuffered(sourceProvider, source, targetProvider, target);
1659
+ }
1660
+ }
1661
+ async doCopyFolder(sourceProvider, sourceFolder, targetProvider, targetFolder) {
1662
+ await targetProvider.mkdir(targetFolder);
1663
+ if (Array.isArray(sourceFolder.children)) {
1664
+ await Promises.settled(sourceFolder.children.map(async (sourceChild) => {
1665
+ const targetChild = this.getExtUri(targetProvider).providerExtUri.joinPath(targetFolder, sourceChild.name);
1666
+ if (sourceChild.isDirectory) {
1667
+ return this.doCopyFolder(sourceProvider, await this.resolve(sourceChild.resource), targetProvider, targetChild);
1668
+ }
1669
+ else {
1670
+ return this.doCopyFile(sourceProvider, sourceChild.resource, targetProvider, targetChild);
1671
+ }
1672
+ }));
1673
+ }
1674
+ }
1675
+ async doValidateMoveCopy(sourceProvider, source, targetProvider, target, mode, overwrite) {
1676
+ let isSameResourceWithDifferentPathCase = false;
1677
+ if (sourceProvider === targetProvider) {
1678
+ const { providerExtUri, isPathCaseSensitive } = this.getExtUri(sourceProvider);
1679
+ if (!isPathCaseSensitive) {
1680
+ isSameResourceWithDifferentPathCase = providerExtUri.isEqual(source, target);
1681
+ }
1682
+ if (isSameResourceWithDifferentPathCase && mode === 'copy') {
1683
+ throw new Error(localize('unableToMoveCopyError1', "Unable to copy when source '{0}' is same as target '{1}' with different path case on a case insensitive file system", this.resourceForError(source), this.resourceForError(target)));
1684
+ }
1685
+ if (!isSameResourceWithDifferentPathCase && providerExtUri.isEqualOrParent(target, source)) {
1686
+ throw new Error(localize('unableToMoveCopyError2', "Unable to move/copy when source '{0}' is parent of target '{1}'.", this.resourceForError(source), this.resourceForError(target)));
1687
+ }
1688
+ }
1689
+ const exists = await this.exists(target);
1690
+ if (exists && !isSameResourceWithDifferentPathCase) {
1691
+ if (!overwrite) {
1692
+ throw new FileOperationError(localize('unableToMoveCopyError3', "Unable to move/copy '{0}' because target '{1}' already exists at destination.", this.resourceForError(source), this.resourceForError(target)), 4 );
1693
+ }
1694
+ if (sourceProvider === targetProvider) {
1695
+ const { providerExtUri } = this.getExtUri(sourceProvider);
1696
+ if (providerExtUri.isEqualOrParent(source, target)) {
1697
+ throw new Error(localize('unableToMoveCopyError4', "Unable to move/copy '{0}' into '{1}' since a file would replace the folder it is contained in.", this.resourceForError(source), this.resourceForError(target)));
1698
+ }
1699
+ }
1700
+ }
1701
+ return { exists, isSameResourceWithDifferentPathCase };
1702
+ }
1703
+ getExtUri(provider) {
1704
+ const isPathCaseSensitive = this.isPathCaseSensitive(provider);
1705
+ return {
1706
+ providerExtUri: isPathCaseSensitive ? extUri : extUriIgnorePathCase,
1707
+ isPathCaseSensitive
1708
+ };
1709
+ }
1710
+ isPathCaseSensitive(provider) {
1711
+ return !!((provider.capabilities & 1024) );
1712
+ }
1713
+ async createFolder(resource) {
1714
+ const provider = this.throwIfFileSystemIsReadonly(await this.withProvider(resource), resource);
1715
+ await this.mkdirp(provider, resource);
1716
+ const fileStat = await this.resolve(resource, { resolveMetadata: true });
1717
+ this._onDidRunOperation.fire( new FileOperationEvent(resource, 0 , fileStat));
1718
+ return fileStat;
1719
+ }
1720
+ async mkdirp(provider, directory) {
1721
+ const directoriesToCreate = [];
1722
+ const { providerExtUri } = this.getExtUri(provider);
1723
+ while (!providerExtUri.isEqual(directory, providerExtUri.dirname(directory))) {
1724
+ try {
1725
+ const stat = await provider.stat(directory);
1726
+ if ((stat.type & FileType.Directory) === 0) {
1727
+ throw new Error(localize('mkdirExistsError', "Unable to create folder '{0}' that already exists but is not a directory", this.resourceForError(directory)));
1728
+ }
1729
+ break;
1730
+ }
1731
+ catch (error) {
1732
+ if (toFileSystemProviderErrorCode(error) !== FileSystemProviderErrorCode.FileNotFound) {
1733
+ throw error;
1734
+ }
1735
+ directoriesToCreate.push(providerExtUri.basename(directory));
1736
+ directory = providerExtUri.dirname(directory);
1737
+ }
1738
+ }
1739
+ for (let i = directoriesToCreate.length - 1; i >= 0; i--) {
1740
+ directory = providerExtUri.joinPath(directory, directoriesToCreate[i]);
1741
+ try {
1742
+ await provider.mkdir(directory);
1743
+ }
1744
+ catch (error) {
1745
+ if (toFileSystemProviderErrorCode(error) !== FileSystemProviderErrorCode.FileExists) {
1746
+ throw error;
1747
+ }
1748
+ }
1749
+ }
1750
+ }
1751
+ async canDelete(resource, options) {
1752
+ try {
1753
+ await this.doValidateDelete(resource, options);
1754
+ }
1755
+ catch (error) {
1756
+ return error;
1757
+ }
1758
+ return true;
1759
+ }
1760
+ async doValidateDelete(resource, options) {
1761
+ const provider = this.throwIfFileSystemIsReadonly(await this.withProvider(resource), resource);
1762
+ const useTrash = !!options?.useTrash;
1763
+ if (useTrash && !((provider.capabilities & 4096) )) {
1764
+ throw new Error(localize('deleteFailedTrashUnsupported', "Unable to delete file '{0}' via trash because provider does not support it.", this.resourceForError(resource)));
1765
+ }
1766
+ let stat = undefined;
1767
+ try {
1768
+ stat = await provider.stat(resource);
1769
+ }
1770
+ catch (error) {
1771
+ }
1772
+ if (stat) {
1773
+ this.throwIfFileIsReadonly(resource, stat);
1774
+ }
1775
+ else {
1776
+ throw new FileOperationError(localize('deleteFailedNotFound', "Unable to delete nonexistent file '{0}'", this.resourceForError(resource)), 1 );
1777
+ }
1778
+ const recursive = !!options?.recursive;
1779
+ if (!recursive) {
1780
+ const stat = await this.resolve(resource);
1781
+ if (stat.isDirectory && Array.isArray(stat.children) && stat.children.length > 0) {
1782
+ throw new Error(localize('deleteFailedNonEmptyFolder', "Unable to delete non-empty folder '{0}'.", this.resourceForError(resource)));
1783
+ }
1784
+ }
1785
+ return provider;
1786
+ }
1787
+ async del(resource, options) {
1788
+ const provider = await this.doValidateDelete(resource, options);
1789
+ const useTrash = !!options?.useTrash;
1790
+ const recursive = !!options?.recursive;
1791
+ await provider.delete(resource, { recursive, useTrash });
1792
+ this._onDidRunOperation.fire( new FileOperationEvent(resource, 1 ));
1793
+ }
1794
+ watch(resource, options = { recursive: false, excludes: [] }) {
1795
+ const disposables = new DisposableStore();
1796
+ let watchDisposed = false;
1797
+ let disposeWatch = () => { watchDisposed = true; };
1798
+ disposables.add(toDisposable(() => disposeWatch()));
1799
+ (async () => {
1800
+ try {
1801
+ const disposable = await this.doWatch(resource, options);
1802
+ if (watchDisposed) {
1803
+ dispose(disposable);
1804
+ }
1805
+ else {
1806
+ disposeWatch = () => dispose(disposable);
1807
+ }
1808
+ }
1809
+ catch (error) {
1810
+ this.logService.error(error);
1811
+ }
1812
+ })();
1813
+ return disposables;
1814
+ }
1815
+ async doWatch(resource, options) {
1816
+ const provider = await this.withProvider(resource);
1817
+ const watchHash = hash([this.getExtUri(provider).providerExtUri.getComparisonKey(resource), options]);
1818
+ let watcher = this.activeWatchers.get(watchHash);
1819
+ if (!watcher) {
1820
+ watcher = {
1821
+ count: 0,
1822
+ disposable: provider.watch(resource, options)
1823
+ };
1824
+ this.activeWatchers.set(watchHash, watcher);
1825
+ }
1826
+ watcher.count += 1;
1827
+ return toDisposable(() => {
1828
+ if (watcher) {
1829
+ watcher.count--;
1830
+ if (watcher.count === 0) {
1831
+ dispose(watcher.disposable);
1832
+ this.activeWatchers.delete(watchHash);
1833
+ }
1834
+ }
1835
+ });
1836
+ }
1837
+ dispose() {
1838
+ super.dispose();
1839
+ for (const [, watcher] of this.activeWatchers) {
1840
+ dispose(watcher.disposable);
1841
+ }
1842
+ this.activeWatchers.clear();
1843
+ }
1844
+ async doWriteBuffered(provider, resource, options, readableOrStreamOrBufferedStream) {
1845
+ return this.writeQueue.queueFor(resource, this.getExtUri(provider).providerExtUri).queue(async () => {
1846
+ const handle = await provider.open(resource, { create: true, unlock: options?.unlock ?? false });
1847
+ try {
1848
+ if (isReadableStream(readableOrStreamOrBufferedStream) || isReadableBufferedStream(readableOrStreamOrBufferedStream)) {
1849
+ await this.doWriteStreamBufferedQueued(provider, handle, readableOrStreamOrBufferedStream);
1850
+ }
1851
+ else {
1852
+ await this.doWriteReadableBufferedQueued(provider, handle, readableOrStreamOrBufferedStream);
1853
+ }
1854
+ }
1855
+ catch (error) {
1856
+ throw ensureFileSystemProviderError(error);
1857
+ }
1858
+ finally {
1859
+ await provider.close(handle);
1860
+ }
1861
+ });
1862
+ }
1863
+ async doWriteStreamBufferedQueued(provider, handle, streamOrBufferedStream) {
1864
+ let posInFile = 0;
1865
+ let stream;
1866
+ if (isReadableBufferedStream(streamOrBufferedStream)) {
1867
+ if (streamOrBufferedStream.buffer.length > 0) {
1868
+ const chunk = VSBuffer.concat(streamOrBufferedStream.buffer);
1869
+ await this.doWriteBuffer(provider, handle, chunk, chunk.byteLength, posInFile, 0);
1870
+ posInFile += chunk.byteLength;
1871
+ }
1872
+ if (streamOrBufferedStream.ended) {
1873
+ return;
1874
+ }
1875
+ stream = streamOrBufferedStream.stream;
1876
+ }
1877
+ else {
1878
+ stream = streamOrBufferedStream;
1879
+ }
1880
+ return (
1881
+ new Promise((resolve, reject) => {
1882
+ listenStream(stream, {
1883
+ onData: async (chunk) => {
1884
+ stream.pause();
1885
+ try {
1886
+ await this.doWriteBuffer(provider, handle, chunk, chunk.byteLength, posInFile, 0);
1887
+ }
1888
+ catch (error) {
1889
+ return reject(error);
1890
+ }
1891
+ posInFile += chunk.byteLength;
1892
+ setTimeout(() => stream.resume());
1893
+ },
1894
+ onError: error => reject(error),
1895
+ onEnd: () => resolve()
1896
+ });
1897
+ })
1898
+ );
1899
+ }
1900
+ async doWriteReadableBufferedQueued(provider, handle, readable) {
1901
+ let posInFile = 0;
1902
+ let chunk;
1903
+ while ((chunk = readable.read()) !== null) {
1904
+ await this.doWriteBuffer(provider, handle, chunk, chunk.byteLength, posInFile, 0);
1905
+ posInFile += chunk.byteLength;
1906
+ }
1907
+ }
1908
+ async doWriteBuffer(provider, handle, buffer, length, posInFile, posInBuffer) {
1909
+ let totalBytesWritten = 0;
1910
+ while (totalBytesWritten < length) {
1911
+ const bytesWritten = await provider.write(handle, posInFile + totalBytesWritten, buffer.buffer, posInBuffer + totalBytesWritten, length - totalBytesWritten);
1912
+ totalBytesWritten += bytesWritten;
1913
+ }
1914
+ }
1915
+ async doWriteUnbuffered(provider, resource, options, bufferOrReadableOrStreamOrBufferedStream) {
1916
+ return this.writeQueue.queueFor(resource, this.getExtUri(provider).providerExtUri).queue(() => this.doWriteUnbufferedQueued(provider, resource, options, bufferOrReadableOrStreamOrBufferedStream));
1917
+ }
1918
+ async doWriteUnbufferedQueued(provider, resource, options, bufferOrReadableOrStreamOrBufferedStream) {
1919
+ let buffer;
1920
+ if (bufferOrReadableOrStreamOrBufferedStream instanceof VSBuffer) {
1921
+ buffer = bufferOrReadableOrStreamOrBufferedStream;
1922
+ }
1923
+ else if (isReadableStream(bufferOrReadableOrStreamOrBufferedStream)) {
1924
+ buffer = await streamToBuffer(bufferOrReadableOrStreamOrBufferedStream);
1925
+ }
1926
+ else if (isReadableBufferedStream(bufferOrReadableOrStreamOrBufferedStream)) {
1927
+ buffer = await bufferedStreamToBuffer(bufferOrReadableOrStreamOrBufferedStream);
1928
+ }
1929
+ else {
1930
+ buffer = readableToBuffer(bufferOrReadableOrStreamOrBufferedStream);
1931
+ }
1932
+ await provider.writeFile(resource, buffer.buffer, { create: true, overwrite: true, unlock: options?.unlock ?? false });
1933
+ }
1934
+ async doPipeBuffered(sourceProvider, source, targetProvider, target) {
1935
+ return this.writeQueue.queueFor(target, this.getExtUri(targetProvider).providerExtUri).queue(() => this.doPipeBufferedQueued(sourceProvider, source, targetProvider, target));
1936
+ }
1937
+ async doPipeBufferedQueued(sourceProvider, source, targetProvider, target) {
1938
+ let sourceHandle = undefined;
1939
+ let targetHandle = undefined;
1940
+ try {
1941
+ sourceHandle = await sourceProvider.open(source, { create: false });
1942
+ targetHandle = await targetProvider.open(target, { create: true, unlock: false });
1943
+ const buffer = VSBuffer.alloc(this.BUFFER_SIZE);
1944
+ let posInFile = 0;
1945
+ let posInBuffer = 0;
1946
+ let bytesRead = 0;
1947
+ do {
1948
+ bytesRead = await sourceProvider.read(sourceHandle, posInFile, buffer.buffer, posInBuffer, buffer.byteLength - posInBuffer);
1949
+ await this.doWriteBuffer(targetProvider, targetHandle, buffer, bytesRead, posInFile, posInBuffer);
1950
+ posInFile += bytesRead;
1951
+ posInBuffer += bytesRead;
1952
+ if (posInBuffer === buffer.byteLength) {
1953
+ posInBuffer = 0;
1954
+ }
1955
+ } while (bytesRead > 0);
1956
+ }
1957
+ catch (error) {
1958
+ throw ensureFileSystemProviderError(error);
1959
+ }
1960
+ finally {
1961
+ await Promises.settled([
1962
+ typeof sourceHandle === 'number' ? sourceProvider.close(sourceHandle) : Promise.resolve(),
1963
+ typeof targetHandle === 'number' ? targetProvider.close(targetHandle) : Promise.resolve(),
1964
+ ]);
1965
+ }
1966
+ }
1967
+ async doPipeUnbuffered(sourceProvider, source, targetProvider, target) {
1968
+ return this.writeQueue.queueFor(target, this.getExtUri(targetProvider).providerExtUri).queue(() => this.doPipeUnbufferedQueued(sourceProvider, source, targetProvider, target));
1969
+ }
1970
+ async doPipeUnbufferedQueued(sourceProvider, source, targetProvider, target) {
1971
+ return targetProvider.writeFile(target, await sourceProvider.readFile(source), { create: true, overwrite: true, unlock: false });
1972
+ }
1973
+ async doPipeUnbufferedToBuffered(sourceProvider, source, targetProvider, target) {
1974
+ return this.writeQueue.queueFor(target, this.getExtUri(targetProvider).providerExtUri).queue(() => this.doPipeUnbufferedToBufferedQueued(sourceProvider, source, targetProvider, target));
1975
+ }
1976
+ async doPipeUnbufferedToBufferedQueued(sourceProvider, source, targetProvider, target) {
1977
+ const targetHandle = await targetProvider.open(target, { create: true, unlock: false });
1978
+ try {
1979
+ const buffer = await sourceProvider.readFile(source);
1980
+ await this.doWriteBuffer(targetProvider, targetHandle, VSBuffer.wrap(buffer), buffer.byteLength, 0, 0);
1981
+ }
1982
+ catch (error) {
1983
+ throw ensureFileSystemProviderError(error);
1984
+ }
1985
+ finally {
1986
+ await targetProvider.close(targetHandle);
1987
+ }
1988
+ }
1989
+ async doPipeBufferedToUnbuffered(sourceProvider, source, targetProvider, target) {
1990
+ const buffer = await streamToBuffer(this.readFileBuffered(sourceProvider, source, CancellationToken.None));
1991
+ await this.doWriteUnbuffered(targetProvider, target, undefined, buffer);
1992
+ }
1993
+ throwIfFileSystemIsReadonly(provider, resource) {
1994
+ if (provider.capabilities & 2048 ) {
1995
+ throw new FileOperationError(localize('err.readonly', "Unable to modify readonly file '{0}'", this.resourceForError(resource)), 6 );
1996
+ }
1997
+ return provider;
1998
+ }
1999
+ throwIfFileIsReadonly(resource, stat) {
2000
+ if ((stat.permissions ?? 0) & FilePermission.Readonly) {
2001
+ throw new FileOperationError(localize('err.readonly', "Unable to modify readonly file '{0}'", this.resourceForError(resource)), 6 );
2002
+ }
2003
+ }
2004
+ resourceForError(resource) {
2005
+ if (resource.scheme === Schemas.file) {
2006
+ return resource.fsPath;
2007
+ }
2008
+ return resource.toString(true);
2009
+ }
2010
+ };
2011
+ FileService = __decorate([
2012
+ __param(0, ILogService)
2013
+ ], FileService);
2014
+ function createConfigurationFileSystemProvider(settingsResource, readConfiguration, onChange) {
2015
+ const onDidFilesChange = new Emitter();
2016
+ onChange(() => {
2017
+ onDidFilesChange.fire([{
2018
+ type: 0 ,
2019
+ resource: settingsResource
2020
+ }]);
2021
+ });
2022
+ const textEncoder = new TextEncoder();
2023
+ const provider = {
2024
+ capabilities: 2 ,
2025
+ onDidChangeCapabilities: Event.None,
2026
+ onDidChangeFile: onDidFilesChange.event,
2027
+ watch: function () {
2028
+ return {
2029
+ dispose() { }
2030
+ };
2031
+ },
2032
+ stat: async (resource) => {
2033
+ if (resource.toString() !== settingsResource.toString()) {
2034
+ unsupported();
2035
+ }
2036
+ return {
2037
+ type: FileType.File,
2038
+ mtime: 0,
2039
+ ctime: 0,
2040
+ size: textEncoder.encode(readConfiguration()).length
2041
+ };
2042
+ },
2043
+ mkdir: unsupported,
2044
+ readdir: unsupported,
2045
+ delete: unsupported,
2046
+ rename: unsupported,
2047
+ writeFile: unsupported,
2048
+ readFile: async (resource) => {
2049
+ if (resource.toString() !== settingsResource.toString()) {
2050
+ unsupported();
2051
+ }
2052
+ return textEncoder.encode(readConfiguration());
2053
+ }
2054
+ };
2055
+ return provider;
2056
+ }
2057
+ function getServiceOverride(readConfiguration, onChange, settingsResource = URI.file('/userSettings.json')) {
2058
+ const logService = StandaloneServices.get(ILogService);
2059
+ const fileService = new FileService(logService);
2060
+ fileService.registerProvider(Schemas.file, createConfigurationFileSystemProvider(settingsResource, readConfiguration, onChange));
2061
+ const configurationService = new ConfigurationService(settingsResource, fileService);
2062
+ configurationService.initialize().catch(error => {
2063
+ logService.error(error);
2064
+ });
2065
+ return {
2066
+ [IConfigurationService.toString()]: configurationService
2067
+ };
2068
+ }
2069
+ export { getServiceOverride as default };