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.
This commit is contained in:
parent
e1aca75974
commit
3ced546033
1 changed files with 13 additions and 9 deletions
|
@ -8,8 +8,9 @@ use std::{
|
|||
};
|
||||
|
||||
use ide::{
|
||||
CompletionResolveCapability, FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData,
|
||||
NavigationTarget, Query, RangeInfo, Runnable, RunnableKind, SearchScope, SymbolKind, TextEdit,
|
||||
AssistConfig, CompletionResolveCapability, FileId, FilePosition, FileRange, HoverAction,
|
||||
HoverGotoTypeData, NavigationTarget, Query, RangeInfo, Runnable, RunnableKind, SearchScope,
|
||||
SymbolKind, TextEdit,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use lsp_server::ErrorCode;
|
||||
|
@ -882,11 +883,14 @@ pub(crate) fn handle_code_action(
|
|||
let range = from_proto::text_range(&line_index, params.range);
|
||||
let frange = FileRange { file_id, range };
|
||||
|
||||
snap.config.assist.allowed = params
|
||||
.clone()
|
||||
.context
|
||||
.only
|
||||
.map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect());
|
||||
let assists_config = AssistConfig {
|
||||
allowed: params
|
||||
.clone()
|
||||
.context
|
||||
.only
|
||||
.map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect()),
|
||||
..snap.config.assist
|
||||
};
|
||||
|
||||
let mut res: Vec<lsp_ext::CodeAction> = Vec::new();
|
||||
|
||||
|
@ -894,12 +898,12 @@ pub(crate) fn handle_code_action(
|
|||
|
||||
if snap.config.client_caps.code_action_resolve {
|
||||
for (index, assist) in
|
||||
snap.analysis.unresolved_assists(&snap.config.assist, frange)?.into_iter().enumerate()
|
||||
snap.analysis.unresolved_assists(&assists_config, frange)?.into_iter().enumerate()
|
||||
{
|
||||
res.push(to_proto::unresolved_code_action(&snap, params.clone(), assist, index)?);
|
||||
}
|
||||
} else {
|
||||
for assist in snap.analysis.resolved_assists(&snap.config.assist, frange)?.into_iter() {
|
||||
for assist in snap.analysis.resolved_assists(&assists_config, frange)?.into_iter() {
|
||||
res.push(to_proto::resolved_code_action(&snap, assist)?);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue