aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api_light
diff options
context:
space:
mode:
authorgfreezy <[email protected]>2019-02-03 16:27:36 +0000
committergfreezy <[email protected]>2019-02-03 16:27:36 +0000
commitbfaefed3f61a29624ea3a0c94fcc498d34d0c31f (patch)
tree29ada72c0ecb620a8b1cc1f892ee838b8f11a674 /crates/ra_ide_api_light
parent581c97a5c3821e247df372f25cf8c01ed514bdd9 (diff)
fill match arm
Diffstat (limited to 'crates/ra_ide_api_light')
-rw-r--r--crates/ra_ide_api_light/src/assists.rs17
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)]
107struct AssistBuilder { 107pub 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
186fn reindent(text: &str, indent: &str) -> String { 189fn reindent(text: &str, indent: &str) -> String {