src/vs/editor/common/tokenizationRegistry.ts
152 LOC · 89 covered · 63 uncovered · 24 ranges · 2653 concepts · 6 introducers · 1317 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
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 related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
languages.ts ×27
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Color } from '../../base/common/color.js';
import { Emitter, Event } from '../../base/common/event.js';
import { Disposable, IDisposable, toDisposable } from '../../base/common/lifecycle.js';
import { ITokenizationRegistry, ITokenizationSupportChangedEvent, ILazyTokenizationSupport } from './languages.js';
import { ColorId } from './encodedTokenAttributes.js';
export class TokenizationRegistry<TSupport> implements ITokenizationRegistry<TSupport> {
private readonly _tokenizationSupports = new Map<string, TSupport>();
private readonly _factories = new Map<string, TokenizationSupportFactoryData<TSupport>>();
private readonly _onDidChange = new Emitter<ITokenizationSupportChangedEvent>();
public readonly onDidChange: Event<ITokenizationSupportChangedEvent> = this._onDidChange.event;
private _colorMap: Color[] | null;
constructor() {
this._colorMap = null;
}
public handleChange(languageIds: string[]): void {
changedLanguages: languageIds,
changedColorMap: false
});
}
public register(languageId: string, support: TSupport): IDisposable {
this.handleChange([languageId]);
return toDisposable(() => {
if (this._tokenizationSupports.get(languageId) !== support) {
return;
}
this.handleChange([languageId]);
});
}
public get(languageId: string): TSupport | null {
}
public registerFactory(languageId: string, factory: ILazyTokenizationSupport<TSupport>): IDisposable {
this._factories.get(languageId)?.dispose();
const myData = new TokenizationSupportFactoryData(this, languageId, factory);
this._factories.set(languageId, myData);
return toDisposable(() => {
const v = this._factories.get(languageId);
if (!v || v !== myData) {
return;
}
this._factories.delete(languageId);
v.dispose();
});
}
public async getOrCreate(languageId: string): Promise<TSupport | null> {
const tokenizationSupport = this.get(languageId);
if (tokenizationSupport) {
}
const factory = this._factories.get(languageId);
return null;
}
await factory.resolve();
return this.get(languageId);
public isResolved(languageId: string): boolean {
const tokenizationSupport = this.get(languageId);
if (tokenizationSupport) {
return true;
}
const factory = this._factories.get(languageId);
if (!factory || factory.isResolved) {
return true;
}
return false;
}
public setColorMap(colorMap: Color[]): void {
this._colorMap = colorMap;
this._onDidChange.fire({
changedLanguages: Array.from(this._tokenizationSupports.keys()),
changedColorMap: true
});
}
public getColorMap(): Color[] | null {
return this._colorMap;
}
public getDefaultBackground(): Color | null {
if (this._colorMap && this._colorMap.length > ColorId.DefaultBackground) {
return this._colorMap[ColorId.DefaultBackground];
}
return null;
}
class TokenizationSupportFactoryData<TSupport> extends Disposable {
private _isDisposed: boolean = false;
private _resolvePromise: Promise<void> | null = null;
private _isResolved: boolean = false;
public get isResolved(): boolean {
return this._isResolved;
}
constructor(
private readonly _registry: TokenizationRegistry<TSupport>,
private readonly _languageId: string,
private readonly _factory: ILazyTokenizationSupport<TSupport>,
) {
super();
}
public override dispose(): void {
this._isDisposed = true;
super.dispose();
}
public async resolve(): Promise<void> {
if (!this._resolvePromise) {
this._resolvePromise = this._create();
}
return this._resolvePromise;
}
private async _create(): Promise<void> {
const value = await this._factory.tokenizationSupport;
this._isResolved = true;
if (value && !this._isDisposed) {
this._register(this._registry.register(this._languageId, value));
}
}