From bfaefed3f61a29624ea3a0c94fcc498d34d0c31f Mon Sep 17 00:00:00 2001 From: gfreezy Date: Mon, 4 Feb 2019 00:27:36 +0800 Subject: fill match arm --- crates/ra_ide_api_light/src/assists.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'crates/ra_ide_api_light/src') 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 { } #[derive(Default)] -struct AssistBuilder { +pub struct AssistBuilder { edit: TextEditBuilder, cursor_position: Option, } @@ -142,11 +142,7 @@ impl<'a> AssistCtx<'a> { } let mut edit = AssistBuilder::default(); f(&mut edit); - Some(Assist::Edit(LocalEdit { - label: label.into(), - edit: edit.edit.finish(), - cursor_position: edit.cursor_position, - })) + Some(edit.build(label)) } pub(crate) fn leaf_at_offset(&self) -> LeafAtOffset<&'a SyntaxNode> { @@ -164,7 +160,7 @@ impl AssistBuilder { fn replace(&mut self, range: TextRange, replace_with: impl Into) { self.edit.replace(range, replace_with.into()) } - fn replace_node_and_indent(&mut self, node: &SyntaxNode, replace_with: impl Into) { + pub fn replace_node_and_indent(&mut self, node: &SyntaxNode, replace_with: impl Into) { let mut replace_with = replace_with.into(); if let Some(indent) = leading_indent(node) { replace_with = reindent(&replace_with, indent) @@ -181,6 +177,13 @@ impl AssistBuilder { fn set_cursor(&mut self, offset: TextUnit) { self.cursor_position = Some(offset) } + pub fn build(self, label: impl Into) -> Assist { + Assist::Edit(LocalEdit { + label: label.into(), + cursor_position: self.cursor_position, + edit: self.edit.finish(), + }) + } } fn reindent(text: &str, indent: &str) -> String { -- cgit v1.2.3