未验证 提交 cb1ce163 编写于 作者: A Alex Dima

Fixes #94211: Disable semantic highlighting when the setting asks to disable...

Fixes #94211: Disable semantic highlighting when the setting asks to disable it or when a theme did not opt in
上级 ee0ef370
......@@ -577,9 +577,17 @@ export interface ILineSequence {
getLineContent(lineNumber: number): string;
}
class SemanticColoringFeature extends Disposable {
export const SEMANTIC_HIGHLIGHTING_SETTING_ID = 'editor.semanticHighlighting';
private static readonly SETTING_ID = 'editor.semanticHighlighting';
export function isSemanticColoringEnabled(model: ITextModel, themeService: IThemeService, configurationService: IConfigurationService): boolean {
if (!themeService.getColorTheme().semanticHighlighting) {
return false;
}
const options = configurationService.getValue<IEditorSemanticHighlightingOptions>(SEMANTIC_HIGHLIGHTING_SETTING_ID, { overrideIdentifier: model.getLanguageIdentifier().language, resource: model.uri });
return Boolean(options && options.enabled);
}
class SemanticColoringFeature extends Disposable {
private readonly _watchers: Record<string, ModelSemanticColoring>;
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<IEditorSemanticHighlightingOptions>(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();
}
}));
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册