From cb1ce1638db3d40b19a35b0a707ecff19e3dbb11 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 2 Apr 2020 01:27:22 +0200 Subject: [PATCH] Fixes #94211: Disable semantic highlighting when the setting asks to disable it or when a theme did not opt in --- .../common/services/modelServiceImpl.ts | 25 ++++++++++--------- .../viewportSemanticTokens.ts | 20 ++++++++++++++- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/vs/editor/common/services/modelServiceImpl.ts b/src/vs/editor/common/services/modelServiceImpl.ts index d54dcf68d6a..494144eddf2 100644 --- a/src/vs/editor/common/services/modelServiceImpl.ts +++ b/src/vs/editor/common/services/modelServiceImpl.ts @@ -577,9 +577,17 @@ export interface ILineSequence { getLineContent(lineNumber: number): string; } -class SemanticColoringFeature extends Disposable { +export const SEMANTIC_HIGHLIGHTING_SETTING_ID = 'editor.semanticHighlighting'; + +export function isSemanticColoringEnabled(model: ITextModel, themeService: IThemeService, configurationService: IConfigurationService): boolean { + if (!themeService.getColorTheme().semanticHighlighting) { + return false; + } + const options = configurationService.getValue(SEMANTIC_HIGHLIGHTING_SETTING_ID, { overrideIdentifier: model.getLanguageIdentifier().language, resource: model.uri }); + return Boolean(options && options.enabled); +} - private static readonly SETTING_ID = 'editor.semanticHighlighting'; +class SemanticColoringFeature extends Disposable { private readonly _watchers: Record; private readonly _semanticStyling: SemanticStyling; @@ -589,13 +597,6 @@ class SemanticColoringFeature extends Disposable { this._watchers = Object.create(null); this._semanticStyling = semanticStyling; - const isSemanticColoringEnabled = (model: ITextModel) => { - if (!themeService.getColorTheme().semanticHighlighting) { - return false; - } - const options = configurationService.getValue(SemanticColoringFeature.SETTING_ID, { overrideIdentifier: model.getLanguageIdentifier().language, resource: model.uri }); - return options && options.enabled; - }; const register = (model: ITextModel) => { this._watchers[model.uri.toString()] = new ModelSemanticColoring(model, themeService, this._semanticStyling); }; @@ -606,7 +607,7 @@ class SemanticColoringFeature extends Disposable { const handleSettingOrThemeChange = () => { for (let model of modelService.getModels()) { const curr = this._watchers[model.uri.toString()]; - if (isSemanticColoringEnabled(model)) { + if (isSemanticColoringEnabled(model, themeService, configurationService)) { if (!curr) { register(model); } @@ -618,7 +619,7 @@ class SemanticColoringFeature extends Disposable { } }; this._register(modelService.onModelAdded((model) => { - if (isSemanticColoringEnabled(model)) { + if (isSemanticColoringEnabled(model, themeService, configurationService)) { register(model); } })); @@ -629,7 +630,7 @@ class SemanticColoringFeature extends Disposable { } })); this._register(configurationService.onDidChangeConfiguration(e => { - if (e.affectsConfiguration(SemanticColoringFeature.SETTING_ID)) { + if (e.affectsConfiguration(SEMANTIC_HIGHLIGHTING_SETTING_ID)) { handleSettingOrThemeChange(); } })); diff --git a/src/vs/editor/contrib/viewportSemanticTokens/viewportSemanticTokens.ts b/src/vs/editor/contrib/viewportSemanticTokens/viewportSemanticTokens.ts index ca30700352e..794e339c3e6 100644 --- a/src/vs/editor/contrib/viewportSemanticTokens/viewportSemanticTokens.ts +++ b/src/vs/editor/contrib/viewportSemanticTokens/viewportSemanticTokens.ts @@ -13,6 +13,9 @@ import { ITextModel } from 'vs/editor/common/model'; import { DocumentRangeSemanticTokensProviderRegistry, DocumentRangeSemanticTokensProvider, SemanticTokens } from 'vs/editor/common/modes'; import { IModelService } from 'vs/editor/common/services/modelService'; import { toMultilineTokens2, SemanticTokensProviderStyling } from 'vs/editor/common/services/semanticTokensProviderStyling'; +import { IThemeService } from 'vs/platform/theme/common/themeService'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { isSemanticColoringEnabled, SEMANTIC_HIGHLIGHTING_SETTING_ID } from 'vs/editor/common/services/modelServiceImpl'; class ViewportSemanticTokensContribution extends Disposable implements IEditorContribution { @@ -28,7 +31,9 @@ class ViewportSemanticTokensContribution extends Disposable implements IEditorCo constructor( editor: ICodeEditor, - @IModelService private readonly _modelService: IModelService + @IModelService private readonly _modelService: IModelService, + @IThemeService private readonly _themeService: IThemeService, + @IConfigurationService private readonly _configurationService: IConfigurationService ) { super(); this._editor = editor; @@ -49,6 +54,16 @@ class ViewportSemanticTokensContribution extends Disposable implements IEditorCo this._cancelAll(); this._tokenizeViewport.schedule(); })); + this._register(this._configurationService.onDidChangeConfiguration(e => { + if (e.affectsConfiguration(SEMANTIC_HIGHLIGHTING_SETTING_ID)) { + this._cancelAll(); + this._tokenizeViewport.schedule(); + } + })); + this._register(this._themeService.onDidColorThemeChange(() => { + this._cancelAll(); + this._tokenizeViewport.schedule(); + })); } private static _getSemanticColoringProvider(model: ITextModel): DocumentRangeSemanticTokensProvider | null { @@ -80,6 +95,9 @@ class ViewportSemanticTokensContribution extends Disposable implements IEditorCo if (model.hasSemanticTokens()) { return; } + if (!isSemanticColoringEnabled(model, this._themeService, this._configurationService)) { + return; + } const provider = ViewportSemanticTokensContribution._getSemanticColoringProvider(model); if (!provider) { return; -- GitLab