diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ide_assists/src/lib.rs | 25 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 4 |
3 files changed, 25 insertions, 8 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 6a88236e3..8e5b72044 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -87,7 +87,9 @@ pub use crate::{ | |||
87 | }, | 87 | }, |
88 | }; | 88 | }; |
89 | pub use hir::{Documentation, Semantics}; | 89 | pub use hir::{Documentation, Semantics}; |
90 | pub use ide_assists::{Assist, AssistConfig, AssistId, AssistKind, AssistResolveStrategy}; | 90 | pub use ide_assists::{ |
91 | Assist, AssistConfig, AssistId, AssistKind, AssistResolveStrategy, SingleResolve, | ||
92 | }; | ||
91 | pub use ide_completion::{ | 93 | pub use ide_completion::{ |
92 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionRelevance, ImportEdit, | 94 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionRelevance, ImportEdit, |
93 | InsertTextFormat, | 95 | InsertTextFormat, |
diff --git a/crates/ide_assists/src/lib.rs b/crates/ide_assists/src/lib.rs index 01addffe9..5a0047f03 100644 --- a/crates/ide_assists/src/lib.rs +++ b/crates/ide_assists/src/lib.rs | |||
@@ -94,12 +94,27 @@ impl FromStr for AssistKind { | |||
94 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 94 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
95 | pub struct AssistId(pub &'static str, pub AssistKind); | 95 | pub struct AssistId(pub &'static str, pub AssistKind); |
96 | 96 | ||
97 | // TODO kb docs | 97 | /// A way to control how many asssist to resolve during the assist resolution. |
98 | #[derive(Debug, Clone)] | 98 | /// When an assist is resolved, its edits are calculated that might be costly to always do by default. |
99 | #[derive(Debug)] | ||
99 | pub enum AssistResolveStrategy { | 100 | pub enum AssistResolveStrategy { |
101 | /// No assists should be resolved. | ||
100 | None, | 102 | None, |
103 | /// All assists should be resolved. | ||
101 | All, | 104 | All, |
102 | Single(String, AssistKind), | 105 | /// Only a certain assists should be resolved. |
106 | Single(SingleResolve), | ||
107 | } | ||
108 | |||
109 | /// Hold the [`AssistId`] data of a certain assist to resolve. | ||
110 | /// The original id object cannot be used due to a `'static` lifetime | ||
111 | /// and the requirement to construct this struct dynamically during the resolve handling. | ||
112 | #[derive(Debug)] | ||
113 | pub struct SingleResolve { | ||
114 | /// The id of the assist. | ||
115 | pub assist_id: String, | ||
116 | // The kind of the assist. | ||
117 | pub assist_kind: AssistKind, | ||
103 | } | 118 | } |
104 | 119 | ||
105 | impl AssistResolveStrategy { | 120 | impl AssistResolveStrategy { |
@@ -107,8 +122,8 @@ impl AssistResolveStrategy { | |||
107 | match self { | 122 | match self { |
108 | AssistResolveStrategy::None => false, | 123 | AssistResolveStrategy::None => false, |
109 | AssistResolveStrategy::All => true, | 124 | AssistResolveStrategy::All => true, |
110 | AssistResolveStrategy::Single(id_to_resolve, kind) => { | 125 | AssistResolveStrategy::Single(single_resolve) => { |
111 | id_to_resolve == id.0 && kind == &id.1 | 126 | single_resolve.assist_id == id.0 && single_resolve.assist_kind == id.1 |
112 | } | 127 | } |
113 | } | 128 | } |
114 | } | 129 | } |
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index cd6bbf303..304951b7d 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -10,7 +10,7 @@ use std::{ | |||
10 | use ide::{ | 10 | use ide::{ |
11 | AnnotationConfig, AssistKind, AssistResolveStrategy, FileId, FilePosition, FileRange, | 11 | AnnotationConfig, AssistKind, AssistResolveStrategy, FileId, FilePosition, FileRange, |
12 | HoverAction, HoverGotoTypeData, Query, RangeInfo, Runnable, RunnableKind, SearchScope, | 12 | HoverAction, HoverGotoTypeData, Query, RangeInfo, Runnable, RunnableKind, SearchScope, |
13 | SourceChange, TextEdit, | 13 | SingleResolve, SourceChange, TextEdit, |
14 | }; | 14 | }; |
15 | use ide_db::SymbolKind; | 15 | use ide_db::SymbolKind; |
16 | use itertools::Itertools; | 16 | use itertools::Itertools; |
@@ -1072,7 +1072,7 @@ pub(crate) fn handle_code_action_resolve( | |||
1072 | let assists = snap.analysis.assists_with_fixes( | 1072 | let assists = snap.analysis.assists_with_fixes( |
1073 | &assists_config, | 1073 | &assists_config, |
1074 | &snap.config.diagnostics(), | 1074 | &snap.config.diagnostics(), |
1075 | AssistResolveStrategy::Single(params.id.clone(), assist_kind), | 1075 | AssistResolveStrategy::Single(SingleResolve { assist_id: params.id.clone(), assist_kind }), |
1076 | frange, | 1076 | frange, |
1077 | )?; | 1077 | )?; |
1078 | 1078 | ||