Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/services/semanticTokensStylingService.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
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 { Disposable } from '../../../base/common/lifecycle.js';
7
import { ILanguageService } from '../languages/language.js';
8
import { DocumentTokensProvider } from './model.js';
9
import { IThemeService } from '../../../platform/theme/common/themeService.js';
10
import { ILogService } from '../../../platform/log/common/log.js';
11
import { SemanticTokensProviderStyling } from './semanticTokensProviderStyling.js';
12
import { ISemanticTokensStylingService } from './semanticTokensStyling.js';
13
import { InstantiationType, registerSingleton } from '../../../platform/instantiation/common/extensions.js';
14
15
export class SemanticTokensStylingService extends Disposable implements ISemanticTokensStylingService {
16
17
public _serviceBrand: undefined;
18
19
private _caches: WeakMap<DocumentTokensProvider, SemanticTokensProviderStyling>;
20
21
constructor(
22
@IThemeService private readonly _themeService: IThemeService,
23
@ILogService private readonly _logService: ILogService,
24
@ILanguageService private readonly _languageService: ILanguageService,
25
) {
26
super();
27
this._caches = new WeakMap<DocumentTokensProvider, SemanticTokensProviderStyling>();
28
this._register(this._themeService.onDidColorThemeChange(() => {
29
this._caches = new WeakMap<DocumentTokensProvider, SemanticTokensProviderStyling>();
30
}));
31
}
32
33
public getStyling(provider: DocumentTokensProvider): SemanticTokensProviderStyling {
34
if (!this._caches.has(provider)) {
35
this._caches.set(provider, new SemanticTokensProviderStyling(provider.getLegend(), this._themeService, this._languageService, this._logService));
36
}
37
return this._caches.get(provider)!;
38
}
39
}
40
41
registerSingleton(ISemanticTokensStylingService, SemanticTokensStylingService, InstantiationType.Delayed);
42
43