[PATCH] D66406: [clangd] Update themeRuleMatcher when color theme changes in vscode extension.

Johan Vikström via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 19 01:26:00 PDT 2019


jvikstrom created this revision.
jvikstrom added reviewers: hokein, ilya-biryukov.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Add event listener that listens to configuration changes and reloads the ThemeRuleMatcher when the theme changes.

Right now it will not recolor the files, depends on the colorizer CL for that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66406

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts


Index: clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===================================================================
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ 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<string>('colorTheme');
+}
+
 // Parameters for the semantic highlighting (server-side) push notification.
 // Mirrors the structure in the semantic highlighting proposal for LSP.
 interface SemanticHighlightingParams {
@@ -49,6 +54,10 @@
   scopeLookupTable: string[][];
   // The rules for the current theme.
   themeRuleMatcher: ThemeRuleMatcher;
+  // The current color theme used for colorization.
+  currentColorThemeName: string;
+  // Disposable that should be cleaned up.
+  disposable: vscode.Disposable;
   fillClientCapabilities(capabilities: vscodelc.ClientCapabilities) {
     // Extend the ClientCapabilities type and add semantic highlighting
     // capability to the object.
@@ -61,9 +70,9 @@
   }
 
   async loadCurrentTheme() {
-    this.themeRuleMatcher = new ThemeRuleMatcher(
-        await loadTheme(vscode.workspace.getConfiguration('workbench')
-                            .get<string>('colorTheme')));
+    this.currentColorThemeName = getCurrentThemeName();
+    this.themeRuleMatcher =
+        new ThemeRuleMatcher(await loadTheme(this.currentColorThemeName));
   }
 
   initialize(capabilities: vscodelc.ServerCapabilities,
@@ -76,6 +85,14 @@
     if (!serverCapabilities.semanticHighlighting)
       return;
     this.scopeLookupTable = serverCapabilities.semanticHighlighting.scopes;
+    this.disposable = 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();
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66406.215831.patch
Type: text/x-patch
Size: 2269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190819/9309d8b7/attachment.bin>


More information about the cfe-commits mailing list