languageService.ts ×24

Frontier kind: Code frontier

unlabeled · c_d0365c1866b5

663 tests · 14981 LOC · 90 files · introduces 0 tests · 85 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
24 ranges85 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1693 ranges14981 lines · 90 files · Browse complete extent
All tests (intent)
663 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: 85 introduced LOC across 24 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/services/languageService.ts 85 introduced LOC · 24 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- languageService.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 { URI } from '../../../base/common/uri.js';
9 > import { LanguagesRegistry } from './languagesRegistry.js';
10 > import { ILanguageNameIdPair, ILanguageSelection, ILanguageService, ILanguageIcon, ILanguageExtensionPoint } from '../languages/language.js';
11 > import { ILanguageIdCodec, TokenizationRegistry } from '../languages.js';
12 > import { PLAINTEXT_LANGUAGE_ID } from '../languages/modesRegistry.js';
13 > import { IObservable, observableFromEvent } from '../../../base/common/observable.js';
14 >
15 > export class LanguageService extends Disposable implements ILanguageService {
16 > public _serviceBrand: undefined;
17 >
18 > static instanceCount = 0;
19 >
20 > private readonly _onDidRequestBasicLanguageFeatures = this._register(new Emitter<string>());
21 > public readonly onDidRequestBasicLanguageFeatures = this._onDidRequestBasicLanguageFeatures.event;
22 >
23 > private readonly _onDidRequestRichLanguageFeatures = this._register(new Emitter<string>());
24 > public readonly onDidRequestRichLanguageFeatures = this._onDidRequestRichLanguageFeatures.event;
25 >
26 > protected readonly _onDidChange = this._register(new Emitter<void>({ leakWarningThreshold: 200, leakWarningName: 'LanguageService._onDidChange' /* https://github.com/microsoft/vscode/issues/119968 */ }));
27 > public readonly onDidChange: Event<void> = this._onDidChange.event;
28 >
29 > private readonly _requestedBasicLanguages = new Set<string>();
30 > private readonly _requestedRichLanguages = new Set<string>();
31 >
32 > protected readonly _registry: LanguagesRegistry;
33 > public readonly languageIdCodec: ILanguageIdCodec;
34 >
35 > constructor(warnOnOverwrite = false) {
36 super();
37 LanguageService.instanceCount++;
40 this._register(this._registry.onDidChange(() => this._onDidChange.fire()));
41 }
43 > public override dispose(): void {
44 LanguageService.instanceCount--;
45 super.dispose();
46 }
48 > public registerLanguage(def: ILanguageExtensionPoint): IDisposable {
49 return this._registry.registerLanguage(def);
50 }
52 > public isRegisteredLanguageId(languageId: string | null | undefined): boolean {
53 return this._registry.isRegisteredLanguageId(languageId);
54 }
56 > public getRegisteredLanguageIds(): string[] {
57 return this._registry.getRegisteredLanguageIds();
58 }
60 > public getSortedRegisteredLanguageNames(): ILanguageNameIdPair[] {
61 return this._registry.getSortedRegisteredLanguageNames();
62 }
64 > public getLanguageName(languageId: string): string | null {
65 return this._registry.getLanguageName(languageId);
66 }
68 > public getMimeType(languageId: string): string | null {
69 return this._registry.getMimeType(languageId);
70 }
72 > public getIcon(languageId: string): ILanguageIcon | null {
73 return this._registry.getIcon(languageId);
74 }
76 > public getExtensions(languageId: string): ReadonlyArray<string> {
77 return this._registry.getExtensions(languageId);
78 }
80 > public getFilenames(languageId: string): ReadonlyArray<string> {
81 return this._registry.getFilenames(languageId);
82 }
84 > public getConfigurationFiles(languageId: string): ReadonlyArray<URI> {
85 return this._registry.getConfigurationFiles(languageId);
86 }
88 > public getLanguageIdByLanguageName(languageName: string): string | null {
89 return this._registry.getLanguageIdByLanguageName(languageName);
90 }
92 > public getLanguageIdByMimeType(mimeType: string | null | undefined): string | null {
93 return this._registry.getLanguageIdByMimeType(mimeType);
94 }
96 > public guessLanguageIdByFilepathOrFirstLine(resource: URI | null, firstLine?: string): string | null {
97 const languageIds = this._registry.guessLanguageIdByFilepathOrFirstLine(resource, firstLine);
98 return languageIds.at(0) ?? null;
99 }
101 > public createById(languageId: string | null | undefined): ILanguageSelection {
102 return new LanguageSelection(this.onDidChange, () => {
103 return this._createAndGetLanguageIdentifier(languageId);
104 });
105 }
107 > public createByMimeType(mimeType: string | null | undefined): ILanguageSelection {
108 return new LanguageSelection(this.onDidChange, () => {
109 const languageId = this.getLanguageIdByMimeType(mimeType);
111 });
112 }
114 > public createByFilepathOrFirstLine(resource: URI | null, firstLine?: string): ILanguageSelection {
115 return new LanguageSelection(this.onDidChange, () => {
116 const languageId = this.guessLanguageIdByFilepathOrFirstLine(resource, firstLine);
118 });
119 }
121 > private _createAndGetLanguageIdentifier(languageId: string | null | undefined): string {
122 if (!languageId || !this.isRegisteredLanguageId(languageId)) {
123 // Fall back to plain text if language is unknown
127 return languageId;
128 }
130 > public requestBasicLanguageFeatures(languageId: string): void {
131 if (!this._requestedBasicLanguages.has(languageId)) {
132 this._requestedBasicLanguages.add(languageId);
134 }
135 }
137 > public requestRichLanguageFeatures(languageId: string): void {
138 if (!this._requestedRichLanguages.has(languageId)) {
139 this._requestedRichLanguages.add(languageId);
148 }
149 }
151 >
152 > class LanguageSelection implements ILanguageSelection {
153 > private readonly _value: IObservable<string>;
154 > public readonly onDidChange: Event<string>;
155 >
156 > constructor(onDidChangeLanguages: Event<void>, selector: () => string) {
157 this._value = observableFromEvent(this, onDidChangeLanguages, () => selector());
158 this.onDidChange = Event.fromObservable(this._value);
159 }
161 > public get languageId(): string {
162 return this._value.get();
163 }