1
>
/*---------------------------------------------------------------------------------------------
languagesRegistry.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { Emitter, Event } from '../../../base/common/event.js';
7
>
import { Disposable, IDisposable } from '../../../base/common/lifecycle.js';
8
>
import { compareIgnoreCase, regExpLeadsToEndlessLoop } from '../../../base/common/strings.js';
9
>
import { clearPlatformLanguageAssociations, getLanguageIds, registerPlatformLanguageAssociation } from './languagesAssociations.js';
10
>
import { URI } from '../../../base/common/uri.js';
11
>
import { ILanguageIdCodec } from '../languages.js';
12
>
import { LanguageId } from '../encodedTokenAttributes.js';
13
>
import { ModesRegistry, PLAINTEXT_LANGUAGE_ID } from '../languages/modesRegistry.js';
14
>
import { ILanguageExtensionPoint, ILanguageNameIdPair, ILanguageIcon } from '../languages/language.js';
15
>
import { Extensions, IConfigurationRegistry } from '../../../platform/configuration/common/configurationRegistry.js';
16
>
import { Registry } from '../../../platform/registry/common/platform.js';
17
>
18
>
const hasOwnProperty = Object.prototype.hasOwnProperty;
19
>
const NULL_LANGUAGE_ID = 'vs.editor.nullLanguage';
20
>
21
>
interface IResolvedLanguage {
22
>
identifier: string;
23
>
name: string | null;
24
>
mimetypes: string[];
25
>
aliases: string[];
26
>
extensions: string[];
27
>
filenames: string[];
28
>
configurationFiles: URI[];
29
>
icons: ILanguageIcon[];
30
>
}
31
>
32
>
export class LanguageIdCodec implements ILanguageIdCodec {
33
>
34
>
private _nextLanguageId: number;
35
>
private readonly _languageIdToLanguage: string[] = [];
36
>
private readonly _languageToLanguageId = new Map<string, number>();
37
>
38
>
constructor() {
39
this._register(NULL_LANGUAGE_ID, LanguageId.Null);
40
this._register(PLAINTEXT_LANGUAGE_ID, LanguageId.PlainText);
41
this._nextLanguageId = 2;
42
}
44
>
private _register(language: string, languageId: LanguageId): void {
45
this._languageIdToLanguage[languageId] = language;
46
this._languageToLanguageId.set(language, languageId);
47
}
49
>
public register(language: string): void {
50
if (this._languageToLanguageId.has(language)) {
51
return;