about summary refs log tree commit diff
path: root/editors/code
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2020-02-26 16:03:30 +0100
committerAleksey Kladov <aleksey.kladov@gmail.com>2020-02-26 16:03:30 +0100
commit225ef6dea24a0e8766fdfd677fb98a15095fa7e5 (patch)
treee88856b7328e69823c41b4ef305f8ae277c9aba5 /editors/code
parent8c0d0894b66ceb1800f09df246ba8fb73b9ceccb (diff)
downloadrust-225ef6dea24a0e8766fdfd677fb98a15095fa7e5.tar.gz
rust-225ef6dea24a0e8766fdfd677fb98a15095fa7e5.zip
Config to switch to semantic tokens
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/client.ts7
-rw-r--r--editors/code/src/config.ts2
-rw-r--r--editors/code/src/main.ts4
4 files changed, 15 insertions, 3 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index 8a8a74f7c61..2a89987e842 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -168,6 +168,11 @@
             "type": "object",
             "title": "Rust Analyzer",
             "properties": {
+                "rust-analyzer.highlighting.semanticTokens": {
+                    "type": "boolean",
+                    "default": false,
+                    "description": "Use proposed semantic tokens API for syntax highlighting"
+                },
                 "rust-analyzer.highlightingOn": {
                     "type": "boolean",
                     "default": false,
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index f9dbe34c24b..44bd04c21b7 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -27,7 +27,7 @@ export async function createClient(config: Config, serverPath: string): Promise<
     const clientOptions: lc.LanguageClientOptions = {
         documentSelector: [{ scheme: 'file', language: 'rust' }],
         initializationOptions: {
-            publishDecorations: true,
+            publishDecorations: !config.highlightingSemanticTokens,
             lruCapacity: config.lruCapacity,
             maxInlayHintLength: config.maxInlayHintLength,
             cargoWatchEnable: cargoWatchOpts.enable,
@@ -84,7 +84,10 @@ export async function createClient(config: Config, serverPath: string): Promise<
     // Here we want to just enable CallHierarchyFeature since it is available on stable.
     // Note that while the CallHierarchyFeature is stable the LSP protocol is not.
     res.registerFeature(new CallHierarchyFeature(res));
-    res.registerFeature(new SemanticTokensFeature(res));
+
+    if (config.highlightingSemanticTokens) {
+        res.registerFeature(new SemanticTokensFeature(res));
+    }
 
     return res;
 }
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 47e8cd45d06..bf915102c80 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -22,6 +22,7 @@ export class Config {
     private static readonly requiresReloadOpts = [
         "cargoFeatures",
         "cargo-watch",
+        "highlighting.semanticTokens"
     ]
         .map(opt => `${Config.rootSection}.${opt}`);
 
@@ -143,6 +144,7 @@ export class Config {
     // We don't do runtime config validation here for simplicity. More on stackoverflow:
     // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension
 
+    get highlightingSemanticTokens() { return this.cfg.get("highlighting.semanticTokens") as boolean; }
     get highlightingOn() { return this.cfg.get("highlightingOn") as boolean; }
     get rainbowHighlightingOn() { return this.cfg.get("rainbowHighlightingOn") as boolean; }
     get lruCapacity() { return this.cfg.get("lruCapacity") as null | number; }
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 424ff1ac3d6..ecf53cf775f 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -89,7 +89,9 @@ export async function activate(context: vscode.ExtensionContext) {
 
     activateStatusDisplay(ctx);
 
-    activateHighlighting(ctx);
+    if (!ctx.config.highlightingSemanticTokens) {
+        activateHighlighting(ctx);
+    }
     activateInlayHints(ctx);
 }