aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/handlers/add_missing_impl_members.rs26
-rw-r--r--crates/ra_assists/src/handlers/add_new.rs4
-rw-r--r--crates/ra_assists/src/utils.rs10
3 files changed, 20 insertions, 20 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
11use crate::{ 11use 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
163fn has_new_fn(imp: &ast::ImplDef) -> bool { 163fn 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;
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs
index 6be704ce3..2f15a3f15 100644
--- a/crates/ra_assists/src/utils.rs
+++ b/crates/ra_assists/src/utils.rs
@@ -13,7 +13,7 @@ use rustc_hash::FxHashSet;
13 13
14pub(crate) use insert_use::insert_use_statement; 14pub(crate) use insert_use::insert_use_statement;
15 15
16pub fn get_missing_impl_items( 16pub fn get_missing_assoc_items(
17 sema: &Semantics<RootDatabase>, 17 sema: &Semantics<RootDatabase>,
18 impl_def: &ast::ImplDef, 18 impl_def: &ast::ImplDef,
19) -> Vec<hir::AssocItem> { 19) -> Vec<hir::AssocItem> {
@@ -23,21 +23,21 @@ pub fn get_missing_impl_items(
23 let mut impl_type = FxHashSet::default(); 23 let mut impl_type = FxHashSet::default();
24 24
25 if let Some(item_list) = impl_def.item_list() { 25 if let Some(item_list) = impl_def.item_list() {
26 for item in item_list.impl_items() { 26 for item in item_list.assoc_items() {
27 match item { 27 match item {
28 ast::ImplItem::FnDef(f) => { 28 ast::AssocItem::FnDef(f) => {
29 if let Some(n) = f.name() { 29 if let Some(n) = f.name() {
30 impl_fns_consts.insert(n.syntax().to_string()); 30 impl_fns_consts.insert(n.syntax().to_string());
31 } 31 }
32 } 32 }
33 33
34 ast::ImplItem::TypeAliasDef(t) => { 34 ast::AssocItem::TypeAliasDef(t) => {
35 if let Some(n) = t.name() { 35 if let Some(n) = t.name() {
36 impl_type.insert(n.syntax().to_string()); 36 impl_type.insert(n.syntax().to_string());
37 } 37 }
38 } 38 }
39 39
40 ast::ImplItem::ConstDef(c) => { 40 ast::AssocItem::ConstDef(c) => {
41 if let Some(n) = c.name() { 41 if let Some(n) = c.name() {
42 impl_fns_consts.insert(n.syntax().to_string()); 42 impl_fns_consts.insert(n.syntax().to_string());
43 } 43 }