aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src')
-rw-r--r--crates/ide_assists/src/utils.rs34
1 files changed, 16 insertions, 18 deletions
diff --git a/crates/ide_assists/src/utils.rs b/crates/ide_assists/src/utils.rs
index 7d562d1d4..fc7caee04 100644
--- a/crates/ide_assists/src/utils.rs
+++ b/crates/ide_assists/src/utils.rs
@@ -17,7 +17,7 @@ use syntax::{
17 ast::AttrsOwner, 17 ast::AttrsOwner,
18 ast::NameOwner, 18 ast::NameOwner,
19 ast::{self, edit, make, ArgListOwner, GenericParamsOwner}, 19 ast::{self, edit, make, ArgListOwner, GenericParamsOwner},
20 AstNode, Direction, SmolStr, 20 ted, AstNode, Direction, SmolStr,
21 SyntaxKind::*, 21 SyntaxKind::*,
22 SyntaxNode, TextSize, T, 22 SyntaxNode, TextSize, T,
23}; 23};
@@ -139,34 +139,32 @@ pub fn add_trait_assoc_items_to_impl(
139 .into_iter() 139 .into_iter()
140 .map(|it| it.clone_for_update()) 140 .map(|it| it.clone_for_update())
141 .inspect(|it| ast_transform::apply(&*ast_transform, it)) 141 .inspect(|it| ast_transform::apply(&*ast_transform, it))
142 .map(|it| match it {
143 ast::AssocItem::Fn(def) => ast::AssocItem::Fn(add_body(def)),
144 ast::AssocItem::TypeAlias(def) => ast::AssocItem::TypeAlias(def.remove_bounds()),
145 _ => it,
146 })
147 .map(|it| edit::remove_attrs_and_docs(&it).clone_subtree().clone_for_update()); 142 .map(|it| edit::remove_attrs_and_docs(&it).clone_subtree().clone_for_update());
148 143
149 let res = impl_.clone_for_update(); 144 let res = impl_.clone_for_update();
145
150 let assoc_item_list = res.get_or_create_assoc_item_list(); 146 let assoc_item_list = res.get_or_create_assoc_item_list();
151 let mut first_item = None; 147 let mut first_item = None;
152 for item in items { 148 for item in items {
153 if first_item.is_none() { 149 first_item.get_or_insert_with(|| item.clone());
154 first_item = Some(item.clone()) 150 match &item {
155 } 151 ast::AssocItem::Fn(fn_) if fn_.body().is_none() => {
156 assoc_item_list.add_item(item)
157 }
158 return (res, first_item.unwrap());
159
160 fn add_body(fn_def: ast::Fn) -> ast::Fn {
161 match fn_def.body() {
162 Some(_) => fn_def,
163 None => {
164 let body = make::block_expr(None, Some(make::ext::expr_todo())) 152 let body = make::block_expr(None, Some(make::ext::expr_todo()))
165 .indent(edit::IndentLevel(1)); 153 .indent(edit::IndentLevel(1));
166 fn_def.with_body(body) 154 ted::replace(fn_.get_or_create_body().syntax(), body.clone_for_update().syntax())
167 } 155 }
156 ast::AssocItem::TypeAlias(type_alias) => {
157 if let Some(type_bound_list) = type_alias.type_bound_list() {
158 type_bound_list.remove()
159 }
160 }
161 _ => {}
168 } 162 }
163
164 assoc_item_list.add_item(item)
169 } 165 }
166
167 (res, first_item.unwrap())
170} 168}
171 169
172#[derive(Clone, Copy, Debug)] 170#[derive(Clone, Copy, Debug)]