@codingame/monaco-vscode-files-service-override 25.1.2 → 26.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/vscode/src/vs/platform/files/browser/indexedDBFileSystemProvider.js +129 -80
- package/vscode/src/vs/platform/files/common/fileService.js +398 -218
- package/vscode/src/vs/platform/files/common/io.js +30 -20
- package/vscode/src/vs/workbench/services/files/browser/elevatedFileService.js +1 -1
- package/vscode/src/vs/workbench/services/textfile/browser/browserTextFileService.js +44 -23
- package/vscode/src/vs/workbench/services/textfile/browser/textFileService.js +176 -116
- package/vscode/src/vs/workbench/services/textfile/common/textFileEditorModelManager.js +95 -71
- package/vscode/src/vs/workbench/services/textfile/common/textFileSaveParticipant.js +6 -11
|
@@ -52,10 +52,35 @@ import '@codingame/monaco-vscode-api/vscode/vs/platform/theme/common/colors/sear
|
|
|
52
52
|
|
|
53
53
|
var AbstractTextFileService_1;
|
|
54
54
|
let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
55
|
-
static {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
static {
|
|
56
|
+
AbstractTextFileService_1 = this;
|
|
57
|
+
}
|
|
58
|
+
static {
|
|
59
|
+
this.TEXTFILE_SAVE_CREATE_SOURCE = SaveSourceRegistry.registerSource("textFileCreate.source", ( localize(14689, "File Created")));
|
|
60
|
+
}
|
|
61
|
+
static {
|
|
62
|
+
this.TEXTFILE_SAVE_REPLACE_SOURCE = SaveSourceRegistry.registerSource("textFileOverwrite.source", ( localize(14690, "File Replaced")));
|
|
63
|
+
}
|
|
64
|
+
constructor(
|
|
65
|
+
fileService,
|
|
66
|
+
untitledTextEditorService,
|
|
67
|
+
lifecycleService,
|
|
68
|
+
instantiationService,
|
|
69
|
+
modelService,
|
|
70
|
+
environmentService,
|
|
71
|
+
dialogService,
|
|
72
|
+
fileDialogService,
|
|
73
|
+
textResourceConfigurationService,
|
|
74
|
+
filesConfigurationService,
|
|
75
|
+
codeEditorService,
|
|
76
|
+
pathService,
|
|
77
|
+
workingCopyFileService,
|
|
78
|
+
uriIdentityService,
|
|
79
|
+
languageService,
|
|
80
|
+
logService,
|
|
81
|
+
elevatedFileService,
|
|
82
|
+
decorationsService
|
|
83
|
+
) {
|
|
59
84
|
super();
|
|
60
85
|
this.fileService = fileService;
|
|
61
86
|
this.lifecycleService = lifecycleService;
|
|
@@ -83,20 +108,28 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
83
108
|
constructor(files) {
|
|
84
109
|
super();
|
|
85
110
|
this.files = files;
|
|
86
|
-
this.label = ( localize(
|
|
111
|
+
this.label = ( localize(14691, "Text File Model Decorations"));
|
|
87
112
|
this._onDidChange = this._register(( new Emitter()));
|
|
88
113
|
this.onDidChange = this._onDidChange.event;
|
|
89
114
|
this.registerListeners();
|
|
90
115
|
}
|
|
91
116
|
registerListeners() {
|
|
92
|
-
this._register(this.files.onDidResolve((
|
|
117
|
+
this._register(this.files.onDidResolve((
|
|
118
|
+
{
|
|
119
|
+
model
|
|
120
|
+
}
|
|
121
|
+
) => {
|
|
93
122
|
if (model.isReadonly() || model.hasState(TextFileEditorModelState.ORPHAN)) {
|
|
94
123
|
this._onDidChange.fire([model.resource]);
|
|
95
124
|
}
|
|
96
125
|
}));
|
|
97
126
|
this._register(this.files.onDidRemove(modelUri => this._onDidChange.fire([modelUri])));
|
|
98
|
-
this._register(
|
|
99
|
-
|
|
127
|
+
this._register(
|
|
128
|
+
this.files.onDidChangeReadonly(model => this._onDidChange.fire([model.resource]))
|
|
129
|
+
);
|
|
130
|
+
this._register(
|
|
131
|
+
this.files.onDidChangeOrphaned(model => this._onDidChange.fire([model.resource]))
|
|
132
|
+
);
|
|
100
133
|
}
|
|
101
134
|
provideDecorations(uri) {
|
|
102
135
|
const model = this.files.get(uri);
|
|
@@ -110,20 +143,20 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
110
143
|
color: listErrorForeground,
|
|
111
144
|
letter: Codicon.lockSmall,
|
|
112
145
|
strikethrough: true,
|
|
113
|
-
tooltip: ( localize(
|
|
146
|
+
tooltip: ( localize(14692, "Deleted, Read-only"))
|
|
114
147
|
};
|
|
115
148
|
}
|
|
116
149
|
else if (isReadonly) {
|
|
117
150
|
return {
|
|
118
151
|
letter: Codicon.lockSmall,
|
|
119
|
-
tooltip: ( localize(
|
|
152
|
+
tooltip: ( localize(14693, "Read-only"))
|
|
120
153
|
};
|
|
121
154
|
}
|
|
122
155
|
else if (isOrphaned) {
|
|
123
156
|
return {
|
|
124
157
|
color: listErrorForeground,
|
|
125
158
|
strikethrough: true,
|
|
126
|
-
tooltip: ( localize(
|
|
159
|
+
tooltip: ( localize(14694, "Deleted"))
|
|
127
160
|
};
|
|
128
161
|
}
|
|
129
162
|
return undefined;
|
|
@@ -145,7 +178,7 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
145
178
|
return {
|
|
146
179
|
...bufferStream,
|
|
147
180
|
encoding: decoder.detected.encoding || UTF8,
|
|
148
|
-
value: await consumeStream(decoder.stream, strings => strings.join(
|
|
181
|
+
value: await consumeStream(decoder.stream, strings => strings.join(""))
|
|
149
182
|
};
|
|
150
183
|
}
|
|
151
184
|
async readStream(resource, options) {
|
|
@@ -165,18 +198,16 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
165
198
|
...content,
|
|
166
199
|
value: bufferToStream(content.value)
|
|
167
200
|
};
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
201
|
+
} else {
|
|
170
202
|
bufferStream = await this.fileService.readFileStream(resource, options, cts.token);
|
|
171
203
|
}
|
|
172
204
|
try {
|
|
173
205
|
const decoder = await this.doGetDecodedStream(resource, bufferStream.value, options);
|
|
174
206
|
return [bufferStream, decoder];
|
|
175
|
-
}
|
|
176
|
-
catch (error) {
|
|
207
|
+
} catch (error) {
|
|
177
208
|
cts.dispose(true);
|
|
178
209
|
if (error.decodeStreamErrorKind === DecodeStreamErrorKind.STREAM_IS_BINARY) {
|
|
179
|
-
throw ( new TextFileOperationError(( localize(
|
|
210
|
+
throw ( new TextFileOperationError(( localize(14695, "File seems to be binary and cannot be opened as text")), TextFileOperationResult.FILE_IS_BINARY, options));
|
|
180
211
|
}
|
|
181
212
|
else {
|
|
182
213
|
throw error;
|
|
@@ -184,7 +215,7 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
184
215
|
}
|
|
185
216
|
}
|
|
186
217
|
async create(operations, undoInfo) {
|
|
187
|
-
const operationsWithContents = await Promise.all(( operations.map(async
|
|
218
|
+
const operationsWithContents = await Promise.all(( operations.map(async operation => {
|
|
188
219
|
const contents = await this.getEncodedReadable(operation.resource, operation.value);
|
|
189
220
|
return {
|
|
190
221
|
resource: operation.resource,
|
|
@@ -202,15 +233,18 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
202
233
|
return this.fileService.writeFile(resource, readable, options);
|
|
203
234
|
}
|
|
204
235
|
async getEncodedReadable(resource, value, options) {
|
|
205
|
-
const {
|
|
236
|
+
const {
|
|
237
|
+
encoding,
|
|
238
|
+
addBOM
|
|
239
|
+
} = await this.encoding.getWriteEncoding(resource, options);
|
|
206
240
|
if (encoding === UTF8 && !addBOM) {
|
|
207
|
-
return typeof value ===
|
|
208
|
-
? undefined
|
|
209
|
-
: toBufferOrReadable(value);
|
|
241
|
+
return typeof value === "undefined" ? undefined : toBufferOrReadable(value);
|
|
210
242
|
}
|
|
211
|
-
value = value ||
|
|
212
|
-
const snapshot = typeof value ===
|
|
213
|
-
return toEncodeReadable(snapshot, encoding, {
|
|
243
|
+
value = value || "";
|
|
244
|
+
const snapshot = typeof value === "string" ? stringToSnapshot(value) : value;
|
|
245
|
+
return toEncodeReadable(snapshot, encoding, {
|
|
246
|
+
addBOM
|
|
247
|
+
});
|
|
214
248
|
}
|
|
215
249
|
async getDecodedStream(resource, value, options) {
|
|
216
250
|
return (await this.doGetDecodedStream(resource, value, options)).stream;
|
|
@@ -218,11 +252,9 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
218
252
|
doGetDecodedStream(resource, stream, options) {
|
|
219
253
|
return toDecodeStream(stream, {
|
|
220
254
|
acceptTextOnly: options?.acceptTextOnly ?? false,
|
|
221
|
-
guessEncoding: options?.autoGuessEncoding ||
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
this.textResourceConfigurationService.getValue(resource, 'files.candidateGuessEncodings'),
|
|
225
|
-
overwriteEncoding: async (detectedEncoding) => this.validateDetectedEncoding(resource, detectedEncoding ?? undefined, options)
|
|
255
|
+
guessEncoding: options?.autoGuessEncoding || this.textResourceConfigurationService.getValue(resource, "files.autoGuessEncoding"),
|
|
256
|
+
candidateGuessEncodings: options?.candidateGuessEncodings || this.textResourceConfigurationService.getValue(resource, "files.candidateGuessEncodings"),
|
|
257
|
+
overwriteEncoding: async detectedEncoding => this.validateDetectedEncoding(resource, detectedEncoding ?? undefined, options)
|
|
226
258
|
});
|
|
227
259
|
}
|
|
228
260
|
getEncoding(resource) {
|
|
@@ -232,14 +264,14 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
232
264
|
async resolveDecoding(resource, options) {
|
|
233
265
|
return {
|
|
234
266
|
preferredEncoding: (await this.encoding.getPreferredReadEncoding(resource, options, undefined)).encoding,
|
|
235
|
-
guessEncoding: options?.autoGuessEncoding ||
|
|
236
|
-
|
|
237
|
-
candidateGuessEncodings: options?.candidateGuessEncodings ||
|
|
238
|
-
this.textResourceConfigurationService.getValue(resource, 'files.candidateGuessEncodings'),
|
|
267
|
+
guessEncoding: options?.autoGuessEncoding || this.textResourceConfigurationService.getValue(resource, "files.autoGuessEncoding"),
|
|
268
|
+
candidateGuessEncodings: options?.candidateGuessEncodings || this.textResourceConfigurationService.getValue(resource, "files.candidateGuessEncodings")
|
|
239
269
|
};
|
|
240
270
|
}
|
|
241
271
|
async validateDetectedEncoding(resource, detectedEncoding, options) {
|
|
242
|
-
const {
|
|
272
|
+
const {
|
|
273
|
+
encoding
|
|
274
|
+
} = await this.encoding.getPreferredReadEncoding(resource, options, detectedEncoding);
|
|
243
275
|
return encoding;
|
|
244
276
|
}
|
|
245
277
|
resolveEncoding(resource, options) {
|
|
@@ -271,7 +303,10 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
271
303
|
}
|
|
272
304
|
async saveAs(source, target, options) {
|
|
273
305
|
if (!target) {
|
|
274
|
-
target = await this.fileDialogService.pickFileToSave(
|
|
306
|
+
target = await this.fileDialogService.pickFileToSave(
|
|
307
|
+
await this.suggestSavePath(options?.suggestedTarget ?? source),
|
|
308
|
+
options?.availableFileSystems
|
|
309
|
+
);
|
|
275
310
|
}
|
|
276
311
|
if (!target) {
|
|
277
312
|
return;
|
|
@@ -280,16 +315,23 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
280
315
|
const confirmed = await this.confirmMakeWriteable(target);
|
|
281
316
|
if (!confirmed) {
|
|
282
317
|
return;
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
318
|
+
} else {
|
|
285
319
|
this.filesConfigurationService.updateReadonly(target, false);
|
|
286
320
|
}
|
|
287
321
|
}
|
|
288
322
|
if (isEqual(source, target)) {
|
|
289
|
-
return this.save(source, {
|
|
323
|
+
return this.save(source, {
|
|
324
|
+
...options,
|
|
325
|
+
force: true
|
|
326
|
+
});
|
|
290
327
|
}
|
|
291
328
|
if (this.fileService.hasProvider(source) && this.uriIdentityService.extUri.isEqual(source, target) && (await this.fileService.exists(source))) {
|
|
292
|
-
await this.workingCopyFileService.move([{
|
|
329
|
+
await this.workingCopyFileService.move([{
|
|
330
|
+
file: {
|
|
331
|
+
source,
|
|
332
|
+
target
|
|
333
|
+
}
|
|
334
|
+
}], CancellationToken.None);
|
|
293
335
|
const success = await this.save(source, options);
|
|
294
336
|
if (!success) {
|
|
295
337
|
await this.save(target, options);
|
|
@@ -306,8 +348,7 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
306
348
|
if (textFileModel?.isResolved()) {
|
|
307
349
|
resolvedTextModel = textFileModel;
|
|
308
350
|
}
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
351
|
+
} else {
|
|
311
352
|
const untitledTextModel = this.untitled.get(source);
|
|
312
353
|
if (untitledTextModel?.isResolved()) {
|
|
313
354
|
resolvedTextModel = untitledTextModel;
|
|
@@ -331,8 +372,7 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
331
372
|
}
|
|
332
373
|
try {
|
|
333
374
|
await this.revert(source);
|
|
334
|
-
}
|
|
335
|
-
catch (error) {
|
|
375
|
+
} catch (error) {
|
|
336
376
|
this.logService.error(error);
|
|
337
377
|
}
|
|
338
378
|
if (source.scheme === Schemas.untitled) {
|
|
@@ -343,7 +383,7 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
343
383
|
async doSaveAsTextFile(sourceModel, source, target, options) {
|
|
344
384
|
let sourceModelEncoding = undefined;
|
|
345
385
|
const sourceModelWithEncodingSupport = sourceModel;
|
|
346
|
-
if (typeof sourceModelWithEncodingSupport.getEncoding ===
|
|
386
|
+
if (typeof sourceModelWithEncodingSupport.getEncoding === "function") {
|
|
347
387
|
sourceModelEncoding = sourceModelWithEncodingSupport.getEncoding();
|
|
348
388
|
}
|
|
349
389
|
let targetExists = false;
|
|
@@ -354,15 +394,18 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
354
394
|
else {
|
|
355
395
|
targetExists = await this.fileService.exists(target);
|
|
356
396
|
if (!targetExists) {
|
|
357
|
-
await this.create([{
|
|
397
|
+
await this.create([{
|
|
398
|
+
resource: target,
|
|
399
|
+
value: ""
|
|
400
|
+
}]);
|
|
358
401
|
}
|
|
359
402
|
try {
|
|
360
|
-
targetModel = await this.files.resolve(target, {
|
|
361
|
-
|
|
362
|
-
|
|
403
|
+
targetModel = await this.files.resolve(target, {
|
|
404
|
+
encoding: sourceModelEncoding
|
|
405
|
+
});
|
|
406
|
+
} catch (error) {
|
|
363
407
|
if (targetExists) {
|
|
364
|
-
if (error.textFileOperationResult === TextFileOperationResult.FILE_IS_BINARY ||
|
|
365
|
-
error.fileOperationResult === FileOperationResult.FILE_TOO_LARGE) {
|
|
408
|
+
if (error.textFileOperationResult === TextFileOperationResult.FILE_IS_BINARY || error.fileOperationResult === FileOperationResult.FILE_TOO_LARGE) {
|
|
366
409
|
await this.fileService.del(target);
|
|
367
410
|
return this.doSaveAsTextFile(sourceModel, source, target, options);
|
|
368
411
|
}
|
|
@@ -371,10 +414,13 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
371
414
|
}
|
|
372
415
|
}
|
|
373
416
|
let write;
|
|
374
|
-
if (sourceModel instanceof UntitledTextEditorModel && sourceModel.hasAssociatedFilePath && targetExists && this.uriIdentityService.extUri.isEqual(target, toLocalResource(
|
|
417
|
+
if (sourceModel instanceof UntitledTextEditorModel && sourceModel.hasAssociatedFilePath && targetExists && this.uriIdentityService.extUri.isEqual(target, toLocalResource(
|
|
418
|
+
sourceModel.resource,
|
|
419
|
+
this.environmentService.remoteAuthority,
|
|
420
|
+
this.pathService.defaultUriScheme
|
|
421
|
+
))) {
|
|
375
422
|
write = await this.confirmOverwrite(target);
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
423
|
+
} else {
|
|
378
424
|
write = true;
|
|
379
425
|
}
|
|
380
426
|
if (!write) {
|
|
@@ -385,8 +431,7 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
385
431
|
if (sourceModel.isResolved()) {
|
|
386
432
|
sourceTextModel = sourceModel.textEditorModel ?? undefined;
|
|
387
433
|
}
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
434
|
+
} else {
|
|
390
435
|
sourceTextModel = sourceModel;
|
|
391
436
|
}
|
|
392
437
|
let targetTextModel = undefined;
|
|
@@ -395,12 +440,23 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
395
440
|
}
|
|
396
441
|
if (sourceTextModel && targetTextModel) {
|
|
397
442
|
targetModel.updatePreferredEncoding(sourceModelEncoding);
|
|
398
|
-
this.modelService.updateModel(
|
|
443
|
+
this.modelService.updateModel(
|
|
444
|
+
targetTextModel,
|
|
445
|
+
createTextBufferFactoryFromSnapshot(sourceTextModel.createSnapshot())
|
|
446
|
+
);
|
|
399
447
|
const sourceLanguageId = sourceTextModel.getLanguageId();
|
|
400
448
|
const targetLanguageId = targetTextModel.getLanguageId();
|
|
401
449
|
if (sourceLanguageId !== PLAINTEXT_LANGUAGE_ID && targetLanguageId === PLAINTEXT_LANGUAGE_ID) {
|
|
402
450
|
targetTextModel.setLanguage(sourceLanguageId);
|
|
403
451
|
}
|
|
452
|
+
const sourceOptions = sourceTextModel.getOptions();
|
|
453
|
+
targetTextModel.updateOptions({
|
|
454
|
+
tabSize: sourceOptions.tabSize,
|
|
455
|
+
indentSize: sourceOptions.indentSize,
|
|
456
|
+
insertSpaces: sourceOptions.insertSpaces
|
|
457
|
+
});
|
|
458
|
+
const sourceEOL = sourceTextModel.getEndOfLineSequence();
|
|
459
|
+
targetTextModel.setEOL(sourceEOL);
|
|
404
460
|
const sourceTransientProperties = this.codeEditorService.getTransientModelProperties(sourceTextModel);
|
|
405
461
|
if (sourceTransientProperties) {
|
|
406
462
|
for (const [key, value] of sourceTransientProperties) {
|
|
@@ -420,33 +476,37 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
420
476
|
});
|
|
421
477
|
}
|
|
422
478
|
async confirmOverwrite(resource) {
|
|
423
|
-
const {
|
|
424
|
-
|
|
479
|
+
const {
|
|
480
|
+
confirmed
|
|
481
|
+
} = await this.dialogService.confirm({
|
|
482
|
+
type: "warning",
|
|
425
483
|
message: ( localize(
|
|
426
|
-
|
|
484
|
+
14696,
|
|
427
485
|
"'{0}' already exists. Do you want to replace it?",
|
|
428
486
|
basename(resource)
|
|
429
487
|
)),
|
|
430
488
|
detail: ( localize(
|
|
431
|
-
|
|
489
|
+
14697,
|
|
432
490
|
"A file or folder with the name '{0}' already exists in the folder '{1}'. Replacing it will overwrite its current contents.",
|
|
433
491
|
basename(resource),
|
|
434
492
|
basename(dirname(resource))
|
|
435
493
|
)),
|
|
436
|
-
primaryButton: ( localize(
|
|
494
|
+
primaryButton: ( localize(14698, "&&Replace"))
|
|
437
495
|
});
|
|
438
496
|
return confirmed;
|
|
439
497
|
}
|
|
440
498
|
async confirmMakeWriteable(resource) {
|
|
441
|
-
const {
|
|
442
|
-
|
|
499
|
+
const {
|
|
500
|
+
confirmed
|
|
501
|
+
} = await this.dialogService.confirm({
|
|
502
|
+
type: "warning",
|
|
443
503
|
message: ( localize(
|
|
444
|
-
|
|
504
|
+
14699,
|
|
445
505
|
"'{0}' is marked as read-only. Do you want to save anyway?",
|
|
446
506
|
basename(resource)
|
|
447
507
|
)),
|
|
448
|
-
detail: ( localize(
|
|
449
|
-
primaryButton: ( localize(
|
|
508
|
+
detail: ( localize(14700, "Paths can be configured as read-only via settings.")),
|
|
509
|
+
primaryButton: ( localize(14701, "&&Save Anyway"))
|
|
450
510
|
});
|
|
451
511
|
return confirmed;
|
|
452
512
|
}
|
|
@@ -466,15 +526,13 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
466
526
|
let nameCandidate;
|
|
467
527
|
if (await this.pathService.hasValidBasename(joinPath(defaultFilePath, model.name), model.name)) {
|
|
468
528
|
nameCandidate = model.name;
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
529
|
+
} else {
|
|
471
530
|
nameCandidate = basename(resource);
|
|
472
531
|
}
|
|
473
532
|
const languageId = model.getLanguageId();
|
|
474
533
|
if (languageId && languageId !== PLAINTEXT_LANGUAGE_ID) {
|
|
475
534
|
suggestedFilename = this.suggestFilename(languageId, nameCandidate);
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
535
|
+
} else {
|
|
478
536
|
suggestedFilename = nameCandidate;
|
|
479
537
|
}
|
|
480
538
|
}
|
|
@@ -529,30 +587,20 @@ let AbstractTextFileService = class AbstractTextFileService extends Disposable {
|
|
|
529
587
|
return false;
|
|
530
588
|
}
|
|
531
589
|
};
|
|
532
|
-
AbstractTextFileService = AbstractTextFileService_1 = ( __decorate([
|
|
533
|
-
( __param(0, IFileService)),
|
|
534
|
-
( __param(1, IUntitledTextEditorService)),
|
|
535
|
-
( __param(2, ILifecycleService)),
|
|
536
|
-
( __param(3, IInstantiationService)),
|
|
537
|
-
( __param(4, IModelService)),
|
|
538
|
-
( __param(5, IWorkbenchEnvironmentService)),
|
|
539
|
-
( __param(6, IDialogService)),
|
|
540
|
-
( __param(7, IFileDialogService)),
|
|
541
|
-
( __param(8, ITextResourceConfigurationService)),
|
|
542
|
-
( __param(9, IFilesConfigurationService)),
|
|
543
|
-
( __param(10, ICodeEditorService)),
|
|
544
|
-
( __param(11, IPathService)),
|
|
545
|
-
( __param(12, IWorkingCopyFileService)),
|
|
546
|
-
( __param(13, IUriIdentityService)),
|
|
547
|
-
( __param(14, ILanguageService)),
|
|
548
|
-
( __param(15, ILogService)),
|
|
549
|
-
( __param(16, IElevatedFileService)),
|
|
550
|
-
( __param(17, IDecorationsService))
|
|
551
|
-
], AbstractTextFileService));
|
|
590
|
+
AbstractTextFileService = AbstractTextFileService_1 = ( __decorate([( __param(0, IFileService)), ( __param(1, IUntitledTextEditorService)), ( __param(2, ILifecycleService)), ( __param(3, IInstantiationService)), ( __param(4, IModelService)), ( __param(5, IWorkbenchEnvironmentService)), ( __param(6, IDialogService)), ( __param(7, IFileDialogService)), ( __param(8, ITextResourceConfigurationService)), ( __param(9, IFilesConfigurationService)), ( __param(10, ICodeEditorService)), ( __param(11, IPathService)), ( __param(12, IWorkingCopyFileService)), ( __param(13, IUriIdentityService)), ( __param(14, ILanguageService)), ( __param(15, ILogService)), ( __param(16, IElevatedFileService)), ( __param(17, IDecorationsService))], AbstractTextFileService));
|
|
552
591
|
let EncodingOracle = class EncodingOracle extends Disposable {
|
|
553
|
-
get encodingOverrides() {
|
|
554
|
-
|
|
555
|
-
|
|
592
|
+
get encodingOverrides() {
|
|
593
|
+
return this._encodingOverrides;
|
|
594
|
+
}
|
|
595
|
+
set encodingOverrides(value) {
|
|
596
|
+
this._encodingOverrides = value;
|
|
597
|
+
}
|
|
598
|
+
constructor(
|
|
599
|
+
textResourceConfigurationService,
|
|
600
|
+
environmentService,
|
|
601
|
+
contextService,
|
|
602
|
+
uriIdentityService
|
|
603
|
+
) {
|
|
556
604
|
super();
|
|
557
605
|
this.textResourceConfigurationService = textResourceConfigurationService;
|
|
558
606
|
this.environmentService = environmentService;
|
|
@@ -562,21 +610,41 @@ let EncodingOracle = class EncodingOracle extends Disposable {
|
|
|
562
610
|
this.registerListeners();
|
|
563
611
|
}
|
|
564
612
|
registerListeners() {
|
|
565
|
-
this._register(
|
|
613
|
+
this._register(
|
|
614
|
+
this.contextService.onDidChangeWorkspaceFolders(() => this.encodingOverrides = this.getDefaultEncodingOverrides())
|
|
615
|
+
);
|
|
566
616
|
}
|
|
567
617
|
getDefaultEncodingOverrides() {
|
|
568
618
|
const defaultEncodingOverrides = [];
|
|
569
|
-
defaultEncodingOverrides.push({
|
|
570
|
-
|
|
571
|
-
|
|
619
|
+
defaultEncodingOverrides.push({
|
|
620
|
+
parent: this.environmentService.userRoamingDataHome,
|
|
621
|
+
encoding: UTF8
|
|
622
|
+
});
|
|
623
|
+
defaultEncodingOverrides.push({
|
|
624
|
+
extension: WORKSPACE_EXTENSION,
|
|
625
|
+
encoding: UTF8
|
|
626
|
+
});
|
|
627
|
+
defaultEncodingOverrides.push({
|
|
628
|
+
parent: this.environmentService.untitledWorkspacesHome,
|
|
629
|
+
encoding: UTF8
|
|
630
|
+
});
|
|
572
631
|
this.contextService.getWorkspace().folders.forEach(folder => {
|
|
573
|
-
defaultEncodingOverrides.push({
|
|
632
|
+
defaultEncodingOverrides.push({
|
|
633
|
+
parent: joinPath(folder.uri, ".vscode"),
|
|
634
|
+
encoding: UTF8
|
|
635
|
+
});
|
|
574
636
|
});
|
|
575
637
|
return defaultEncodingOverrides;
|
|
576
638
|
}
|
|
577
639
|
async getWriteEncoding(resource, options) {
|
|
578
|
-
const {
|
|
579
|
-
|
|
640
|
+
const {
|
|
641
|
+
encoding,
|
|
642
|
+
hasBOM
|
|
643
|
+
} = await this.getPreferredWriteEncoding(resource, options ? options.encoding : undefined);
|
|
644
|
+
return {
|
|
645
|
+
encoding,
|
|
646
|
+
addBOM: hasBOM
|
|
647
|
+
};
|
|
580
648
|
}
|
|
581
649
|
async getPreferredWriteEncoding(resource, preferredEncoding) {
|
|
582
650
|
const resourceEncoding = await this.getValidatedEncodingForResource(resource, preferredEncoding);
|
|
@@ -590,15 +658,14 @@ let EncodingOracle = class EncodingOracle extends Disposable {
|
|
|
590
658
|
if (options?.encoding) {
|
|
591
659
|
if (detectedEncoding === UTF8_with_bom && options.encoding === UTF8) {
|
|
592
660
|
preferredEncoding = UTF8_with_bom;
|
|
593
|
-
}
|
|
594
|
-
else {
|
|
661
|
+
} else {
|
|
595
662
|
preferredEncoding = options.encoding;
|
|
596
663
|
}
|
|
597
664
|
}
|
|
598
|
-
else if (typeof detectedEncoding ===
|
|
665
|
+
else if (typeof detectedEncoding === "string") {
|
|
599
666
|
preferredEncoding = detectedEncoding;
|
|
600
667
|
}
|
|
601
|
-
else if (this.textResourceConfigurationService.getValue(resource,
|
|
668
|
+
else if (this.textResourceConfigurationService.getValue(resource, "files.encoding") === UTF8_with_bom) {
|
|
602
669
|
preferredEncoding = UTF8;
|
|
603
670
|
}
|
|
604
671
|
const encoding = await this.getValidatedEncodingForResource(resource, preferredEncoding);
|
|
@@ -612,12 +679,10 @@ let EncodingOracle = class EncodingOracle extends Disposable {
|
|
|
612
679
|
const override = this.getEncodingOverride(resource);
|
|
613
680
|
if (override) {
|
|
614
681
|
fileEncoding = override;
|
|
615
|
-
}
|
|
616
|
-
else if (preferredEncoding) {
|
|
682
|
+
} else if (preferredEncoding) {
|
|
617
683
|
fileEncoding = preferredEncoding;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
fileEncoding = this.textResourceConfigurationService.getValue(resource, 'files.encoding');
|
|
684
|
+
} else {
|
|
685
|
+
fileEncoding = this.textResourceConfigurationService.getValue(resource, "files.encoding");
|
|
621
686
|
}
|
|
622
687
|
return fileEncoding || UTF8;
|
|
623
688
|
}
|
|
@@ -642,11 +707,6 @@ let EncodingOracle = class EncodingOracle extends Disposable {
|
|
|
642
707
|
return undefined;
|
|
643
708
|
}
|
|
644
709
|
};
|
|
645
|
-
EncodingOracle = ( __decorate([
|
|
646
|
-
( __param(0, ITextResourceConfigurationService)),
|
|
647
|
-
( __param(1, IWorkbenchEnvironmentService)),
|
|
648
|
-
( __param(2, IWorkspaceContextService)),
|
|
649
|
-
( __param(3, IUriIdentityService))
|
|
650
|
-
], EncodingOracle));
|
|
710
|
+
EncodingOracle = ( __decorate([( __param(0, ITextResourceConfigurationService)), ( __param(1, IWorkbenchEnvironmentService)), ( __param(2, IWorkspaceContextService)), ( __param(3, IUriIdentityService))], EncodingOracle));
|
|
651
711
|
|
|
652
712
|
export { AbstractTextFileService, EncodingOracle };
|