diff options
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r-- | crates/ra_assists/src/handlers/add_missing_impl_members.rs | 26 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/add_new.rs | 4 |
2 files changed, 15 insertions, 15 deletions
diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs index e466c9a86..e47feda71 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs | |||
@@ -10,7 +10,7 @@ use ra_syntax::{ | |||
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams}, | 12 | ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams}, |
13 | utils::{get_missing_impl_items, resolve_target_trait}, | 13 | utils::{get_missing_assoc_items, resolve_target_trait}, |
14 | Assist, AssistCtx, AssistId, | 14 | Assist, AssistCtx, AssistId, |
15 | }; | 15 | }; |
16 | 16 | ||
@@ -112,25 +112,25 @@ fn add_missing_impl_members_inner( | |||
112 | 112 | ||
113 | let trait_ = resolve_target_trait(&ctx.sema, &impl_node)?; | 113 | let trait_ = resolve_target_trait(&ctx.sema, &impl_node)?; |
114 | 114 | ||
115 | let def_name = |item: &ast::ImplItem| -> Option<SmolStr> { | 115 | let def_name = |item: &ast::AssocItem| -> Option<SmolStr> { |
116 | match item { | 116 | match item { |
117 | ast::ImplItem::FnDef(def) => def.name(), | 117 | ast::AssocItem::FnDef(def) => def.name(), |
118 | ast::ImplItem::TypeAliasDef(def) => def.name(), | 118 | ast::AssocItem::TypeAliasDef(def) => def.name(), |
119 | ast::ImplItem::ConstDef(def) => def.name(), | 119 | ast::AssocItem::ConstDef(def) => def.name(), |
120 | } | 120 | } |
121 | .map(|it| it.text().clone()) | 121 | .map(|it| it.text().clone()) |
122 | }; | 122 | }; |
123 | 123 | ||
124 | let missing_items = get_missing_impl_items(&ctx.sema, &impl_node) | 124 | let missing_items = get_missing_assoc_items(&ctx.sema, &impl_node) |
125 | .iter() | 125 | .iter() |
126 | .map(|i| match i { | 126 | .map(|i| match i { |
127 | hir::AssocItem::Function(i) => ast::ImplItem::FnDef(i.source(ctx.db).value), | 127 | hir::AssocItem::Function(i) => ast::AssocItem::FnDef(i.source(ctx.db).value), |
128 | hir::AssocItem::TypeAlias(i) => ast::ImplItem::TypeAliasDef(i.source(ctx.db).value), | 128 | hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAliasDef(i.source(ctx.db).value), |
129 | hir::AssocItem::Const(i) => ast::ImplItem::ConstDef(i.source(ctx.db).value), | 129 | hir::AssocItem::Const(i) => ast::AssocItem::ConstDef(i.source(ctx.db).value), |
130 | }) | 130 | }) |
131 | .filter(|t| def_name(&t).is_some()) | 131 | .filter(|t| def_name(&t).is_some()) |
132 | .filter(|t| match t { | 132 | .filter(|t| match t { |
133 | ast::ImplItem::FnDef(def) => match mode { | 133 | ast::AssocItem::FnDef(def) => match mode { |
134 | AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(), | 134 | AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(), |
135 | AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(), | 135 | AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(), |
136 | }, | 136 | }, |
@@ -145,7 +145,7 @@ fn add_missing_impl_members_inner( | |||
145 | let sema = ctx.sema; | 145 | let sema = ctx.sema; |
146 | 146 | ||
147 | ctx.add_assist(AssistId(assist_id), label, |edit| { | 147 | ctx.add_assist(AssistId(assist_id), label, |edit| { |
148 | let n_existing_items = impl_item_list.impl_items().count(); | 148 | let n_existing_items = impl_item_list.assoc_items().count(); |
149 | let source_scope = sema.scope_for_def(trait_); | 149 | let source_scope = sema.scope_for_def(trait_); |
150 | let target_scope = sema.scope(impl_item_list.syntax()); | 150 | let target_scope = sema.scope(impl_item_list.syntax()); |
151 | let ast_transform = QualifyPaths::new(&target_scope, &source_scope) | 151 | let ast_transform = QualifyPaths::new(&target_scope, &source_scope) |
@@ -154,13 +154,13 @@ fn add_missing_impl_members_inner( | |||
154 | .into_iter() | 154 | .into_iter() |
155 | .map(|it| ast_transform::apply(&*ast_transform, it)) | 155 | .map(|it| ast_transform::apply(&*ast_transform, it)) |
156 | .map(|it| match it { | 156 | .map(|it| match it { |
157 | ast::ImplItem::FnDef(def) => ast::ImplItem::FnDef(add_body(def)), | 157 | ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)), |
158 | _ => it, | 158 | _ => it, |
159 | }) | 159 | }) |
160 | .map(|it| edit::remove_attrs_and_docs(&it)); | 160 | .map(|it| edit::remove_attrs_and_docs(&it)); |
161 | let new_impl_item_list = impl_item_list.append_items(items); | 161 | let new_impl_item_list = impl_item_list.append_items(items); |
162 | let cursor_position = { | 162 | let cursor_position = { |
163 | let first_new_item = new_impl_item_list.impl_items().nth(n_existing_items).unwrap(); | 163 | let first_new_item = new_impl_item_list.assoc_items().nth(n_existing_items).unwrap(); |
164 | first_new_item.syntax().text_range().start() | 164 | first_new_item.syntax().text_range().start() |
165 | }; | 165 | }; |
166 | 166 | ||
diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 0f9174a29..e8a36c7de 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs | |||
@@ -162,8 +162,8 @@ fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<a | |||
162 | 162 | ||
163 | fn has_new_fn(imp: &ast::ImplDef) -> bool { | 163 | fn has_new_fn(imp: &ast::ImplDef) -> bool { |
164 | if let Some(il) = imp.item_list() { | 164 | if let Some(il) = imp.item_list() { |
165 | for item in il.impl_items() { | 165 | for item in il.assoc_items() { |
166 | if let ast::ImplItem::FnDef(f) = item { | 166 | if let ast::AssocItem::FnDef(f) = item { |
167 | if let Some(name) = f.name() { | 167 | if let Some(name) = f.name() { |
168 | if name.text().eq_ignore_ascii_case("new") { | 168 | if name.text().eq_ignore_ascii_case("new") { |
169 | return true; | 169 | return true; |