diff options
author | Aleksey Kladov <[email protected]> | 2020-12-23 10:16:24 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-12-23 10:16:24 +0000 |
commit | 3ced546033973a63cb2ef1644ca099740fdfb1c2 (patch) | |
tree | 7c38c6204afc8faa7f9b2ede6e6d5ffe73f8b80f /crates | |
parent | e1aca75974d917755c04e5040100dfb6ae92f2f9 (diff) |
Make code more understandable
Avoid mutation of snapshot's config -- that's spooky action at a
distance. Instead, copy it over to a local variable.
This points out a minor architecture problem, which we won't fix right
away.
Various `ide`-level config structs, like `AssistConfig`, are geared
towards one-shot use when calling a specific methods. On the other
hand, the large `Config` struct in `rust-analyzer` is a long-term
config store.
The fact that `Config` stores `AssistConfig` is accidental -- a better
design would probably be to just store `ConfigData` inside `Config`
and create various `Config`s on the fly out of it.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index a51a9293f..83b3a343c 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -8,8 +8,9 @@ use std::{ | |||
8 | }; | 8 | }; |
9 | 9 | ||
10 | use ide::{ | 10 | use ide::{ |
11 | CompletionResolveCapability, FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, | 11 | AssistConfig, CompletionResolveCapability, FileId, FilePosition, FileRange, HoverAction, |
12 | NavigationTarget, Query, RangeInfo, Runnable, RunnableKind, SearchScope, SymbolKind, TextEdit, | 12 | HoverGotoTypeData, NavigationTarget, Query, RangeInfo, Runnable, RunnableKind, SearchScope, |
13 | SymbolKind, TextEdit, | ||
13 | }; | 14 | }; |
14 | use itertools::Itertools; | 15 | use itertools::Itertools; |
15 | use lsp_server::ErrorCode; | 16 | use lsp_server::ErrorCode; |
@@ -882,11 +883,14 @@ pub(crate) fn handle_code_action( | |||
882 | let range = from_proto::text_range(&line_index, params.range); | 883 | let range = from_proto::text_range(&line_index, params.range); |
883 | let frange = FileRange { file_id, range }; | 884 | let frange = FileRange { file_id, range }; |
884 | 885 | ||
885 | snap.config.assist.allowed = params | 886 | let assists_config = AssistConfig { |
886 | .clone() | 887 | allowed: params |
887 | .context | 888 | .clone() |
888 | .only | 889 | .context |
889 | .map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect()); | 890 | .only |
891 | .map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect()), | ||
892 | ..snap.config.assist | ||
893 | }; | ||
890 | 894 | ||
891 | let mut res: Vec<lsp_ext::CodeAction> = Vec::new(); | 895 | let mut res: Vec<lsp_ext::CodeAction> = Vec::new(); |
892 | 896 | ||
@@ -894,12 +898,12 @@ pub(crate) fn handle_code_action( | |||
894 | 898 | ||
895 | if snap.config.client_caps.code_action_resolve { | 899 | if snap.config.client_caps.code_action_resolve { |
896 | for (index, assist) in | 900 | for (index, assist) in |
897 | snap.analysis.unresolved_assists(&snap.config.assist, frange)?.into_iter().enumerate() | 901 | snap.analysis.unresolved_assists(&assists_config, frange)?.into_iter().enumerate() |
898 | { | 902 | { |
899 | res.push(to_proto::unresolved_code_action(&snap, params.clone(), assist, index)?); | 903 | res.push(to_proto::unresolved_code_action(&snap, params.clone(), assist, index)?); |
900 | } | 904 | } |
901 | } else { | 905 | } else { |
902 | for assist in snap.analysis.resolved_assists(&snap.config.assist, frange)?.into_iter() { | 906 | for assist in snap.analysis.resolved_assists(&assists_config, frange)?.into_iter() { |
903 | res.push(to_proto::resolved_code_action(&snap, assist)?); | 907 | res.push(to_proto::resolved_code_action(&snap, assist)?); |
904 | } | 908 | } |
905 | } | 909 | } |