diff options
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 10 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 9 | ||||
-rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/rust-analyzer/main.rs | 16 | ||||
-rw-r--r-- | docs/user/generated_config.adoc | 9 | ||||
-rw-r--r-- | editors/code/package.json | 5 |
6 files changed, 35 insertions, 16 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 3818160b7..123b63f53 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -44,9 +44,6 @@ config_data! { | |||
44 | /// Show function name and docs in parameter hints. | 44 | /// Show function name and docs in parameter hints. |
45 | callInfo_full: bool = "true", | 45 | callInfo_full: bool = "true", |
46 | 46 | ||
47 | /// Use semantic tokens for strings. Disable to support injected grammars | ||
48 | semanticStringTokens: bool = "true", | ||
49 | |||
50 | /// Automatically refresh project info via `cargo metadata` on | 47 | /// Automatically refresh project info via `cargo metadata` on |
51 | /// `Cargo.toml` changes. | 48 | /// `Cargo.toml` changes. |
52 | cargo_autoreload: bool = "true", | 49 | cargo_autoreload: bool = "true", |
@@ -211,6 +208,13 @@ config_data! { | |||
211 | /// Advanced option, fully override the command rust-analyzer uses for | 208 | /// Advanced option, fully override the command rust-analyzer uses for |
212 | /// formatting. | 209 | /// formatting. |
213 | rustfmt_overrideCommand: Option<Vec<String>> = "null", | 210 | rustfmt_overrideCommand: Option<Vec<String>> = "null", |
211 | |||
212 | /// Use semantic tokens for strings. | ||
213 | /// | ||
214 | /// In some editors (e.g. vscode) semantic tokens override other highlighting grammars. | ||
215 | /// By disabling semantic tokens for strings, other grammars can be used to highlight | ||
216 | /// their contents. | ||
217 | semanticStringTokens: bool = "true", | ||
214 | } | 218 | } |
215 | } | 219 | } |
216 | 220 | ||
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 85dd73fca..78b558a21 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( | |||
1377 | 1377 | ||
1378 | let highlights = snap.analysis.highlight(file_id)?; | 1378 | let highlights = snap.analysis.highlight(file_id)?; |
1379 | let semantic_strings = snap.config.semantic_strings(); | 1379 | let semantic_strings = snap.config.semantic_strings(); |
1380 | let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings); | 1380 | let semantic_tokens = |
1381 | to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings); | ||
1381 | 1382 | ||
1382 | // Unconditionally cache the tokens | 1383 | // Unconditionally cache the tokens |
1383 | snap.semantic_tokens_cache.lock().insert(params.text_document.uri, semantic_tokens.clone()); | 1384 | 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( | |||
1397 | 1398 | ||
1398 | let highlights = snap.analysis.highlight(file_id)?; | 1399 | let highlights = snap.analysis.highlight(file_id)?; |
1399 | let semantic_strings = snap.config.semantic_strings(); | 1400 | let semantic_strings = snap.config.semantic_strings(); |
1400 | let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings); | 1401 | let semantic_tokens = |
1402 | to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings); | ||
1401 | 1403 | ||
1402 | let mut cache = snap.semantic_tokens_cache.lock(); | 1404 | let mut cache = snap.semantic_tokens_cache.lock(); |
1403 | let cached_tokens = cache.entry(params.text_document.uri).or_default(); | 1405 | let cached_tokens = cache.entry(params.text_document.uri).or_default(); |
@@ -1427,7 +1429,8 @@ pub(crate) fn handle_semantic_tokens_range( | |||
1427 | 1429 | ||
1428 | let highlights = snap.analysis.highlight_range(frange)?; | 1430 | let highlights = snap.analysis.highlight_range(frange)?; |
1429 | let semantic_strings = snap.config.semantic_strings(); | 1431 | let semantic_strings = snap.config.semantic_strings(); |
1430 | let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings); | 1432 | let semantic_tokens = |
1433 | to_proto::semantic_tokens(&text, &line_index, highlights, semantic_strings); | ||
1431 | Ok(Some(semantic_tokens.into())) | 1434 | Ok(Some(semantic_tokens.into())) |
1432 | } | 1435 | } |
1433 | 1436 | ||
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 01ffe8db1..5f2dd418f 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( | |||
381 | text: &str, | 381 | text: &str, |
382 | line_index: &LineIndex, | 382 | line_index: &LineIndex, |
383 | highlights: Vec<HlRange>, | 383 | highlights: Vec<HlRange>, |
384 | include_strings: bool | 384 | include_strings: bool, |
385 | ) -> lsp_types::SemanticTokens { | 385 | ) -> lsp_types::SemanticTokens { |
386 | let id = TOKEN_RESULT_COUNTER.fetch_add(1, Ordering::SeqCst).to_string(); | 386 | let id = TOKEN_RESULT_COUNTER.fetch_add(1, Ordering::SeqCst).to_string(); |
387 | let mut builder = semantic_tokens::SemanticTokensBuilder::new(id); | 387 | 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 62f34b643..920c43f25 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::{ | |||
18 | notification::DidOpenTextDocument, | 18 | notification::DidOpenTextDocument, |
19 | request::{ | 19 | request::{ |
20 | CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest, | 20 | CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest, |
21 | SemanticTokensRangeRequest, WillRenameFiles | 21 | SemanticTokensRangeRequest, WillRenameFiles, |
22 | }, | 22 | }, |
23 | CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams, | 23 | CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams, |
24 | DocumentFormattingParams, FileRename, FormattingOptions, GotoDefinitionParams, HoverParams, | 24 | DocumentFormattingParams, FileRename, FormattingOptions, GotoDefinitionParams, HoverParams, |
25 | PartialResultParams, Position, Range, RenameFilesParams, SemanticTokensRangeParams, TextDocumentItem, | 25 | PartialResultParams, Position, Range, RenameFilesParams, SemanticTokens, |
26 | TextDocumentPositionParams, WorkDoneProgressParams, | 26 | SemanticTokensRangeParams, TextDocumentItem, TextDocumentPositionParams, |
27 | SemanticTokens | 27 | WorkDoneProgressParams, |
28 | }; | 28 | }; |
29 | use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams}; | 29 | use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams}; |
30 | use serde_json::{from_value, json}; | 30 | use serde_json::{from_value, json}; |
@@ -56,10 +56,9 @@ version = "0.0.0" | |||
56 | const foo: &'static str = "hi"; | 56 | const foo: &'static str = "hi"; |
57 | "#, | 57 | "#, |
58 | ) | 58 | ) |
59 | .with_config(serde_json::json!({ | 59 | .with_config(serde_json::json!({ "semanticStringTokens": semantic_strings })) |
60 | "semanticStringTokens": semantic_strings | 60 | .server() |
61 | })) | 61 | .wait_until_workspace_is_loaded(); |
62 | .server().wait_until_workspace_is_loaded(); | ||
63 | 62 | ||
64 | let res = server.send_request::<SemanticTokensRangeRequest>(SemanticTokensRangeParams { | 63 | let res = server.send_request::<SemanticTokensRangeRequest>(SemanticTokensRangeParams { |
65 | text_document: server.doc_id("src/lib.rs"), | 64 | text_document: server.doc_id("src/lib.rs"), |
@@ -73,7 +72,6 @@ const foo: &'static str = "hi"; | |||
73 | }); | 72 | }); |
74 | } | 73 | } |
75 | 74 | ||
76 | |||
77 | #[test] | 75 | #[test] |
78 | fn completes_items_from_standard_library() { | 76 | fn completes_items_from_standard_library() { |
79 | if skip_slow_tests() { | 77 | if skip_slow_tests() { |
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index e28423e99..ff4fb064e 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc | |||
@@ -332,3 +332,12 @@ Additional arguments to `rustfmt`. | |||
332 | Advanced option, fully override the command rust-analyzer uses for | 332 | Advanced option, fully override the command rust-analyzer uses for |
333 | formatting. | 333 | formatting. |
334 | -- | 334 | -- |
335 | [[rust-analyzer.semanticStringTokens]]rust-analyzer.semanticStringTokens (default: `true`):: | ||
336 | + | ||
337 | -- | ||
338 | Use semantic tokens for strings. | ||
339 | |||
340 | In some editors (e.g. vscode) semantic tokens override other highlighting grammars. | ||
341 | By disabling semantic tokens for strings, other grammars can be used to highlight | ||
342 | their contents. | ||
343 | -- | ||
diff --git a/editors/code/package.json b/editors/code/package.json index 67e10df7e..1605d926b 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -770,6 +770,11 @@ | |||
770 | "type": "string" | 770 | "type": "string" |
771 | } | 771 | } |
772 | }, | 772 | }, |
773 | "rust-analyzer.semanticStringTokens": { | ||
774 | "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.", | ||
775 | "default": true, | ||
776 | "type": "boolean" | ||
777 | }, | ||
773 | "$generated-end": false | 778 | "$generated-end": false |
774 | } | 779 | } |
775 | }, | 780 | }, |