diff options
Diffstat (limited to 'crates/ra_assists/src/assist_ctx.rs')
-rw-r--r-- | crates/ra_assists/src/assist_ctx.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 879216a36..e13f969c7 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | //! This module defines `AssistCtx` -- the API surface that is exposed to assists. | 1 | //! This module defines `AssistCtx` -- the API surface that is exposed to assists. |
2 | use hir::{db::HirDatabase, InFile, SourceAnalyzer}; | 2 | use hir::{db::HirDatabase, InFile, SourceAnalyzer}; |
3 | use itertools::Either; | ||
3 | use ra_db::FileRange; | 4 | use ra_db::FileRange; |
4 | use ra_fmt::{leading_indent, reindent}; | 5 | use ra_fmt::{leading_indent, reindent}; |
5 | use ra_syntax::{ | 6 | use ra_syntax::{ |
@@ -9,12 +10,12 @@ use ra_syntax::{ | |||
9 | }; | 10 | }; |
10 | use ra_text_edit::TextEditBuilder; | 11 | use ra_text_edit::TextEditBuilder; |
11 | 12 | ||
12 | use crate::{AssistAction, AssistId, AssistLabel}; | 13 | use crate::{AssistAction, AssistId, AssistLabel, ResolvedAssist}; |
13 | 14 | ||
14 | #[derive(Clone, Debug)] | 15 | #[derive(Clone, Debug)] |
15 | pub(crate) enum Assist { | 16 | pub(crate) enum Assist { |
16 | Unresolved { label: AssistLabel }, | 17 | Unresolved { label: AssistLabel }, |
17 | Resolved { label: AssistLabel, action: AssistAction, alternative_actions: Vec<AssistAction> }, | 18 | Resolved { assist: ResolvedAssist }, |
18 | } | 19 | } |
19 | 20 | ||
20 | /// `AssistCtx` allows to apply an assist or check if it could be applied. | 21 | /// `AssistCtx` allows to apply an assist or check if it could be applied. |
@@ -92,7 +93,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> { | |||
92 | f(&mut edit); | 93 | f(&mut edit); |
93 | edit.build() | 94 | edit.build() |
94 | }; | 95 | }; |
95 | Assist::Resolved { label, action, alternative_actions: Vec::default() } | 96 | Assist::Resolved { assist: ResolvedAssist { label, action_data: Either::Left(action) } } |
96 | } else { | 97 | } else { |
97 | Assist::Unresolved { label } | 98 | Assist::Unresolved { label } |
98 | }; | 99 | }; |
@@ -105,18 +106,20 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> { | |||
105 | self, | 106 | self, |
106 | id: AssistId, | 107 | id: AssistId, |
107 | label: impl Into<String>, | 108 | label: impl Into<String>, |
108 | f: impl FnOnce() -> (ActionBuilder, Vec<ActionBuilder>), | 109 | f: impl FnOnce() -> Vec<ActionBuilder>, |
109 | ) -> Option<Assist> { | 110 | ) -> Option<Assist> { |
110 | let label = AssistLabel { label: label.into(), id }; | 111 | let label = AssistLabel { label: label.into(), id }; |
111 | let assist = if self.should_compute_edit { | 112 | let assist = if self.should_compute_edit { |
112 | let (action, alternative_actions) = f(); | 113 | let actions = f(); |
114 | assert!(!actions.is_empty(), "Assist cannot have no"); | ||
115 | |||
113 | Assist::Resolved { | 116 | Assist::Resolved { |
114 | label, | 117 | assist: ResolvedAssist { |
115 | action: action.build(), | 118 | label, |
116 | alternative_actions: alternative_actions | 119 | action_data: Either::Right( |
117 | .into_iter() | 120 | actions.into_iter().map(ActionBuilder::build).collect(), |
118 | .map(ActionBuilder::build) | 121 | ), |
119 | .collect(), | 122 | }, |
120 | } | 123 | } |
121 | } else { | 124 | } else { |
122 | Assist::Unresolved { label } | 125 | Assist::Unresolved { label } |