aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/handlers.rs
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-05-03 16:03:28 +0100
committerKirill Bulatov <[email protected]>2021-05-03 16:03:28 +0100
commit1679a376f30c5ad8971c0f855074a3f489fee5fa (patch)
tree1ffe5d504426f6e1d9cbf1c56d9e6b91ab9ac43d /crates/rust-analyzer/src/handlers.rs
parente5cdcb8b124f5b7d59950429787e760e46388f72 (diff)
Resolve single assist only
Diffstat (limited to 'crates/rust-analyzer/src/handlers.rs')
-rw-r--r--crates/rust-analyzer/src/handlers.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index dc350c01f..cd6bbf303 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -8,9 +8,9 @@ use std::{
8}; 8};
9 9
10use ide::{ 10use ide::{
11 AnnotationConfig, AssistResolveStrategy, FileId, FilePosition, FileRange, HoverAction, 11 AnnotationConfig, AssistKind, AssistResolveStrategy, FileId, FilePosition, FileRange,
12 HoverGotoTypeData, Query, RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, 12 HoverAction, HoverGotoTypeData, Query, RangeInfo, Runnable, RunnableKind, SearchScope,
13 TextEdit, 13 SourceChange, TextEdit,
14}; 14};
15use ide_db::SymbolKind; 15use ide_db::SymbolKind;
16use itertools::Itertools; 16use itertools::Itertools;
@@ -28,7 +28,7 @@ use lsp_types::{
28use project_model::TargetKind; 28use project_model::TargetKind;
29use serde::{Deserialize, Serialize}; 29use serde::{Deserialize, Serialize};
30use serde_json::to_value; 30use serde_json::to_value;
31use stdx::{format_to, split_once}; 31use stdx::format_to;
32use syntax::{algo, ast, AstNode, TextRange, TextSize}; 32use syntax::{algo, ast, AstNode, TextRange, TextSize};
33 33
34use crate::{ 34use crate::{
@@ -1058,18 +1058,27 @@ pub(crate) fn handle_code_action_resolve(
1058 .only 1058 .only
1059 .map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect()); 1059 .map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect());
1060 1060
1061 let assist_kind: AssistKind = match params.kind.parse() {
1062 Ok(kind) => kind,
1063 Err(e) => {
1064 return Err(LspError::new(
1065 ErrorCode::InvalidParams as i32,
1066 format!("For the assist to resolve, failed to parse the kind: {}", e),
1067 )
1068 .into())
1069 }
1070 };
1071
1061 let assists = snap.analysis.assists_with_fixes( 1072 let assists = snap.analysis.assists_with_fixes(
1062 &assists_config, 1073 &assists_config,
1063 &snap.config.diagnostics(), 1074 &snap.config.diagnostics(),
1064 // TODO kb pass a certain id 1075 AssistResolveStrategy::Single(params.id.clone(), assist_kind),
1065 AssistResolveStrategy::All,
1066 frange, 1076 frange,
1067 )?; 1077 )?;
1068 1078
1069 let (id, index) = split_once(&params.id, ':').unwrap(); 1079 let assist = &assists[params.index];
1070 let index = index.parse::<usize>().unwrap(); 1080 assert!(assist.id.0 == params.id);
1071 let assist = &assists[index]; 1081 assert!(assist.id.1 == assist_kind);
1072 assert!(assist.id.0 == id);
1073 let edit = to_proto::code_action(&snap, assist.clone(), None)?.edit; 1082 let edit = to_proto::code_action(&snap, assist.clone(), None)?.edit;
1074 code_action.edit = edit; 1083 code_action.edit = edit;
1075 Ok(code_action) 1084 Ok(code_action)