about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/config.rs10
-rw-r--r--crates/rust-analyzer/src/handlers.rs9
-rw-r--r--crates/rust-analyzer/src/to_proto.rs2
-rw-r--r--crates/rust-analyzer/tests/rust-analyzer/main.rs16
-rw-r--r--docs/user/generated_config.adoc9
-rw-r--r--editors/code/package.json5
6 files changed, 35 insertions, 16 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 3818160b701..123b63f5311 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -44,9 +44,6 @@ config_data! {
         /// Show function name and docs in parameter hints.
         callInfo_full: bool = "true",
 
-        /// Use semantic tokens for strings. Disable to support injected grammars
-        semanticStringTokens: bool = "true",
-
         /// Automatically refresh project info via `cargo metadata` on
         /// `Cargo.toml` changes.
         cargo_autoreload: bool           = "true",
@@ -211,6 +208,13 @@ config_data! {
         /// Advanced option, fully override the command rust-analyzer uses for
         /// formatting.
         rustfmt_overrideCommand: Option<Vec<String>> = "null",
+
+        /// Use semantic tokens for strings.
+        ///
+        /// In some editors (e.g. vscode) semantic tokens override other highlighting grammars.
+        /// By disabling semantic tokens for strings, other grammars can be used to highlight
+        /// their contents.
+        semanticStringTokens: bool = "true",
     }
 }
 
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 85dd73fca82..78b558a2129 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -1377,7 +1377,8 @@ pub(crate) fn handle_semantic_tokens_full(
 
     let highlights = snap.analysis.highlight(file_id)?;
     let semantic_strings = snap.config.semantic_strings();
-    let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
+    let semantic_tokens =
+        to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
 
     // Unconditionally cache the tokens
     snap.semantic_tokens_cache.lock().insert(params.text_document.uri, semantic_tokens.clone());
@@ -1397,7 +1398,8 @@ pub(crate) fn handle_semantic_tokens_full_delta(
 
     let highlights = snap.analysis.highlight(file_id)?;
     let semantic_strings = snap.config.semantic_strings();
-    let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
+    let semantic_tokens =
+        to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
 
     let mut cache = snap.semantic_tokens_cache.lock();
     let cached_tokens = cache.entry(params.text_document.uri).or_default();
@@ -1427,7 +1429,8 @@ pub(crate) fn handle_semantic_tokens_range(
 
     let highlights = snap.analysis.highlight_range(frange)?;
     let semantic_strings = snap.config.semantic_strings();
-    let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
+    let semantic_tokens =
+        to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings);
     Ok(Some(semantic_tokens.into()))
 }
 
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 01ffe8db156..5f2dd418f32 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -381,7 +381,7 @@ pub(crate) fn semantic_tokens(
     text: &str,
     line_index: &LineIndex,
     highlights: Vec<HlRange>,
-    include_strings: bool
+    include_strings: bool,
 ) -> lsp_types::SemanticTokens {
     let id = TOKEN_RESULT_COUNTER.fetch_add(1, Ordering::SeqCst).to_string();
     let mut builder = semantic_tokens::SemanticTokensBuilder::new(id);
diff --git a/crates/rust-analyzer/tests/rust-analyzer/main.rs b/crates/rust-analyzer/tests/rust-analyzer/main.rs
index 62f34b643e3..920c43f25dc 100644
--- a/crates/rust-analyzer/tests/rust-analyzer/main.rs
+++ b/crates/rust-analyzer/tests/rust-analyzer/main.rs
@@ -18,13 +18,13 @@ use lsp_types::{
     notification::DidOpenTextDocument,
     request::{
         CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest,
-        SemanticTokensRangeRequest, WillRenameFiles
+        SemanticTokensRangeRequest, WillRenameFiles,
     },
     CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
     DocumentFormattingParams, FileRename, FormattingOptions, GotoDefinitionParams, HoverParams,
-    PartialResultParams, Position, Range, RenameFilesParams, SemanticTokensRangeParams, TextDocumentItem,
-    TextDocumentPositionParams, WorkDoneProgressParams,
-    SemanticTokens
+    PartialResultParams, Position, Range, RenameFilesParams, SemanticTokens,
+    SemanticTokensRangeParams, TextDocumentItem, TextDocumentPositionParams,
+    WorkDoneProgressParams,
 };
 use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams};
 use serde_json::{from_value, json};
@@ -56,10 +56,9 @@ version = "0.0.0"
 const foo: &'static str = "hi";
 "#,
         )
-        .with_config(serde_json::json!({
-            "semanticStringTokens": semantic_strings 
-        }))
-        .server().wait_until_workspace_is_loaded();
+        .with_config(serde_json::json!({ "semanticStringTokens": semantic_strings }))
+        .server()
+        .wait_until_workspace_is_loaded();
 
         let res = server.send_request::<SemanticTokensRangeRequest>(SemanticTokensRangeParams {
             text_document: server.doc_id("src/lib.rs"),
@@ -73,7 +72,6 @@ const foo: &'static str = "hi";
     });
 }
 
-
 #[test]
 fn completes_items_from_standard_library() {
     if skip_slow_tests() {
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index e28423e9932..ff4fb064e56 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -332,3 +332,12 @@ Additional arguments to `rustfmt`.
 Advanced option, fully override the command rust-analyzer uses for
 formatting.
 --
+[[rust-analyzer.semanticStringTokens]]rust-analyzer.semanticStringTokens (default: `true`)::
++
+--
+Use semantic tokens for strings.
+
+In some editors (e.g. vscode) semantic tokens override other highlighting grammars.
+By disabling semantic tokens for strings, other grammars can be used to highlight
+their contents.
+--
diff --git a/editors/code/package.json b/editors/code/package.json
index 67e10df7efb..1605d926bfd 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -770,6 +770,11 @@
                         "type": "string"
                     }
                 },
+                "rust-analyzer.semanticStringTokens": {
+                    "markdownDescription": "Use semantic tokens for strings.\n\nIn some editors (e.g. vscode) semantic tokens override other highlighting grammars.\nBy disabling semantic tokens for strings, other grammars can be used to highlight\ntheir contents.",
+                    "default": true,
+                    "type": "boolean"
+                },
                 "$generated-end": false
             }
         },