aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/handlers.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-04-13 09:27:00 +0100
committerAleksey Kladov <[email protected]>2021-04-13 09:27:00 +0100
commit04b5fcfdb28f18f4d5279b43c2bb2b3f9c082313 (patch)
tree6f15b2ffa1bd22ec7543b1cb9fb059b12d6ec002 /crates/rust-analyzer/src/handlers.rs
parentfe29a9e837c6e9699185ccae55e83902b4f6ef6a (diff)
Ensure that listing&resolving code actions use the same set of actions
Diffstat (limited to 'crates/rust-analyzer/src/handlers.rs')
-rw-r--r--crates/rust-analyzer/src/handlers.rs38
1 files changed, 15 insertions, 23 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 85c70373a..85cc8602e 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -8,8 +8,8 @@ use std::{
8}; 8};
9 9
10use ide::{ 10use ide::{
11 AnnotationConfig, AssistKind, FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, 11 AnnotationConfig, FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, Query,
12 Query, RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, TextEdit, 12 RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, TextEdit,
13}; 13};
14use ide_db::SymbolKind; 14use ide_db::SymbolKind;
15use itertools::Itertools; 15use itertools::Itertools;
@@ -1003,27 +1003,13 @@ pub(crate) fn handle_code_action(
1003 1003
1004 let mut res: Vec<lsp_ext::CodeAction> = Vec::new(); 1004 let mut res: Vec<lsp_ext::CodeAction> = Vec::new();
1005 1005
1006 let include_quick_fixes = match &assists_config.allowed {
1007 Some(v) => v.iter().any(|it| it == &AssistKind::None || it == &AssistKind::QuickFix),
1008 None => true,
1009 };
1010 let code_action_resolve_cap = snap.config.code_action_resolve(); 1006 let code_action_resolve_cap = snap.config.code_action_resolve();
1011 1007 let assists = snap.analysis.assists_with_fixes(
1012 let mut assists = Vec::new(); 1008 &assists_config,
1013 1009 &snap.config.diagnostics(),
1014 // Fixes from native diagnostics. 1010 !code_action_resolve_cap,
1015 if include_quick_fixes { 1011 frange,
1016 let diagnostics = snap.analysis.diagnostics(&snap.config.diagnostics(), frange.file_id)?; 1012 )?;
1017 assists.extend(
1018 diagnostics
1019 .into_iter()
1020 .filter_map(|d| d.fix)
1021 .filter(|fix| fix.target.intersect(frange.range).is_some()),
1022 )
1023 }
1024
1025 // Assists proper.
1026 assists.extend(snap.analysis.assists(&assists_config, !code_action_resolve_cap, frange)?);
1027 for (index, assist) in assists.into_iter().enumerate() { 1013 for (index, assist) in assists.into_iter().enumerate() {
1028 let resolve_data = 1014 let resolve_data =
1029 if code_action_resolve_cap { Some((index, params.clone())) } else { None }; 1015 if code_action_resolve_cap { Some((index, params.clone())) } else { None };
@@ -1066,7 +1052,13 @@ pub(crate) fn handle_code_action_resolve(
1066 .only 1052 .only
1067 .map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect()); 1053 .map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect());
1068 1054
1069 let assists = snap.analysis.assists(&assists_config, true, frange)?; 1055 let assists = snap.analysis.assists_with_fixes(
1056 &assists_config,
1057 &snap.config.diagnostics(),
1058 true,
1059 frange,
1060 )?;
1061
1070 let (id, index) = split_once(&params.id, ':').unwrap(); 1062 let (id, index) = split_once(&params.id, ':').unwrap();
1071 let index = index.parse::<usize>().unwrap(); 1063 let index = index.parse::<usize>().unwrap();
1072 let assist = &assists[index]; 1064 let assist = &assists[index];