1
>
/*---------------------------------------------------------------------------------------------
languagesAssociations.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 { ParsedPattern, parse } from '../../../base/common/glob.js';
7
>
import { Mimes } from '../../../base/common/mime.js';
8
>
import { Schemas } from '../../../base/common/network.js';
9
>
import { basename, posix } from '../../../base/common/path.js';
10
>
import { DataUri } from '../../../base/common/resources.js';
11
>
import { endsWithIgnoreCase, equals, startsWithUTF8BOM } from '../../../base/common/strings.js';
12
>
import { URI } from '../../../base/common/uri.js';
13
>
import { PLAINTEXT_LANGUAGE_ID } from '../languages/modesRegistry.js';
14
>
15
>
export interface ILanguageAssociation {
16
>
readonly id: string;
17
>
readonly mime: string;
18
>
readonly filename?: string;
19
>
readonly extension?: string;
20
>
readonly filepattern?: string;
21
>
readonly firstline?: RegExp;
22
>
}
23
>
24
>
interface ILanguageAssociationItem extends ILanguageAssociation {
25
>
readonly userConfigured: boolean;
26
>
readonly filepatternParsed?: ParsedPattern;
27
>
readonly filepatternOnPath?: boolean;
28
>
}
29
>
30
>
let registeredAssociations: ILanguageAssociationItem[] = [];
31
>
let nonUserRegisteredAssociations: ILanguageAssociationItem[] = [];
32
>
let userRegisteredAssociations: ILanguageAssociationItem[] = [];
33
>
34
>
/**
35
>
* Associate a language to the registry (platform).
36
>
* * **NOTE**: This association will lose over associations registered using `registerConfiguredLanguageAssociation`.
37
>
* * **NOTE**: Use `clearPlatformLanguageAssociations` to remove all associations registered using this function.
38
>
*/
39
>
export function registerPlatformLanguageAssociation(association: ILanguageAssociation, warnOnOverwrite = false): void {
40
_registerLanguageAssociation(association, false, warnOnOverwrite);
41
}
43
>
/**
44
>
* Associate a language to the registry (configured).
45
>
* * **NOTE**: This association will win over associations registered using `registerPlatformLanguageAssociation`.
46
>
* * **NOTE**: Use `clearConfiguredLanguageAssociations` to remove all associations registered using this function.
47
>
*/
48
>
export function registerConfiguredLanguageAssociation(association: ILanguageAssociation): void {
49
_registerLanguageAssociation(association, true, false);
50
}
52
function _registerLanguageAssociation(association: ILanguageAssociation, userConfigured: boolean, warnOnOverwrite: boolean): void {
53