diff options
Diffstat (limited to 'crates/ra_ide_api_light/src')
-rw-r--r-- | crates/ra_ide_api_light/src/assists.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/crates/ra_ide_api_light/src/assists.rs b/crates/ra_ide_api_light/src/assists.rs index 8905b0419..e578805f1 100644 --- a/crates/ra_ide_api_light/src/assists.rs +++ b/crates/ra_ide_api_light/src/assists.rs | |||
@@ -104,7 +104,7 @@ pub enum Assist { | |||
104 | } | 104 | } |
105 | 105 | ||
106 | #[derive(Default)] | 106 | #[derive(Default)] |
107 | struct AssistBuilder { | 107 | pub struct AssistBuilder { |
108 | edit: TextEditBuilder, | 108 | edit: TextEditBuilder, |
109 | cursor_position: Option<TextUnit>, | 109 | cursor_position: Option<TextUnit>, |
110 | } | 110 | } |
@@ -142,11 +142,7 @@ impl<'a> AssistCtx<'a> { | |||
142 | } | 142 | } |
143 | let mut edit = AssistBuilder::default(); | 143 | let mut edit = AssistBuilder::default(); |
144 | f(&mut edit); | 144 | f(&mut edit); |
145 | Some(Assist::Edit(LocalEdit { | 145 | Some(edit.build(label)) |
146 | label: label.into(), | ||
147 | edit: edit.edit.finish(), | ||
148 | cursor_position: edit.cursor_position, | ||
149 | })) | ||
150 | } | 146 | } |
151 | 147 | ||
152 | pub(crate) fn leaf_at_offset(&self) -> LeafAtOffset<&'a SyntaxNode> { | 148 | pub(crate) fn leaf_at_offset(&self) -> LeafAtOffset<&'a SyntaxNode> { |
@@ -164,7 +160,7 @@ impl AssistBuilder { | |||
164 | fn replace(&mut self, range: TextRange, replace_with: impl Into<String>) { | 160 | fn replace(&mut self, range: TextRange, replace_with: impl Into<String>) { |
165 | self.edit.replace(range, replace_with.into()) | 161 | self.edit.replace(range, replace_with.into()) |
166 | } | 162 | } |
167 | fn replace_node_and_indent(&mut self, node: &SyntaxNode, replace_with: impl Into<String>) { | 163 | pub fn replace_node_and_indent(&mut self, node: &SyntaxNode, replace_with: impl Into<String>) { |
168 | let mut replace_with = replace_with.into(); | 164 | let mut replace_with = replace_with.into(); |
169 | if let Some(indent) = leading_indent(node) { | 165 | if let Some(indent) = leading_indent(node) { |
170 | replace_with = reindent(&replace_with, indent) | 166 | replace_with = reindent(&replace_with, indent) |
@@ -181,6 +177,13 @@ impl AssistBuilder { | |||
181 | fn set_cursor(&mut self, offset: TextUnit) { | 177 | fn set_cursor(&mut self, offset: TextUnit) { |
182 | self.cursor_position = Some(offset) | 178 | self.cursor_position = Some(offset) |
183 | } | 179 | } |
180 | pub fn build(self, label: impl Into<String>) -> Assist { | ||
181 | Assist::Edit(LocalEdit { | ||
182 | label: label.into(), | ||
183 | cursor_position: self.cursor_position, | ||
184 | edit: self.edit.finish(), | ||
185 | }) | ||
186 | } | ||
184 | } | 187 | } |
185 | 188 | ||
186 | fn reindent(text: &str, indent: &str) -> String { | 189 | fn reindent(text: &str, indent: &str) -> String { |