textfiles.ts 18.9 KB
Newer Older
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6
import { URI } from 'vs/base/common/uri';
7
import { Event, IWaitUntil } from 'vs/base/common/event';
J
Johannes Rieken 已提交
8
import { IDisposable } from 'vs/base/common/lifecycle';
9
import { IEncodingSupport, IModeSupport, ISaveOptions, IRevertOptions, SaveReason } from 'vs/workbench/common/editor';
10
import { IBaseStatWithMetadata, IFileStatWithMetadata, IReadFileOptions, IWriteFileOptions, FileOperationError, FileOperationResult, FileOperation } from 'vs/platform/files/common/files';
11
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
B
Benjamin Pasero 已提交
12
import { ITextEditorModel } from 'vs/editor/common/services/resolverService';
13 14 15
import { ITextBufferFactory, ITextModel, ITextSnapshot } from 'vs/editor/common/model';
import { VSBuffer, VSBufferReadable } from 'vs/base/common/buffer';
import { isUndefinedOrNull } from 'vs/base/common/types';
16
import { isNative } from 'vs/base/common/platform';
17
import { IWorkingCopy } from 'vs/workbench/services/workingCopy/common/workingCopyService';
18
import { IUntitledTextEditorModelManager } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
19
import { CancellationToken } from 'vs/base/common/cancellation';
20
import { IProgress, IProgressStep } from 'vs/platform/progress/common/progress';
21

B
Benjamin Pasero 已提交
22 23 24 25
export const ITextFileService = createDecorator<ITextFileService>('textFileService');

export interface ITextFileService extends IDisposable {

26
	_serviceBrand: undefined;
B
Benjamin Pasero 已提交
27

28 29 30 31 32 33 34 35 36 37
	/**
	 * An event that is fired before attempting a certain file operation.
	 */
	readonly onWillRunOperation: Event<FileOperationWillRunEvent>;

	/**
	 * An event that is fired after a file operation has been performed.
	 */
	readonly onDidRunOperation: Event<FileOperationDidRunEvent>;

B
Benjamin Pasero 已提交
38
	/**
39 40
	 * Access to the manager of text file editor models providing further
	 * methods to work with them.
B
Benjamin Pasero 已提交
41
	 */
42
	readonly files: ITextFileEditorModelManager;
B
Benjamin Pasero 已提交
43

44 45 46 47 48 49
	/**
	 * Access to the manager of untitled text editor models providing further
	 * methods to work with them.
	 */
	readonly untitled: IUntitledTextEditorModelManager;

B
Benjamin Pasero 已提交
50 51 52 53 54 55 56 57
	/**
	 * Helper to determine encoding for resources.
	 */
	readonly encoding: IResourceEncodings;

	/**
	 * A resource is dirty if it has unsaved changes or is an untitled file not yet saved.
	 *
58
	 * @param resource the resource to check for being dirty
B
Benjamin Pasero 已提交
59
	 */
60
	isDirty(resource: URI): boolean;
B
Benjamin Pasero 已提交
61 62 63 64 65 66

	/**
	 * Saves the resource.
	 *
	 * @param resource the resource to save
	 * @param options optional save options
67
	 * @return Path of the saved resource or undefined if canceled.
B
Benjamin Pasero 已提交
68
	 */
69
	save(resource: URI, options?: ITextFileSaveOptions): Promise<URI | undefined>;
B
Benjamin Pasero 已提交
70 71 72 73 74 75 76

	/**
	 * Saves the provided resource asking the user for a file name or using the provided one.
	 *
	 * @param resource the resource to save as.
	 * @param targetResource the optional target to save to.
	 * @param options optional save options
77
	 * @return Path of the saved resource or undefined if canceled.
B
Benjamin Pasero 已提交
78
	 */
79
	saveAs(resource: URI, targetResource?: URI, options?: ITextFileSaveOptions): Promise<URI | undefined>;
B
Benjamin Pasero 已提交
80 81 82 83 84 85 86 87 88 89 90 91

	/**
	 * Reverts the provided resource.
	 *
	 * @param resource the resource of the file to revert.
	 * @param force to force revert even when the file is not dirty
	 */
	revert(resource: URI, options?: IRevertOptions): Promise<boolean>;

	/**
	 * Read the contents of a file identified by the resource.
	 */
B
Benjamin Pasero 已提交
92
	read(resource: URI, options?: IReadTextFileOptions): Promise<ITextFileContent>;
B
Benjamin Pasero 已提交
93

94 95 96 97 98
	/**
	 * Read the contents of a file identified by the resource as stream.
	 */
	readStream(resource: URI, options?: IReadTextFileOptions): Promise<ITextFileStreamContent>;

B
Benjamin Pasero 已提交
99 100 101 102 103 104
	/**
	 * Update a file with given contents.
	 */
	write(resource: URI, value: string | ITextSnapshot, options?: IWriteTextFileOptions): Promise<IFileStatWithMetadata>;

	/**
B
Benjamin Pasero 已提交
105 106
	 * Create a file. If the file exists it will be overwritten with the contents if
	 * the options enable to overwrite.
B
Benjamin Pasero 已提交
107
	 */
B
Benjamin Pasero 已提交
108
	create(resource: URI, contents?: string | ITextSnapshot, options?: { overwrite?: boolean }): Promise<IFileStatWithMetadata>;
B
Benjamin Pasero 已提交
109 110 111 112

	/**
	 * Move a file. If the file is dirty, its contents will be preserved and restored.
	 */
113
	move(source: URI, target: URI, overwrite?: boolean): Promise<IFileStatWithMetadata>;
I
isidor 已提交
114 115 116 117 118

	/**
	 * Copy a file. If the file is dirty, its contents will be preserved and restored.
	 */
	copy(source: URI, target: URI, overwrite?: boolean): Promise<IFileStatWithMetadata>;
B
Benjamin Pasero 已提交
119 120 121 122 123

	/**
	 * Delete a file. If the file is dirty, it will get reverted and then deleted from disk.
	 */
	delete(resource: URI, options?: { useTrash?: boolean, recursive?: boolean }): Promise<void>;
B
Benjamin Pasero 已提交
124 125
}

J
Johannes Rieken 已提交
126 127 128 129
export interface FileOperationWillRunEvent extends IWaitUntil {
	operation: FileOperation;
	target: URI;
	source?: URI;
130 131 132 133 134 135 136 137 138 139 140
}

export class FileOperationDidRunEvent {

	constructor(
		readonly operation: FileOperation,
		readonly target: URI,
		readonly source?: URI | undefined
	) { }
}

141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
export interface IReadTextFileOptions extends IReadFileOptions {

	/**
	 * The optional acceptTextOnly parameter allows to fail this request early if the file
	 * contents are not textual.
	 */
	acceptTextOnly?: boolean;

	/**
	 * The optional encoding parameter allows to specify the desired encoding when resolving
	 * the contents of the file.
	 */
	encoding?: string;

	/**
	 * The optional guessEncoding parameter allows to guess encoding from content of the file.
	 */
	autoGuessEncoding?: boolean;
}

export interface IWriteTextFileOptions extends IWriteFileOptions {

	/**
	 * The encoding to use when updating a file.
	 */
	encoding?: string;

	/**
	 * If set to true, will enforce the selected encoding and not perform any detection using BOMs.
	 */
	overwriteEncoding?: boolean;

	/**
	 * Whether to overwrite a file even if it is readonly.
	 */
	overwriteReadonly?: boolean;

	/**
M
Maher Jendoubi 已提交
179
	 * Whether to write to the file as elevated (admin) user. When setting this option a prompt will
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
	 * ask the user to authenticate as super user.
	 */
	writeElevated?: boolean;
}

export const enum TextFileOperationResult {
	FILE_IS_BINARY
}

export class TextFileOperationError extends FileOperationError {
	constructor(message: string, public textFileOperationResult: TextFileOperationResult, public options?: IReadTextFileOptions & IWriteTextFileOptions) {
		super(message, FileOperationResult.FILE_OTHER_ERROR);
	}

	static isTextFileOperationError(obj: unknown): obj is TextFileOperationError {
		return obj instanceof Error && !isUndefinedOrNull((obj as TextFileOperationError).textFileOperationResult);
	}
}

export interface IResourceEncodings {
	getPreferredWriteEncoding(resource: URI, preferredEncoding?: string): IResourceEncoding;
}

export interface IResourceEncoding {
	encoding: string;
	hasBOM: boolean;
}

208
/**
N
Nick Schonning 已提交
209
 * The save error handler can be installed on the text file editor model to install code that executes when save errors occur.
210 211 212 213 214 215
 */
export interface ISaveErrorHandler {

	/**
	 * Called whenever a save fails.
	 */
B
Benjamin Pasero 已提交
216
	onSaveError(error: Error, model: ITextFileEditorModel): void;
217 218 219
}

/**
N
Nick Schonning 已提交
220
 * States the text file editor model can be in.
221
 */
222
export const enum ModelState {
B
Benjamin Pasero 已提交
223 224 225 226

	/**
	 * A model is saved.
	 */
227
	SAVED,
B
Benjamin Pasero 已提交
228 229 230 231

	/**
	 * A model is dirty.
	 */
232
	DIRTY,
B
Benjamin Pasero 已提交
233 234

	/**
235
	 * A model is currently being saved but this operation has not completed yet.
B
Benjamin Pasero 已提交
236
	 */
237
	PENDING_SAVE,
238 239 240 241 242

	/**
	 * A model is in conflict mode when changes cannot be saved because the
	 * underlying file has changed. Models in conflict mode are always dirty.
	 */
243
	CONFLICT,
244 245 246 247 248 249 250 251

	/**
	 * A model is in orphan state when the underlying file has been deleted.
	 */
	ORPHAN,

	/**
	 * Any error that happens during a save that is not causing the CONFLICT state.
M
Maher Jendoubi 已提交
252
	 * Models in error mode are always dirty.
253
	 */
254 255 256 257 258 259 260 261 262 263
	ERROR
}

export interface ITextFileOperationResult {
	results: IResult[];
}

export interface IResult {
	source: URI;
	target?: URI;
B
Benjamin Pasero 已提交
264
	error?: boolean;
265 266
}

267
export const enum LoadReason {
268 269 270 271 272
	EDITOR = 1,
	REFERENCE = 2,
	OTHER = 3
}

273
interface IBaseTextFileContent extends IBaseStatWithMetadata {
274 275

	/**
276
	 * The encoding of the content if known.
277
	 */
278 279 280 281
	encoding: string;
}

export interface ITextFileContent extends IBaseTextFileContent {
282 283

	/**
284
	 * The content of a text file.
285
	 */
286 287 288 289 290 291 292 293 294
	value: string;
}

export interface ITextFileStreamContent extends IBaseTextFileContent {

	/**
	 * The line grouped content of a text file.
	 */
	value: ITextBufferFactory;
295 296
}

297
export interface IModelLoadOrCreateOptions {
298

299 300 301 302
	/**
	 * Context why the model is being loaded or created.
	 */
	reason?: LoadReason;
303

304 305 306 307 308
	/**
	 * The language mode to use for the model text content.
	 */
	mode?: string;

309 310 311
	/**
	 * The encoding to use when resolving the model text content.
	 */
312
	encoding?: string;
313 314

	/**
315 316
	 * If the model was already loaded before, allows to trigger
	 * a reload of it to fetch the latest contents:
B
Benjamin Pasero 已提交
317
	 * - async: resolve() will return immediately and trigger
318
	 * a reload that will run in the background.
B
Benjamin Pasero 已提交
319
	 * - sync: resolve() will only return resolved when the
320
	 * model has finished reloading.
321
	 */
322 323 324
	reload?: {
		async: boolean
	};
325 326 327 328 329

	/**
	 * Allow to load a model even if we think it is a binary file.
	 */
	allowBinary?: boolean;
330 331
}

332 333 334 335 336 337 338 339 340 341
export interface ITextFileModelSaveEvent {
	model: ITextFileEditorModel;
	reason: SaveReason;
}

export interface ITextFileModelLoadEvent {
	model: ITextFileEditorModel;
	reason: LoadReason;
}

342 343 344 345 346 347 348 349 350 351 352 353 354 355
export interface ITextFileSaveParticipant {

	/**
	 * Participate in a save of a model. Allows to change the model
	 * before it is being saved to disk.
	 */
	participate(
		model: IResolvedTextFileEditorModel,
		context: { reason: SaveReason },
		progress: IProgress<IProgressStep>,
		token: CancellationToken
	): Promise<void>;
}

356 357
export interface ITextFileEditorModelManager {

358
	readonly onDidLoad: Event<ITextFileModelLoadEvent>;
359 360
	readonly onDidChangeDirty: Event<ITextFileEditorModel>;
	readonly onDidSaveError: Event<ITextFileEditorModel>;
361
	readonly onDidSave: Event<ITextFileModelSaveEvent>;
362 363 364
	readonly onDidRevert: Event<ITextFileEditorModel>;
	readonly onDidChangeEncoding: Event<ITextFileEditorModel>;
	readonly onDidChangeOrphaned: Event<ITextFileEditorModel>;
365

M
Matt Bierner 已提交
366
	get(resource: URI): ITextFileEditorModel | undefined;
B
Benjamin Pasero 已提交
367
	getAll(): ITextFileEditorModel[];
368

B
Benjamin Pasero 已提交
369
	resolve(resource: URI, options?: IModelLoadOrCreateOptions): Promise<ITextFileEditorModel>;
370

371 372 373
	addSaveParticipant(participant: ITextFileSaveParticipant): IDisposable;
	runSaveParticipants(model: IResolvedTextFileEditorModel, context: { reason: SaveReason; }, token: CancellationToken): Promise<void>

374 375
	saveErrorHandler: ISaveErrorHandler;

376
	disposeModel(model: ITextFileEditorModel): void;
377 378
}

379
export interface ITextFileSaveOptions extends ISaveOptions {
380 381
	overwriteReadonly?: boolean;
	overwriteEncoding?: boolean;
382
	writeElevated?: boolean;
383
	ignoreModifiedSince?: boolean;
384
	ignoreErrorHandler?: boolean;
385 386
}

387 388 389 390 391 392 393 394 395 396 397
export interface ILoadOptions {

	/**
	 * Go to disk bypassing any cache of the model if any.
	 */
	forceReadFromDisk?: boolean;

	/**
	 * Allow to load a model even if we think it is a binary file.
	 */
	allowBinary?: boolean;
398 399 400 401 402

	/**
	 * Context why the model is being loaded.
	 */
	reason?: LoadReason;
403 404
}

405
export interface ITextFileEditorModel extends ITextEditorModel, IEncodingSupport, IModeSupport, IWorkingCopy {
406

407
	readonly onDidChangeContent: Event<void>;
408
	readonly onDidLoad: Event<LoadReason>;
409
	readonly onDidSaveError: Event<void>;
410
	readonly onDidSave: Event<SaveReason>;
411 412 413
	readonly onDidRevert: Event<void>;
	readonly onDidChangeEncoding: Event<void>;
	readonly onDidChangeOrphaned: Event<void>;
414

415
	hasState(state: ModelState): boolean;
416

417
	updatePreferredEncoding(encoding: string | undefined): void;
418

419
	save(options?: ITextFileSaveOptions): Promise<boolean>;
420

J
Johannes Rieken 已提交
421
	load(options?: ILoadOptions): Promise<ITextFileEditorModel>;
B
Benjamin Pasero 已提交
422

423
	revert(options?: IRevertOptions): Promise<boolean>;
424

B
Benjamin Pasero 已提交
425 426
	isDirty(): this is IResolvedTextFileEditorModel;

427
	setDirty(dirty: boolean): void;
428

429 430
	getMode(): string | undefined;

431
	isResolved(): this is IResolvedTextFileEditorModel;
432

433 434 435
	isDisposed(): boolean;
}

436
export interface IResolvedTextFileEditorModel extends ITextFileEditorModel {
437

438
	readonly textEditorModel: ITextModel;
M
Matt Bierner 已提交
439 440

	createSnapshot(): ITextSnapshot;
441 442
}

443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
export function snapshotToString(snapshot: ITextSnapshot): string {
	const chunks: string[] = [];

	let chunk: string | null;
	while (typeof (chunk = snapshot.read()) === 'string') {
		chunks.push(chunk);
	}

	return chunks.join('');
}

export function stringToSnapshot(value: string): ITextSnapshot {
	let done = false;

	return {
		read(): string | null {
			if (!done) {
				done = true;

				return value;
			}

			return null;
		}
	};
}

export class TextSnapshotReadable implements VSBufferReadable {
471
	private preambleHandled = false;
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514

	constructor(private snapshot: ITextSnapshot, private preamble?: string) { }

	read(): VSBuffer | null {
		let value = this.snapshot.read();

		// Handle preamble if provided
		if (!this.preambleHandled) {
			this.preambleHandled = true;

			if (typeof this.preamble === 'string') {
				if (typeof value === 'string') {
					value = this.preamble + value;
				} else {
					value = this.preamble;
				}
			}
		}

		if (typeof value === 'string') {
			return VSBuffer.fromString(value);
		}

		return null;
	}
}

export function toBufferOrReadable(value: string): VSBuffer;
export function toBufferOrReadable(value: ITextSnapshot): VSBufferReadable;
export function toBufferOrReadable(value: string | ITextSnapshot): VSBuffer | VSBufferReadable;
export function toBufferOrReadable(value: string | ITextSnapshot | undefined): VSBuffer | VSBufferReadable | undefined;
export function toBufferOrReadable(value: string | ITextSnapshot | undefined): VSBuffer | VSBufferReadable | undefined {
	if (typeof value === 'undefined') {
		return undefined;
	}

	if (typeof value === 'string') {
		return VSBuffer.fromString(value);
	}

	return new TextSnapshotReadable(value);
}

515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768
export const SUPPORTED_ENCODINGS: { [encoding: string]: { labelLong: string; labelShort: string; order: number; encodeOnly?: boolean; alias?: string } } =

	// Desktop
	isNative ?
		{
			utf8: {
				labelLong: 'UTF-8',
				labelShort: 'UTF-8',
				order: 1,
				alias: 'utf8bom'
			},
			utf8bom: {
				labelLong: 'UTF-8 with BOM',
				labelShort: 'UTF-8 with BOM',
				encodeOnly: true,
				order: 2,
				alias: 'utf8'
			},
			utf16le: {
				labelLong: 'UTF-16 LE',
				labelShort: 'UTF-16 LE',
				order: 3
			},
			utf16be: {
				labelLong: 'UTF-16 BE',
				labelShort: 'UTF-16 BE',
				order: 4
			},
			windows1252: {
				labelLong: 'Western (Windows 1252)',
				labelShort: 'Windows 1252',
				order: 5
			},
			iso88591: {
				labelLong: 'Western (ISO 8859-1)',
				labelShort: 'ISO 8859-1',
				order: 6
			},
			iso88593: {
				labelLong: 'Western (ISO 8859-3)',
				labelShort: 'ISO 8859-3',
				order: 7
			},
			iso885915: {
				labelLong: 'Western (ISO 8859-15)',
				labelShort: 'ISO 8859-15',
				order: 8
			},
			macroman: {
				labelLong: 'Western (Mac Roman)',
				labelShort: 'Mac Roman',
				order: 9
			},
			cp437: {
				labelLong: 'DOS (CP 437)',
				labelShort: 'CP437',
				order: 10
			},
			windows1256: {
				labelLong: 'Arabic (Windows 1256)',
				labelShort: 'Windows 1256',
				order: 11
			},
			iso88596: {
				labelLong: 'Arabic (ISO 8859-6)',
				labelShort: 'ISO 8859-6',
				order: 12
			},
			windows1257: {
				labelLong: 'Baltic (Windows 1257)',
				labelShort: 'Windows 1257',
				order: 13
			},
			iso88594: {
				labelLong: 'Baltic (ISO 8859-4)',
				labelShort: 'ISO 8859-4',
				order: 14
			},
			iso885914: {
				labelLong: 'Celtic (ISO 8859-14)',
				labelShort: 'ISO 8859-14',
				order: 15
			},
			windows1250: {
				labelLong: 'Central European (Windows 1250)',
				labelShort: 'Windows 1250',
				order: 16
			},
			iso88592: {
				labelLong: 'Central European (ISO 8859-2)',
				labelShort: 'ISO 8859-2',
				order: 17
			},
			cp852: {
				labelLong: 'Central European (CP 852)',
				labelShort: 'CP 852',
				order: 18
			},
			windows1251: {
				labelLong: 'Cyrillic (Windows 1251)',
				labelShort: 'Windows 1251',
				order: 19
			},
			cp866: {
				labelLong: 'Cyrillic (CP 866)',
				labelShort: 'CP 866',
				order: 20
			},
			iso88595: {
				labelLong: 'Cyrillic (ISO 8859-5)',
				labelShort: 'ISO 8859-5',
				order: 21
			},
			koi8r: {
				labelLong: 'Cyrillic (KOI8-R)',
				labelShort: 'KOI8-R',
				order: 22
			},
			koi8u: {
				labelLong: 'Cyrillic (KOI8-U)',
				labelShort: 'KOI8-U',
				order: 23
			},
			iso885913: {
				labelLong: 'Estonian (ISO 8859-13)',
				labelShort: 'ISO 8859-13',
				order: 24
			},
			windows1253: {
				labelLong: 'Greek (Windows 1253)',
				labelShort: 'Windows 1253',
				order: 25
			},
			iso88597: {
				labelLong: 'Greek (ISO 8859-7)',
				labelShort: 'ISO 8859-7',
				order: 26
			},
			windows1255: {
				labelLong: 'Hebrew (Windows 1255)',
				labelShort: 'Windows 1255',
				order: 27
			},
			iso88598: {
				labelLong: 'Hebrew (ISO 8859-8)',
				labelShort: 'ISO 8859-8',
				order: 28
			},
			iso885910: {
				labelLong: 'Nordic (ISO 8859-10)',
				labelShort: 'ISO 8859-10',
				order: 29
			},
			iso885916: {
				labelLong: 'Romanian (ISO 8859-16)',
				labelShort: 'ISO 8859-16',
				order: 30
			},
			windows1254: {
				labelLong: 'Turkish (Windows 1254)',
				labelShort: 'Windows 1254',
				order: 31
			},
			iso88599: {
				labelLong: 'Turkish (ISO 8859-9)',
				labelShort: 'ISO 8859-9',
				order: 32
			},
			windows1258: {
				labelLong: 'Vietnamese (Windows 1258)',
				labelShort: 'Windows 1258',
				order: 33
			},
			gbk: {
				labelLong: 'Simplified Chinese (GBK)',
				labelShort: 'GBK',
				order: 34
			},
			gb18030: {
				labelLong: 'Simplified Chinese (GB18030)',
				labelShort: 'GB18030',
				order: 35
			},
			cp950: {
				labelLong: 'Traditional Chinese (Big5)',
				labelShort: 'Big5',
				order: 36
			},
			big5hkscs: {
				labelLong: 'Traditional Chinese (Big5-HKSCS)',
				labelShort: 'Big5-HKSCS',
				order: 37
			},
			shiftjis: {
				labelLong: 'Japanese (Shift JIS)',
				labelShort: 'Shift JIS',
				order: 38
			},
			eucjp: {
				labelLong: 'Japanese (EUC-JP)',
				labelShort: 'EUC-JP',
				order: 39
			},
			euckr: {
				labelLong: 'Korean (EUC-KR)',
				labelShort: 'EUC-KR',
				order: 40
			},
			windows874: {
				labelLong: 'Thai (Windows 874)',
				labelShort: 'Windows 874',
				order: 41
			},
			iso885911: {
				labelLong: 'Latin/Thai (ISO 8859-11)',
				labelShort: 'ISO 8859-11',
				order: 42
			},
			koi8ru: {
				labelLong: 'Cyrillic (KOI8-RU)',
				labelShort: 'KOI8-RU',
				order: 43
			},
			koi8t: {
				labelLong: 'Tajik (KOI8-T)',
				labelShort: 'KOI8-T',
				order: 44
			},
			gb2312: {
				labelLong: 'Simplified Chinese (GB 2312)',
				labelShort: 'GB 2312',
				order: 45
			},
			cp865: {
				labelLong: 'Nordic DOS (CP 865)',
				labelShort: 'CP 865',
				order: 46
			},
			cp850: {
				labelLong: 'Western European DOS (CP 850)',
				labelShort: 'CP 850',
				order: 47
			}
		} :

		// Web (https://github.com/microsoft/vscode/issues/79275)
		{
			utf8: {
				labelLong: 'UTF-8',
				labelShort: 'UTF-8',
				order: 1,
				alias: 'utf8bom'
			}
		};