diff options
author | Aleksey Kladov <[email protected]> | 2019-09-28 17:50:16 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-09-28 17:50:16 +0100 |
commit | 5dbbfda34ae423229487595fd0ae9e727ae42906 (patch) | |
tree | 647be92788a5d338bcfbb088ffb4e56582ad3367 /crates/ra_assists/src | |
parent | dbdf0e24d51ce425c0066a76a0efc723e41e5071 (diff) |
simplify strip attrs
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r-- | crates/ra_assists/src/assists/add_missing_impl_members.rs | 12 | ||||
-rw-r--r-- | crates/ra_assists/src/ast_editor.rs | 17 |
2 files changed, 3 insertions, 26 deletions
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 @@ | |||
1 | use hir::{db::HirDatabase, HasSource}; | 1 | use hir::{db::HirDatabase, HasSource}; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | ast::{self, make, AstNode, NameOwner}, | 3 | ast::{self, edit, make, AstNode, NameOwner}, |
4 | SmolStr, | 4 | SmolStr, |
5 | }; | 5 | }; |
6 | 6 | ||
@@ -76,8 +76,8 @@ fn add_missing_impl_members_inner( | |||
76 | ctx.add_action(AssistId(assist_id), label, |edit| { | 76 | ctx.add_action(AssistId(assist_id), label, |edit| { |
77 | let n_existing_items = impl_item_list.impl_items().count(); | 77 | let n_existing_items = impl_item_list.impl_items().count(); |
78 | let items = missing_items.into_iter().map(|it| match it { | 78 | let items = missing_items.into_iter().map(|it| match it { |
79 | ast::ImplItem::FnDef(def) => strip_docstring(add_body(def).into()), | 79 | ast::ImplItem::FnDef(def) => edit::strip_attrs_and_docs(add_body(def).into()), |
80 | _ => strip_docstring(it), | 80 | _ => edit::strip_attrs_and_docs(it), |
81 | }); | 81 | }); |
82 | let mut ast_editor = AstEditor::new(impl_item_list); | 82 | let mut ast_editor = AstEditor::new(impl_item_list); |
83 | 83 | ||
@@ -93,12 +93,6 @@ fn add_missing_impl_members_inner( | |||
93 | ctx.build() | 93 | ctx.build() |
94 | } | 94 | } |
95 | 95 | ||
96 | fn strip_docstring(item: ast::ImplItem) -> ast::ImplItem { | ||
97 | let mut ast_editor = AstEditor::new(item); | ||
98 | ast_editor.strip_attrs_and_docs(); | ||
99 | ast_editor.ast().to_owned() | ||
100 | } | ||
101 | |||
102 | fn add_body(fn_def: ast::FnDef) -> ast::FnDef { | 96 | fn add_body(fn_def: ast::FnDef) -> ast::FnDef { |
103 | if fn_def.body().is_none() { | 97 | if fn_def.body().is_none() { |
104 | fn_def.with_body(make::block_from_expr(make::expr_unimplemented())) | 98 | 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<ast::ItemList> { | |||
212 | } | 212 | } |
213 | } | 213 | } |
214 | 214 | ||
215 | impl AstEditor<ast::ImplItem> { | ||
216 | pub fn strip_attrs_and_docs(&mut self) { | ||
217 | while let Some(start) = self | ||
218 | .ast() | ||
219 | .syntax() | ||
220 | .children_with_tokens() | ||
221 | .find(|it| it.kind() == ATTR || it.kind() == COMMENT) | ||
222 | { | ||
223 | let end = match &start.next_sibling_or_token() { | ||
224 | Some(el) if el.kind() == WHITESPACE => el.clone(), | ||
225 | Some(_) | None => start.clone(), | ||
226 | }; | ||
227 | self.ast = self.replace_children(RangeInclusive::new(start, end), iter::empty()); | ||
228 | } | ||
229 | } | ||
230 | } | ||
231 | |||
232 | impl AstEditor<ast::TypeParam> { | 215 | impl AstEditor<ast::TypeParam> { |
233 | pub fn remove_bounds(&mut self) -> &mut Self { | 216 | pub fn remove_bounds(&mut self) -> &mut Self { |
234 | let colon = match self.ast.colon_token() { | 217 | let colon = match self.ast.colon_token() { |