languagesRegistry.ts ×26

Frontier kind: Code frontier

unlabeled · c_7eb64b753fbf

699 tests · 8959 LOC · 44 files · introduces 0 tests · 103 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
26 ranges103 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1219 ranges8959 lines · 44 files · Browse complete extent
All tests (intent)
699 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: 103 introduced LOC across 26 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/services/languagesRegistry.ts 103 introduced LOC · 26 ranges

Open complete file

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;
54 this._register(language, languageId);
55 }
57 > public encodeLanguageId(languageId: string): LanguageId {
58 return this._languageToLanguageId.get(languageId) || LanguageId.Null;
59 }
61 > public decodeLanguageId(languageId: LanguageId): string {
62 return this._languageIdToLanguage[languageId] || NULL_LANGUAGE_ID;
63 }
65 >
66 > export class LanguagesRegistry extends Disposable {
67 >
68 > static instanceCount = 0;
69 >
70 > private readonly _onDidChange: Emitter<void> = this._register(new Emitter<void>());
71 > public readonly onDidChange: Event<void> = this._onDidChange.event;
72 >
73 > private readonly _warnOnOverwrite: boolean;
74 > public readonly languageIdCodec: LanguageIdCodec;
75 > private _dynamicLanguages: ILanguageExtensionPoint[];
76 > private _languages: { [id: string]: IResolvedLanguage };
77 > private _mimeTypesMap: { [mimeType: string]: string };
78 > private _nameMap: { [name: string]: string };
79 > private _lowercaseNameMap: { [name: string]: string };
80 >
81 > constructor(useModesRegistry = true, warnOnOverwrite = false) {
82 super();
83 LanguagesRegistry.instanceCount++;
98 }
99 }
101 > override dispose() {
102 LanguagesRegistry.instanceCount--;
103 super.dispose();
104 }
106 > public setDynamicLanguages(def: ILanguageExtensionPoint[]): void {
107 this._dynamicLanguages = def;
108 this._initializeFromRegistry();
109 }
111 > private _initializeFromRegistry(): void {
112 this._languages = {};
113 this._mimeTypesMap = {};
119 this._registerLanguages(desc);
120 }
122 > registerLanguage(desc: ILanguageExtensionPoint): IDisposable {
123 return ModesRegistry.registerLanguage(desc);
124 }
126 > _registerLanguages(desc: ILanguageExtensionPoint[]): void {
127
128 for (const d of desc) {
151 this._onDidChange.fire();
152 }
154 > private _registerLanguage(lang: ILanguageExtensionPoint): void {
155 const langId = lang.id;
156
175 this._mergeLanguage(resolvedLanguage, lang);
176 }
178 > private _mergeLanguage(resolvedLanguage: IResolvedLanguage, lang: ILanguageExtensionPoint): void {
179 const langId = lang.id;
180
271 }
272 }
274 > public isRegisteredLanguageId(languageId: string | null | undefined): boolean {
275 if (!languageId) {
276 return false;
278 return hasOwnProperty.call(this._languages, languageId);
279 }
281 > public getRegisteredLanguageIds(): string[] {
282 return Object.keys(this._languages);
283 }
285 > public getSortedRegisteredLanguageNames(): ILanguageNameIdPair[] {
286 const result: ILanguageNameIdPair[] = [];
287 for (const languageName in this._nameMap) {
296 return result;
297 }
299 > public getLanguageName(languageId: string): string | null {
300 if (!hasOwnProperty.call(this._languages, languageId)) {
301 return null;
303 return this._languages[languageId].name;
304 }
306 > public getMimeType(languageId: string): string | null {
307 if (!hasOwnProperty.call(this._languages, languageId)) {
308 return null;
311 return (language.mimetypes[0] || null);
312 }
314 > public getExtensions(languageId: string): ReadonlyArray<string> {
315 if (!hasOwnProperty.call(this._languages, languageId)) {
316 return [];
318 return this._languages[languageId].extensions;
319 }
321 > public getFilenames(languageId: string): ReadonlyArray<string> {
322 if (!hasOwnProperty.call(this._languages, languageId)) {
323 return [];
325 return this._languages[languageId].filenames;
326 }
328 > public getIcon(languageId: string): ILanguageIcon | null {
329 if (!hasOwnProperty.call(this._languages, languageId)) {
330 return null;
333 return (language.icons[0] || null);
334 }
336 > public getConfigurationFiles(languageId: string): ReadonlyArray<URI> {
337 if (!hasOwnProperty.call(this._languages, languageId)) {
338 return [];
340 return this._languages[languageId].configurationFiles || [];
341 }
343 > public getLanguageIdByLanguageName(languageName: string): string | null {
344 const languageNameLower = languageName.toLowerCase();
345 if (!hasOwnProperty.call(this._lowercaseNameMap, languageNameLower)) {
348 return this._lowercaseNameMap[languageNameLower];
349 }
351 > public getLanguageIdByMimeType(mimeType: string | null | undefined): string | null {
352 if (!mimeType) {
353 return null;
358 return null;
359 }
361 > public guessLanguageIdByFilepathOrFirstLine(resource: URI | null, firstLine?: string): string[] {
362 if (!resource && !firstLine) {
363 return [];