Skip to content

Commit 3ced546

Browse files
committed
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.
1 parent e1aca75 commit 3ced546

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

crates/rust-analyzer/src/handlers.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use std::{
88
};
99

1010
use ide::{
11-
CompletionResolveCapability, FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData,
12-
NavigationTarget, Query, RangeInfo, Runnable, RunnableKind, SearchScope, SymbolKind, TextEdit,
11+
AssistConfig, CompletionResolveCapability, FileId, FilePosition, FileRange, HoverAction,
12+
HoverGotoTypeData, NavigationTarget, Query, RangeInfo, Runnable, RunnableKind, SearchScope,
13+
SymbolKind, TextEdit,
1314
};
1415
use itertools::Itertools;
1516
use lsp_server::ErrorCode;
@@ -882,24 +883,27 @@ pub(crate) fn handle_code_action(
882883
let range = from_proto::text_range(&line_index, params.range);
883884
let frange = FileRange { file_id, range };
884885

885-
snap.config.assist.allowed = params
886-
.clone()
887-
.context
888-
.only
889-
.map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect());
886+
let assists_config = AssistConfig {
887+
allowed: params
888+
.clone()
889+
.context
890+
.only
891+
.map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect()),
892+
..snap.config.assist
893+
};
890894

891895
let mut res: Vec<lsp_ext::CodeAction> = Vec::new();
892896

893897
add_quick_fixes(&snap, &params, &mut res)?;
894898

895899
if snap.config.client_caps.code_action_resolve {
896900
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()
898902
{
899903
res.push(to_proto::unresolved_code_action(&snap, params.clone(), assist, index)?);
900904
}
901905
} 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() {
903907
res.push(to_proto::resolved_code_action(&snap, assist)?);
904908
}
905909
}

0 commit comments

Comments
 (0)