diff options
Diffstat (limited to 'crates/rust-analyzer')
-rw-r--r-- | crates/rust-analyzer/src/caps.rs | 1 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 73 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 61 | ||||
-rw-r--r-- | crates/rust-analyzer/src/integrated_benchmarks.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/lsp_ext.rs | 42 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/semantic_tokens.rs | 5 | ||||
-rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 11 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/slow-tests/main.rs (renamed from crates/rust-analyzer/tests/rust-analyzer/main.rs) | 0 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/slow-tests/support.rs (renamed from crates/rust-analyzer/tests/rust-analyzer/support.rs) | 0 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/slow-tests/testdir.rs (renamed from crates/rust-analyzer/tests/rust-analyzer/testdir.rs) | 0 |
11 files changed, 181 insertions, 18 deletions
diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs index 3c87782f2..b2317618a 100644 --- a/crates/rust-analyzer/src/caps.rs +++ b/crates/rust-analyzer/src/caps.rs | |||
@@ -122,6 +122,7 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti | |||
122 | "runnables": { | 122 | "runnables": { |
123 | "kinds": [ "cargo" ], | 123 | "kinds": [ "cargo" ], |
124 | }, | 124 | }, |
125 | "workspaceSymbolScopeKindFiltering": true, | ||
125 | })), | 126 | })), |
126 | } | 127 | } |
127 | } | 128 | } |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index d83670bda..339014fd3 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -24,7 +24,8 @@ use vfs::AbsPathBuf; | |||
24 | 24 | ||
25 | use crate::{ | 25 | use crate::{ |
26 | caps::completion_item_edit_resolve, diagnostics::DiagnosticsMapConfig, | 26 | caps::completion_item_edit_resolve, diagnostics::DiagnosticsMapConfig, |
27 | line_index::OffsetEncoding, lsp_ext::supports_utf8, | 27 | line_index::OffsetEncoding, lsp_ext::supports_utf8, lsp_ext::WorkspaceSymbolSearchKind, |
28 | lsp_ext::WorkspaceSymbolSearchScope, | ||
28 | }; | 29 | }; |
29 | 30 | ||
30 | // Defines the server-side configuration of the rust-analyzer. We generate | 31 | // Defines the server-side configuration of the rust-analyzer. We generate |
@@ -124,6 +125,13 @@ config_data! { | |||
124 | /// These directories will be ignored by rust-analyzer. | 125 | /// These directories will be ignored by rust-analyzer. |
125 | files_excludeDirs: Vec<PathBuf> = "[]", | 126 | files_excludeDirs: Vec<PathBuf> = "[]", |
126 | 127 | ||
128 | /// Use semantic tokens for strings. | ||
129 | /// | ||
130 | /// In some editors (e.g. vscode) semantic tokens override other highlighting grammars. | ||
131 | /// By disabling semantic tokens for strings, other grammars can be used to highlight | ||
132 | /// their contents. | ||
133 | highlighting_strings: bool = "true", | ||
134 | |||
127 | /// Whether to show `Debug` action. Only applies when | 135 | /// Whether to show `Debug` action. Only applies when |
128 | /// `#rust-analyzer.hoverActions.enable#` is set. | 136 | /// `#rust-analyzer.hoverActions.enable#` is set. |
129 | hoverActions_debug: bool = "true", | 137 | hoverActions_debug: bool = "true", |
@@ -208,6 +216,11 @@ config_data! { | |||
208 | /// Advanced option, fully override the command rust-analyzer uses for | 216 | /// Advanced option, fully override the command rust-analyzer uses for |
209 | /// formatting. | 217 | /// formatting. |
210 | rustfmt_overrideCommand: Option<Vec<String>> = "null", | 218 | rustfmt_overrideCommand: Option<Vec<String>> = "null", |
219 | |||
220 | /// Workspace symbol search scope. | ||
221 | workspace_symbol_search_scope: WorskpaceSymbolSearchScopeDef = "\"workspace\"", | ||
222 | /// Workspace symbol search kind. | ||
223 | workspace_symbol_search_kind: WorskpaceSymbolSearchKindDef = "\"only_types\"", | ||
211 | } | 224 | } |
212 | } | 225 | } |
213 | 226 | ||
@@ -302,6 +315,15 @@ pub struct RunnablesConfig { | |||
302 | pub cargo_extra_args: Vec<String>, | 315 | pub cargo_extra_args: Vec<String>, |
303 | } | 316 | } |
304 | 317 | ||
318 | /// Configuration for workspace symbol search requests. | ||
319 | #[derive(Debug, Clone)] | ||
320 | pub struct WorkspaceSymbolConfig { | ||
321 | /// In what scope should the symbol be searched in. | ||
322 | pub search_scope: WorkspaceSymbolSearchScope, | ||
323 | /// What kind of symbol is being search for. | ||
324 | pub search_kind: WorkspaceSymbolSearchKind, | ||
325 | } | ||
326 | |||
305 | impl Config { | 327 | impl Config { |
306 | pub fn new(root_path: AbsPathBuf, caps: ClientCapabilities) -> Self { | 328 | pub fn new(root_path: AbsPathBuf, caps: ClientCapabilities) -> Self { |
307 | Config { caps, data: ConfigData::default(), discovered_projects: None, root_path } | 329 | Config { caps, data: ConfigData::default(), discovered_projects: None, root_path } |
@@ -655,6 +677,9 @@ impl Config { | |||
655 | refs: self.data.lens_enable && self.data.lens_references, | 677 | refs: self.data.lens_enable && self.data.lens_references, |
656 | } | 678 | } |
657 | } | 679 | } |
680 | pub fn highlighting_strings(&self) -> bool { | ||
681 | self.data.highlighting_strings | ||
682 | } | ||
658 | pub fn hover(&self) -> HoverConfig { | 683 | pub fn hover(&self) -> HoverConfig { |
659 | HoverConfig { | 684 | HoverConfig { |
660 | implementations: self.data.hoverActions_enable | 685 | implementations: self.data.hoverActions_enable |
@@ -677,6 +702,22 @@ impl Config { | |||
677 | .contains(&MarkupKind::Markdown), | 702 | .contains(&MarkupKind::Markdown), |
678 | } | 703 | } |
679 | } | 704 | } |
705 | |||
706 | pub fn workspace_symbol(&self) -> WorkspaceSymbolConfig { | ||
707 | WorkspaceSymbolConfig { | ||
708 | search_scope: match self.data.workspace_symbol_search_scope { | ||
709 | WorskpaceSymbolSearchScopeDef::Workspace => WorkspaceSymbolSearchScope::Workspace, | ||
710 | WorskpaceSymbolSearchScopeDef::WorkspaceAndDependencies => { | ||
711 | WorkspaceSymbolSearchScope::WorkspaceAndDependencies | ||
712 | } | ||
713 | }, | ||
714 | search_kind: match self.data.workspace_symbol_search_kind { | ||
715 | WorskpaceSymbolSearchKindDef::OnlyTypes => WorkspaceSymbolSearchKind::OnlyTypes, | ||
716 | WorskpaceSymbolSearchKindDef::AllSymbols => WorkspaceSymbolSearchKind::AllSymbols, | ||
717 | }, | ||
718 | } | ||
719 | } | ||
720 | |||
680 | pub fn semantic_tokens_refresh(&self) -> bool { | 721 | pub fn semantic_tokens_refresh(&self) -> bool { |
681 | try_or!(self.caps.workspace.as_ref()?.semantic_tokens.as_ref()?.refresh_support?, false) | 722 | try_or!(self.caps.workspace.as_ref()?.semantic_tokens.as_ref()?.refresh_support?, false) |
682 | } | 723 | } |
@@ -723,6 +764,20 @@ enum ImportPrefixDef { | |||
723 | ByCrate, | 764 | ByCrate, |
724 | } | 765 | } |
725 | 766 | ||
767 | #[derive(Deserialize, Debug, Clone)] | ||
768 | #[serde(rename_all = "snake_case")] | ||
769 | enum WorskpaceSymbolSearchScopeDef { | ||
770 | Workspace, | ||
771 | WorkspaceAndDependencies, | ||
772 | } | ||
773 | |||
774 | #[derive(Deserialize, Debug, Clone)] | ||
775 | #[serde(rename_all = "snake_case")] | ||
776 | enum WorskpaceSymbolSearchKindDef { | ||
777 | OnlyTypes, | ||
778 | AllSymbols, | ||
779 | } | ||
780 | |||
726 | macro_rules! _config_data { | 781 | macro_rules! _config_data { |
727 | (struct $name:ident { | 782 | (struct $name:ident { |
728 | $( | 783 | $( |
@@ -893,6 +948,22 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json | |||
893 | "type": "array", | 948 | "type": "array", |
894 | "items": { "type": ["string", "object"] }, | 949 | "items": { "type": ["string", "object"] }, |
895 | }, | 950 | }, |
951 | "WorskpaceSymbolSearchScopeDef" => set! { | ||
952 | "type": "string", | ||
953 | "enum": ["workspace", "workspace_and_dependencies"], | ||
954 | "enumDescriptions": [ | ||
955 | "Search in current workspace only", | ||
956 | "Search in current workspace and dependencies" | ||
957 | ], | ||
958 | }, | ||
959 | "WorskpaceSymbolSearchKindDef" => set! { | ||
960 | "type": "string", | ||
961 | "enum": ["only_types", "all_symbols"], | ||
962 | "enumDescriptions": [ | ||
963 | "Search for types only", | ||
964 | "Search for all symbols kinds" | ||
965 | ], | ||
966 | }, | ||
896 | _ => panic!("{}: {}", ty, default), | 967 | _ => panic!("{}: {}", ty, default), |
897 | } | 968 | } |
898 | 969 | ||
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 551013aa9..51041d7a0 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -38,7 +38,7 @@ use crate::{ | |||
38 | from_proto, | 38 | from_proto, |
39 | global_state::{GlobalState, GlobalStateSnapshot}, | 39 | global_state::{GlobalState, GlobalStateSnapshot}, |
40 | line_index::LineEndings, | 40 | line_index::LineEndings, |
41 | lsp_ext::{self, InlayHint, InlayHintsParams}, | 41 | lsp_ext::{self, InlayHint, InlayHintsParams, WorkspaceSymbolParams}, |
42 | lsp_utils::all_edits_are_disjoint, | 42 | lsp_utils::all_edits_are_disjoint, |
43 | to_proto, LspError, Result, | 43 | to_proto, LspError, Result, |
44 | }; | 44 | }; |
@@ -380,11 +380,12 @@ pub(crate) fn handle_document_symbol( | |||
380 | 380 | ||
381 | pub(crate) fn handle_workspace_symbol( | 381 | pub(crate) fn handle_workspace_symbol( |
382 | snap: GlobalStateSnapshot, | 382 | snap: GlobalStateSnapshot, |
383 | params: lsp_types::WorkspaceSymbolParams, | 383 | params: WorkspaceSymbolParams, |
384 | ) -> Result<Option<Vec<SymbolInformation>>> { | 384 | ) -> Result<Option<Vec<SymbolInformation>>> { |
385 | let _p = profile::span("handle_workspace_symbol"); | 385 | let _p = profile::span("handle_workspace_symbol"); |
386 | let all_symbols = params.query.contains('#'); | 386 | |
387 | let libs = params.query.contains('*'); | 387 | let (all_symbols, libs) = decide_search_scope_and_kind(¶ms, &snap); |
388 | |||
388 | let query = { | 389 | let query = { |
389 | let query: String = params.query.chars().filter(|&c| c != '#' && c != '*').collect(); | 390 | let query: String = params.query.chars().filter(|&c| c != '#' && c != '*').collect(); |
390 | let mut q = Query::new(query); | 391 | let mut q = Query::new(query); |
@@ -406,6 +407,45 @@ pub(crate) fn handle_workspace_symbol( | |||
406 | 407 | ||
407 | return Ok(Some(res)); | 408 | return Ok(Some(res)); |
408 | 409 | ||
410 | fn decide_search_scope_and_kind( | ||
411 | params: &WorkspaceSymbolParams, | ||
412 | snap: &GlobalStateSnapshot, | ||
413 | ) -> (bool, bool) { | ||
414 | // Support old-style parsing of markers in the query. | ||
415 | let mut all_symbols = params.query.contains('#'); | ||
416 | let mut libs = params.query.contains('*'); | ||
417 | |||
418 | let config = snap.config.workspace_symbol(); | ||
419 | |||
420 | // If no explicit marker was set, check request params. If that's also empty | ||
421 | // use global config. | ||
422 | if !all_symbols { | ||
423 | let search_kind = if let Some(ref search_kind) = params.search_kind { | ||
424 | search_kind | ||
425 | } else { | ||
426 | &config.search_kind | ||
427 | }; | ||
428 | all_symbols = match search_kind { | ||
429 | lsp_ext::WorkspaceSymbolSearchKind::OnlyTypes => false, | ||
430 | lsp_ext::WorkspaceSymbolSearchKind::AllSymbols => true, | ||
431 | } | ||
432 | } | ||
433 | |||
434 | if !libs { | ||
435 | let search_scope = if let Some(ref search_scope) = params.search_scope { | ||
436 | search_scope | ||
437 | } else { | ||
438 | &config.search_scope | ||
439 | }; | ||
440 | libs = match search_scope { | ||
441 | lsp_ext::WorkspaceSymbolSearchScope::Workspace => false, | ||
442 | lsp_ext::WorkspaceSymbolSearchScope::WorkspaceAndDependencies => true, | ||
443 | } | ||
444 | } | ||
445 | |||
446 | (all_symbols, libs) | ||
447 | } | ||
448 | |||
409 | fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> { | 449 | fn exec_query(snap: &GlobalStateSnapshot, query: Query) -> Result<Vec<SymbolInformation>> { |
410 | let mut res = Vec::new(); | 450 | let mut res = Vec::new(); |
411 | for nav in snap.analysis.symbol_search(query)? { | 451 | for nav in snap.analysis.symbol_search(query)? { |
@@ -1394,7 +1434,9 @@ pub(crate) fn handle_semantic_tokens_full( | |||
1394 | let line_index = snap.file_line_index(file_id)?; | 1434 | let line_index = snap.file_line_index(file_id)?; |
1395 | 1435 | ||
1396 | let highlights = snap.analysis.highlight(file_id)?; | 1436 | let highlights = snap.analysis.highlight(file_id)?; |
1397 | let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights); | 1437 | let highlight_strings = snap.config.highlighting_strings(); |
1438 | let semantic_tokens = | ||
1439 | to_proto::semantic_tokens(&text, &line_index, highlights, highlight_strings); | ||
1398 | 1440 | ||
1399 | // Unconditionally cache the tokens | 1441 | // Unconditionally cache the tokens |
1400 | snap.semantic_tokens_cache.lock().insert(params.text_document.uri, semantic_tokens.clone()); | 1442 | snap.semantic_tokens_cache.lock().insert(params.text_document.uri, semantic_tokens.clone()); |
@@ -1413,8 +1455,9 @@ pub(crate) fn handle_semantic_tokens_full_delta( | |||
1413 | let line_index = snap.file_line_index(file_id)?; | 1455 | let line_index = snap.file_line_index(file_id)?; |
1414 | 1456 | ||
1415 | let highlights = snap.analysis.highlight(file_id)?; | 1457 | let highlights = snap.analysis.highlight(file_id)?; |
1416 | 1458 | let highlight_strings = snap.config.highlighting_strings(); | |
1417 | let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights); | 1459 | let semantic_tokens = |
1460 | to_proto::semantic_tokens(&text, &line_index, highlights, highlight_strings); | ||
1418 | 1461 | ||
1419 | let mut cache = snap.semantic_tokens_cache.lock(); | 1462 | let mut cache = snap.semantic_tokens_cache.lock(); |
1420 | let cached_tokens = cache.entry(params.text_document.uri).or_default(); | 1463 | let cached_tokens = cache.entry(params.text_document.uri).or_default(); |
@@ -1443,7 +1486,9 @@ pub(crate) fn handle_semantic_tokens_range( | |||
1443 | let line_index = snap.file_line_index(frange.file_id)?; | 1486 | let line_index = snap.file_line_index(frange.file_id)?; |
1444 | 1487 | ||
1445 | let highlights = snap.analysis.highlight_range(frange)?; | 1488 | let highlights = snap.analysis.highlight_range(frange)?; |
1446 | let semantic_tokens = to_proto::semantic_tokens(&text, &line_index, highlights); | 1489 | let highlight_strings = snap.config.highlighting_strings(); |
1490 | let semantic_tokens = | ||
1491 | to_proto::semantic_tokens(&text, &line_index, highlights, highlight_strings); | ||
1447 | Ok(Some(semantic_tokens.into())) | 1492 | Ok(Some(semantic_tokens.into())) |
1448 | } | 1493 | } |
1449 | 1494 | ||
diff --git a/crates/rust-analyzer/src/integrated_benchmarks.rs b/crates/rust-analyzer/src/integrated_benchmarks.rs index 56de9681c..ba2790acb 100644 --- a/crates/rust-analyzer/src/integrated_benchmarks.rs +++ b/crates/rust-analyzer/src/integrated_benchmarks.rs | |||
@@ -123,7 +123,7 @@ fn integrated_completion_benchmark() { | |||
123 | }; | 123 | }; |
124 | 124 | ||
125 | { | 125 | { |
126 | let _it = stdx::timeit("unqualified path completion"); | 126 | let _p = profile::span("unqualified path completion"); |
127 | let _span = profile::cpu_span(); | 127 | let _span = profile::cpu_span(); |
128 | let analysis = host.analysis(); | 128 | let analysis = host.analysis(); |
129 | let config = CompletionConfig { | 129 | let config = CompletionConfig { |
@@ -156,7 +156,7 @@ fn integrated_completion_benchmark() { | |||
156 | }; | 156 | }; |
157 | 157 | ||
158 | { | 158 | { |
159 | let _it = stdx::timeit("dot completion"); | 159 | let _p = profile::span("dot completion"); |
160 | let _span = profile::cpu_span(); | 160 | let _span = profile::cpu_span(); |
161 | let analysis = host.analysis(); | 161 | let analysis = host.analysis(); |
162 | let config = CompletionConfig { | 162 | let config = CompletionConfig { |
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 3bd098058..34b53a7a8 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs | |||
@@ -4,7 +4,8 @@ use std::{collections::HashMap, path::PathBuf}; | |||
4 | 4 | ||
5 | use lsp_types::request::Request; | 5 | use lsp_types::request::Request; |
6 | use lsp_types::{ | 6 | use lsp_types::{ |
7 | notification::Notification, CodeActionKind, Position, Range, TextDocumentIdentifier, | 7 | notification::Notification, CodeActionKind, PartialResultParams, Position, Range, |
8 | TextDocumentIdentifier, WorkDoneProgressParams, | ||
8 | }; | 9 | }; |
9 | use serde::{Deserialize, Serialize}; | 10 | use serde::{Deserialize, Serialize}; |
10 | 11 | ||
@@ -438,3 +439,42 @@ pub enum MoveItemDirection { | |||
438 | Up, | 439 | Up, |
439 | Down, | 440 | Down, |
440 | } | 441 | } |
442 | |||
443 | #[derive(Debug)] | ||
444 | pub enum WorkspaceSymbol {} | ||
445 | |||
446 | impl Request for WorkspaceSymbol { | ||
447 | type Params = WorkspaceSymbolParams; | ||
448 | type Result = Option<Vec<lsp_types::SymbolInformation>>; | ||
449 | const METHOD: &'static str = "workspace/symbol"; | ||
450 | } | ||
451 | |||
452 | #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] | ||
453 | pub struct WorkspaceSymbolParams { | ||
454 | #[serde(flatten)] | ||
455 | pub partial_result_params: PartialResultParams, | ||
456 | |||
457 | #[serde(flatten)] | ||
458 | pub work_done_progress_params: WorkDoneProgressParams, | ||
459 | |||
460 | /// A non-empty query string | ||
461 | pub query: String, | ||
462 | |||
463 | pub search_scope: Option<WorkspaceSymbolSearchScope>, | ||
464 | |||
465 | pub search_kind: Option<WorkspaceSymbolSearchKind>, | ||
466 | } | ||
467 | |||
468 | #[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] | ||
469 | #[serde(rename_all = "camelCase")] | ||
470 | pub enum WorkspaceSymbolSearchScope { | ||
471 | Workspace, | ||
472 | WorkspaceAndDependencies, | ||
473 | } | ||
474 | |||
475 | #[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] | ||
476 | #[serde(rename_all = "camelCase")] | ||
477 | pub enum WorkspaceSymbolSearchKind { | ||
478 | OnlyTypes, | ||
479 | AllSymbols, | ||
480 | } | ||
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index c7bd7eee1..4e0791611 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -525,9 +525,9 @@ impl GlobalState { | |||
525 | .on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs) | 525 | .on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs) |
526 | .on::<lsp_ext::OpenCargoToml>(handlers::handle_open_cargo_toml) | 526 | .on::<lsp_ext::OpenCargoToml>(handlers::handle_open_cargo_toml) |
527 | .on::<lsp_ext::MoveItem>(handlers::handle_move_item) | 527 | .on::<lsp_ext::MoveItem>(handlers::handle_move_item) |
528 | .on::<lsp_ext::WorkspaceSymbol>(handlers::handle_workspace_symbol) | ||
528 | .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting) | 529 | .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting) |
529 | .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol) | 530 | .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol) |
530 | .on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol) | ||
531 | .on::<lsp_types::request::GotoDefinition>(handlers::handle_goto_definition) | 531 | .on::<lsp_types::request::GotoDefinition>(handlers::handle_goto_definition) |
532 | .on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation) | 532 | .on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation) |
533 | .on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition) | 533 | .on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition) |
diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs index ecab89b2a..4fd576adb 100644 --- a/crates/rust-analyzer/src/semantic_tokens.rs +++ b/crates/rust-analyzer/src/semantic_tokens.rs | |||
@@ -91,6 +91,7 @@ define_semantic_token_modifiers![ | |||
91 | (INJECTED, "injected"), | 91 | (INJECTED, "injected"), |
92 | (MUTABLE, "mutable"), | 92 | (MUTABLE, "mutable"), |
93 | (CONSUMING, "consuming"), | 93 | (CONSUMING, "consuming"), |
94 | (ASYNC, "async"), | ||
94 | (UNSAFE, "unsafe"), | 95 | (UNSAFE, "unsafe"), |
95 | (ATTRIBUTE_MODIFIER, "attribute"), | 96 | (ATTRIBUTE_MODIFIER, "attribute"), |
96 | (TRAIT_MODIFIER, "trait"), | 97 | (TRAIT_MODIFIER, "trait"), |
@@ -183,8 +184,8 @@ pub(crate) fn diff_tokens(old: &[SemanticToken], new: &[SemanticToken]) -> Vec<S | |||
183 | } | 184 | } |
184 | } | 185 | } |
185 | 186 | ||
186 | pub(crate) fn type_index(type_: SemanticTokenType) -> u32 { | 187 | pub(crate) fn type_index(ty: SemanticTokenType) -> u32 { |
187 | SUPPORTED_TYPES.iter().position(|it| *it == type_).unwrap() as u32 | 188 | SUPPORTED_TYPES.iter().position(|it| *it == ty).unwrap() as u32 |
188 | } | 189 | } |
189 | 190 | ||
190 | #[cfg(test)] | 191 | #[cfg(test)] |
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index ecf6fd12f..9dec46c78 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs | |||
@@ -381,6 +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 | highlight_strings: bool, | ||
384 | ) -> lsp_types::SemanticTokens { | 385 | ) -> lsp_types::SemanticTokens { |
385 | 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(); |
386 | let mut builder = semantic_tokens::SemanticTokensBuilder::new(id); | 387 | let mut builder = semantic_tokens::SemanticTokensBuilder::new(id); |
@@ -389,8 +390,11 @@ pub(crate) fn semantic_tokens( | |||
389 | if highlight_range.highlight.is_empty() { | 390 | if highlight_range.highlight.is_empty() { |
390 | continue; | 391 | continue; |
391 | } | 392 | } |
392 | let (type_, mods) = semantic_token_type_and_modifiers(highlight_range.highlight); | 393 | let (ty, mods) = semantic_token_type_and_modifiers(highlight_range.highlight); |
393 | let token_index = semantic_tokens::type_index(type_); | 394 | if !highlight_strings && ty == lsp_types::SemanticTokenType::STRING { |
395 | continue; | ||
396 | } | ||
397 | let token_index = semantic_tokens::type_index(ty); | ||
394 | let modifier_bitset = mods.0; | 398 | let modifier_bitset = mods.0; |
395 | 399 | ||
396 | for mut text_range in line_index.index.lines(highlight_range.range) { | 400 | for mut text_range in line_index.index.lines(highlight_range.range) { |
@@ -422,7 +426,7 @@ fn semantic_token_type_and_modifiers( | |||
422 | let type_ = match highlight.tag { | 426 | let type_ = match highlight.tag { |
423 | HlTag::Symbol(symbol) => match symbol { | 427 | HlTag::Symbol(symbol) => match symbol { |
424 | SymbolKind::Module => lsp_types::SemanticTokenType::NAMESPACE, | 428 | SymbolKind::Module => lsp_types::SemanticTokenType::NAMESPACE, |
425 | SymbolKind::Impl => lsp_types::SemanticTokenType::TYPE, | 429 | SymbolKind::Impl => semantic_tokens::TYPE_ALIAS, |
426 | SymbolKind::Field => lsp_types::SemanticTokenType::PROPERTY, | 430 | SymbolKind::Field => lsp_types::SemanticTokenType::PROPERTY, |
427 | SymbolKind::TypeParam => lsp_types::SemanticTokenType::TYPE_PARAMETER, | 431 | SymbolKind::TypeParam => lsp_types::SemanticTokenType::TYPE_PARAMETER, |
428 | SymbolKind::ConstParam => semantic_tokens::CONST_PARAMETER, | 432 | SymbolKind::ConstParam => semantic_tokens::CONST_PARAMETER, |
@@ -496,6 +500,7 @@ fn semantic_token_type_and_modifiers( | |||
496 | HlMod::ControlFlow => semantic_tokens::CONTROL_FLOW, | 500 | HlMod::ControlFlow => semantic_tokens::CONTROL_FLOW, |
497 | HlMod::Mutable => semantic_tokens::MUTABLE, | 501 | HlMod::Mutable => semantic_tokens::MUTABLE, |
498 | HlMod::Consuming => semantic_tokens::CONSUMING, | 502 | HlMod::Consuming => semantic_tokens::CONSUMING, |
503 | HlMod::Async => semantic_tokens::ASYNC, | ||
499 | HlMod::Unsafe => semantic_tokens::UNSAFE, | 504 | HlMod::Unsafe => semantic_tokens::UNSAFE, |
500 | HlMod::Callable => semantic_tokens::CALLABLE, | 505 | HlMod::Callable => semantic_tokens::CALLABLE, |
501 | HlMod::Static => lsp_types::SemanticTokenModifier::STATIC, | 506 | HlMod::Static => lsp_types::SemanticTokenModifier::STATIC, |
diff --git a/crates/rust-analyzer/tests/rust-analyzer/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs index 9e89209ea..9e89209ea 100644 --- a/crates/rust-analyzer/tests/rust-analyzer/main.rs +++ b/crates/rust-analyzer/tests/slow-tests/main.rs | |||
diff --git a/crates/rust-analyzer/tests/rust-analyzer/support.rs b/crates/rust-analyzer/tests/slow-tests/support.rs index 75e677762..75e677762 100644 --- a/crates/rust-analyzer/tests/rust-analyzer/support.rs +++ b/crates/rust-analyzer/tests/slow-tests/support.rs | |||
diff --git a/crates/rust-analyzer/tests/rust-analyzer/testdir.rs b/crates/rust-analyzer/tests/slow-tests/testdir.rs index 36271344b..36271344b 100644 --- a/crates/rust-analyzer/tests/rust-analyzer/testdir.rs +++ b/crates/rust-analyzer/tests/slow-tests/testdir.rs | |||