From 5dbbfda34ae423229487595fd0ae9e727ae42906 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 28 Sep 2019 19:50:16 +0300 Subject: simplify strip attrs --- .../ra_assists/src/assists/add_missing_impl_members.rs | 12 +++--------- crates/ra_assists/src/ast_editor.rs | 17 ----------------- 2 files changed, 3 insertions(+), 26 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/assists/add_missing_impl_members.rs b/crates/ra_assists/src/assists/add_missing_impl_members.rs index 682455bce..3fce4a5b7 100644 --- a/crates/ra_assists/src/assists/add_missing_impl_members.rs +++ b/crates/ra_assists/src/assists/add_missing_impl_members.rs @@ -1,6 +1,6 @@ use hir::{db::HirDatabase, HasSource}; use ra_syntax::{ - ast::{self, make, AstNode, NameOwner}, + ast::{self, edit, make, AstNode, NameOwner}, SmolStr, }; @@ -76,8 +76,8 @@ fn add_missing_impl_members_inner( ctx.add_action(AssistId(assist_id), label, |edit| { let n_existing_items = impl_item_list.impl_items().count(); let items = missing_items.into_iter().map(|it| match it { - ast::ImplItem::FnDef(def) => strip_docstring(add_body(def).into()), - _ => strip_docstring(it), + ast::ImplItem::FnDef(def) => edit::strip_attrs_and_docs(add_body(def).into()), + _ => edit::strip_attrs_and_docs(it), }); let mut ast_editor = AstEditor::new(impl_item_list); @@ -93,12 +93,6 @@ fn add_missing_impl_members_inner( ctx.build() } -fn strip_docstring(item: ast::ImplItem) -> ast::ImplItem { - let mut ast_editor = AstEditor::new(item); - ast_editor.strip_attrs_and_docs(); - ast_editor.ast().to_owned() -} - fn add_body(fn_def: ast::FnDef) -> ast::FnDef { if fn_def.body().is_none() { fn_def.with_body(make::block_from_expr(make::expr_unimplemented())) diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs index 72c8c478a..60b8923e1 100644 --- a/crates/ra_assists/src/ast_editor.rs +++ b/crates/ra_assists/src/ast_editor.rs @@ -212,23 +212,6 @@ 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.clone(), - Some(_) | None => start.clone(), - }; - self.ast = self.replace_children(RangeInclusive::new(start, end), iter::empty()); - } - } -} - impl AstEditor { pub fn remove_bounds(&mut self) -> &mut Self { let colon = match self.ast.colon_token() { -- cgit v1.2.3