Path: blob/main/src/vs/editor/common/services/semanticTokensStylingService.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Disposable } from '../../../base/common/lifecycle.js';6import { ILanguageService } from '../languages/language.js';7import { DocumentTokensProvider } from './model.js';8import { IThemeService } from '../../../platform/theme/common/themeService.js';9import { ILogService } from '../../../platform/log/common/log.js';10import { SemanticTokensProviderStyling } from './semanticTokensProviderStyling.js';11import { ISemanticTokensStylingService } from './semanticTokensStyling.js';12import { InstantiationType, registerSingleton } from '../../../platform/instantiation/common/extensions.js';1314export class SemanticTokensStylingService extends Disposable implements ISemanticTokensStylingService {1516public _serviceBrand: undefined;1718private _caches: WeakMap<DocumentTokensProvider, SemanticTokensProviderStyling>;1920constructor(21@IThemeService private readonly _themeService: IThemeService,22@ILogService private readonly _logService: ILogService,23@ILanguageService private readonly _languageService: ILanguageService,24) {25super();26this._caches = new WeakMap<DocumentTokensProvider, SemanticTokensProviderStyling>();27this._register(this._themeService.onDidColorThemeChange(() => {28this._caches = new WeakMap<DocumentTokensProvider, SemanticTokensProviderStyling>();29}));30}3132public getStyling(provider: DocumentTokensProvider): SemanticTokensProviderStyling {33if (!this._caches.has(provider)) {34this._caches.set(provider, new SemanticTokensProviderStyling(provider.getLegend(), this._themeService, this._languageService, this._logService));35}36return this._caches.get(provider)!;37}38}3940registerSingleton(ISemanticTokensStylingService, SemanticTokensStylingService, InstantiationType.Delayed);414243