aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorJohn Renner <[email protected]>2021-05-10 21:34:09 +0100
committerJohn Renner <[email protected]>2021-05-10 21:34:09 +0100
commit7ae3967e5739b786fcd3f7b7b333c73f2c38e8dd (patch)
treeda0ab8119d19bcce349eb9c60825761898a231e4 /crates
parentc3ba1f14faaf132de7c216123878a681d7f3ca61 (diff)
Formatting and docs
Diffstat (limited to 'crates')
-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
4 files changed, 21 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};
29use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams}; 29use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams};
30use serde_json::{from_value, json}; 30use serde_json::{from_value, json};
@@ -56,10 +56,9 @@ version = "0.0.0"
56const foo: &'static str = "hi"; 56const 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]
78fn completes_items_from_standard_library() { 76fn completes_items_from_standard_library() {
79 if skip_slow_tests() { 77 if skip_slow_tests() {