diff options
author | Kirill Bulatov <[email protected]> | 2021-05-03 16:03:28 +0100 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2021-05-03 16:03:28 +0100 |
commit | 1679a376f30c5ad8971c0f855074a3f489fee5fa (patch) | |
tree | 1ffe5d504426f6e1d9cbf1c56d9e6b91ab9ac43d /crates/rust-analyzer/src/handlers.rs | |
parent | e5cdcb8b124f5b7d59950429787e760e46388f72 (diff) |
Resolve single assist only
Diffstat (limited to 'crates/rust-analyzer/src/handlers.rs')
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 29 |
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 | ||
10 | use ide::{ | 10 | use 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 | }; |
15 | use ide_db::SymbolKind; | 15 | use ide_db::SymbolKind; |
16 | use itertools::Itertools; | 16 | use itertools::Itertools; |
@@ -28,7 +28,7 @@ use lsp_types::{ | |||
28 | use project_model::TargetKind; | 28 | use project_model::TargetKind; |
29 | use serde::{Deserialize, Serialize}; | 29 | use serde::{Deserialize, Serialize}; |
30 | use serde_json::to_value; | 30 | use serde_json::to_value; |
31 | use stdx::{format_to, split_once}; | 31 | use stdx::format_to; |
32 | use syntax::{algo, ast, AstNode, TextRange, TextSize}; | 32 | use syntax::{algo, ast, AstNode, TextRange, TextSize}; |
33 | 33 | ||
34 | use crate::{ | 34 | use 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(¶ms.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) |