diff options
Diffstat (limited to 'crates/ra_assists/src/assist_ctx.rs')
-rw-r--r-- | crates/ra_assists/src/assist_ctx.rs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index da2880037..83dd270c6 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs | |||
@@ -4,14 +4,13 @@ use ra_db::FileRange; | |||
4 | use ra_fmt::{leading_indent, reindent}; | 4 | use ra_fmt::{leading_indent, reindent}; |
5 | use ra_ide_db::RootDatabase; | 5 | use ra_ide_db::RootDatabase; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | algo::{self, find_covering_element, find_node_at_offset}, | 7 | algo::{self, find_covering_element, find_node_at_offset, SyntaxRewriter}, |
8 | AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize, | 8 | AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize, |
9 | TokenAtOffset, | 9 | TokenAtOffset, |
10 | }; | 10 | }; |
11 | use ra_text_edit::TextEditBuilder; | 11 | use ra_text_edit::TextEditBuilder; |
12 | 12 | ||
13 | use crate::{AssistAction, AssistFile, AssistId, AssistLabel, GroupLabel, ResolvedAssist}; | 13 | use crate::{AssistAction, AssistFile, AssistId, AssistLabel, GroupLabel, ResolvedAssist}; |
14 | use algo::SyntaxRewriter; | ||
15 | 14 | ||
16 | #[derive(Clone, Debug)] | 15 | #[derive(Clone, Debug)] |
17 | pub(crate) struct Assist(pub(crate) Vec<AssistInfo>); | 16 | pub(crate) struct Assist(pub(crate) Vec<AssistInfo>); |
@@ -38,13 +37,10 @@ impl AssistInfo { | |||
38 | 37 | ||
39 | pub(crate) fn into_resolved(self) -> Option<ResolvedAssist> { | 38 | pub(crate) fn into_resolved(self) -> Option<ResolvedAssist> { |
40 | let label = self.label; | 39 | let label = self.label; |
41 | let group_label = self.group_label; | 40 | self.action.map(|action| ResolvedAssist { label, action }) |
42 | self.action.map(|action| ResolvedAssist { label, group_label, action }) | ||
43 | } | 41 | } |
44 | } | 42 | } |
45 | 43 | ||
46 | pub(crate) type AssistHandler = fn(AssistCtx) -> Option<Assist>; | ||
47 | |||
48 | /// `AssistCtx` allows to apply an assist or check if it could be applied. | 44 | /// `AssistCtx` allows to apply an assist or check if it could be applied. |
49 | /// | 45 | /// |
50 | /// Assists use a somewhat over-engineered approach, given the current needs. The | 46 | /// Assists use a somewhat over-engineered approach, given the current needs. The |
@@ -100,7 +96,7 @@ impl<'a> AssistCtx<'a> { | |||
100 | label: impl Into<String>, | 96 | label: impl Into<String>, |
101 | f: impl FnOnce(&mut ActionBuilder), | 97 | f: impl FnOnce(&mut ActionBuilder), |
102 | ) -> Option<Assist> { | 98 | ) -> Option<Assist> { |
103 | let label = AssistLabel::new(label.into(), id); | 99 | let label = AssistLabel::new(id, label.into(), None); |
104 | 100 | ||
105 | let mut info = AssistInfo::new(label); | 101 | let mut info = AssistInfo::new(label); |
106 | if self.should_compute_edit { | 102 | if self.should_compute_edit { |
@@ -116,7 +112,8 @@ impl<'a> AssistCtx<'a> { | |||
116 | } | 112 | } |
117 | 113 | ||
118 | pub(crate) fn add_assist_group(self, group_name: impl Into<String>) -> AssistGroup<'a> { | 114 | pub(crate) fn add_assist_group(self, group_name: impl Into<String>) -> AssistGroup<'a> { |
119 | AssistGroup { ctx: self, group_name: group_name.into(), assists: Vec::new() } | 115 | let group = GroupLabel(group_name.into()); |
116 | AssistGroup { ctx: self, group, assists: Vec::new() } | ||
120 | } | 117 | } |
121 | 118 | ||
122 | pub(crate) fn token_at_offset(&self) -> TokenAtOffset<SyntaxToken> { | 119 | pub(crate) fn token_at_offset(&self) -> TokenAtOffset<SyntaxToken> { |
@@ -146,7 +143,7 @@ impl<'a> AssistCtx<'a> { | |||
146 | 143 | ||
147 | pub(crate) struct AssistGroup<'a> { | 144 | pub(crate) struct AssistGroup<'a> { |
148 | ctx: AssistCtx<'a>, | 145 | ctx: AssistCtx<'a>, |
149 | group_name: String, | 146 | group: GroupLabel, |
150 | assists: Vec<AssistInfo>, | 147 | assists: Vec<AssistInfo>, |
151 | } | 148 | } |
152 | 149 | ||
@@ -157,9 +154,9 @@ impl<'a> AssistGroup<'a> { | |||
157 | label: impl Into<String>, | 154 | label: impl Into<String>, |
158 | f: impl FnOnce(&mut ActionBuilder), | 155 | f: impl FnOnce(&mut ActionBuilder), |
159 | ) { | 156 | ) { |
160 | let label = AssistLabel::new(label.into(), id); | 157 | let label = AssistLabel::new(id, label.into(), Some(self.group.clone())); |
161 | 158 | ||
162 | let mut info = AssistInfo::new(label).with_group(GroupLabel(self.group_name.clone())); | 159 | let mut info = AssistInfo::new(label).with_group(self.group.clone()); |
163 | if self.ctx.should_compute_edit { | 160 | if self.ctx.should_compute_edit { |
164 | let action = { | 161 | let action = { |
165 | let mut edit = ActionBuilder::new(&self.ctx); | 162 | let mut edit = ActionBuilder::new(&self.ctx); |