diff --git a/clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts b/clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts --- a/clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts +++ b/clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts @@ -5,6 +5,11 @@ import * as vscodelc from 'vscode-languageclient'; import * as vscodelct from 'vscode-languageserver-types'; +function getCurrentThemeName() { + return vscode.workspace.getConfiguration('workbench') + .get('colorTheme'); +} + // Parameters for the semantic highlighting (server-side) push notification. // Mirrors the structure in the semantic highlighting proposal for LSP. interface SemanticHighlightingParams { @@ -56,6 +61,8 @@ scopeLookupTable: string[][]; // The object that applies the highlightings clangd sends. highlighter: Highlighter; + // The current color theme used for colorization. + private currentColorThemeName: string; // Any disposables that should be cleaned up when clangd crashes. private subscriptions: vscode.Disposable[] = []; fillClientCapabilities(capabilities: vscodelc.ClientCapabilities) { @@ -70,9 +77,9 @@ } async loadCurrentTheme() { - const themeRuleMatcher = new ThemeRuleMatcher( - await loadTheme(vscode.workspace.getConfiguration('workbench') - .get('colorTheme'))); + this.currentColorThemeName = getCurrentThemeName(); + const themeRuleMatcher = + new ThemeRuleMatcher(await loadTheme(this.currentColorThemeName)); this.highlighter.initialize(themeRuleMatcher); } @@ -91,6 +98,16 @@ // highlighter being created. this.highlighter = new Highlighter(this.scopeLookupTable); this.subscriptions.push(vscode.Disposable.from(this.highlighter)); + // Adds a listener to reload the theme when it changes. + this.subscriptions.push( + vscode.workspace.onDidChangeConfiguration((conf) => { + if (!conf.affectsConfiguration('workbench')) + // Configuration could not have affected the current colorTheme. + return; + const newColorTheme = getCurrentThemeName(); + if (newColorTheme !== this.currentColorThemeName) + this.loadCurrentTheme(); + })); this.loadCurrentTheme(); // Event handling for handling with TextDocuments/Editors lifetimes. this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(