From e0e42095db8fb6a7c47c23f2a9bbcebbd8971191 Mon Sep 17 00:00:00 2001 From: Ekaterina Babshukova Date: Wed, 3 Jul 2019 16:17:18 +0300 Subject: extend add_impl_members to constants and types --- crates/ra_assists/src/ast_editor.rs | 41 +++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'crates/ra_assists/src/ast_editor.rs') diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs index de0529b32..5f8ba3df6 100644 --- a/crates/ra_assists/src/ast_editor.rs +++ b/crates/ra_assists/src/ast_editor.rs @@ -163,11 +163,7 @@ impl AstEditor { self.do_make_multiline() } - pub fn append_functions<'a>(&mut self, fns: impl Iterator) { - fns.for_each(|it| self.append_function(it)) - } - - pub fn append_function(&mut self, fn_def: &ast::FnDef) { + pub fn append_item(&mut self, item: &ast::ImplItem) { let (indent, position) = match self.ast().impl_items().last() { Some(it) => ( leading_indent(it.syntax()).unwrap_or("").to_string(), @@ -182,8 +178,7 @@ impl AstEditor { }, }; let ws = tokens::WsBuilder::new(&format!("\n{}", indent)); - let to_insert: ArrayVec<[SyntaxElement; 2]> = - [ws.ws().into(), fn_def.syntax().into()].into(); + let to_insert: ArrayVec<[SyntaxElement; 2]> = [ws.ws().into(), item.syntax().into()].into(); self.ast = self.insert_children(position, to_insert.into_iter()); } @@ -192,6 +187,23 @@ impl AstEditor { } } +impl AstEditor { + pub fn strip_attrs_and_docs(&mut self) { + while let Some(start) = self + .ast() + .syntax() + .children_with_tokens() + .find(|it| it.kind() == ATTR || it.kind() == COMMENT) + { + let end = match start.next_sibling_or_token() { + Some(el) if el.kind() == WHITESPACE => el, + Some(_) | None => start, + }; + self.ast = self.replace_children(RangeInclusive::new(start, end), iter::empty()); + } + } +} + impl AstEditor { pub fn set_body(&mut self, body: &ast::Block) { let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); @@ -210,21 +222,6 @@ impl AstEditor { let replace_range = RangeInclusive::new(old_body_or_semi, old_body_or_semi); self.ast = self.replace_children(replace_range, to_insert.into_iter()) } - - pub fn strip_attrs_and_docs(&mut self) { - while let Some(start) = self - .ast() - .syntax() - .children_with_tokens() - .find(|it| it.kind() == ATTR || it.kind() == COMMENT) - { - let end = match start.next_sibling_or_token() { - Some(el) if el.kind() == WHITESPACE => el, - Some(_) | None => start, - }; - self.ast = self.replace_children(RangeInclusive::new(start, end), iter::empty()); - } - } } pub struct AstBuilder { -- cgit v1.2.3