languagesAssociations.ts ×11

Frontier kind: Code frontier

unlabeled · c_b82d24a47f91

709 tests · 8728 LOC · 42 files · introduces 0 tests · 77 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
11 ranges77 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1183 ranges8728 lines · 42 files · Browse complete extent
All tests (intent)
709 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 77 introduced LOC across 11 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/services/languagesAssociations.ts 77 introduced LOC · 11 ranges

Open complete file

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
86 }
87 }
89 function toLanguageAssociationItem(association: ILanguageAssociation, userConfigured: boolean): ILanguageAssociationItem {
90 return {
100 };
101 }
103 > /**
104 > * Clear language associations from the registry (platform).
105 > */
106 > export function clearPlatformLanguageAssociations(): void {
107 registeredAssociations = registeredAssociations.filter(a => a.userConfigured);
108 nonUserRegisteredAssociations = [];
109 }
111 > /**
112 > * Clear language associations from the registry (configured).
113 > */
114 > export function clearConfiguredLanguageAssociations(): void {
115 registeredAssociations = registeredAssociations.filter(a => !a.userConfigured);
116 userRegisteredAssociations = [];
117 }
119 > interface IdAndMime {
120 > id: string;
121 > mime: string;
122 > }
123 >
124 > /**
125 > * Given a file, return the best matching mime types for it
126 > * based on the registered language associations.
127 > */
128 > export function getMimeTypes(resource: URI | null, firstLine?: string): string[] {
129 return getAssociations(resource, firstLine).map(item => item.mime);
130 }
132 > /**
133 > * @see `getMimeTypes`
134 > */
135 > export function getLanguageIds(resource: URI | null, firstLine?: string): string[] {
136 return getAssociations(resource, firstLine).map(item => item.id);
137 }
139 function getAssociations(resource: URI | null, firstLine?: string): IdAndMime[] {
140 let path: string | undefined;
188 return [{ id: 'unknown', mime: Mimes.unknown }];
189 }
191 function getAssociationByPath(path: string, filename: string, associations: ILanguageAssociationItem[]): ILanguageAssociationItem | undefined {
192 let filenameMatch: ILanguageAssociationItem | undefined = undefined;
242 return undefined;
243 }
245 function getAssociationByFirstline(firstLine: string): ILanguageAssociationItem | undefined {
246 if (startsWithUTF8BOM(firstLine)) {