From a38540771fa93994c369d53a2abc01769c64c0b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Jan 2020 14:42:52 +0100 Subject: Move Type API to type --- crates/ra_ide/src/completion/complete_dot.rs | 17 ++++++++++------- crates/ra_ide/src/completion/complete_path.rs | 26 ++++++++++++++------------ 2 files changed, 24 insertions(+), 19 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs index 9ab43644e..2ca78c927 100644 --- a/crates/ra_ide/src/completion/complete_dot.rs +++ b/crates/ra_ide/src/completion/complete_dot.rs @@ -53,13 +53,16 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Ty } fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) { - let mut seen_methods = FxHashSet::default(); - ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| { - if func.has_self_param(ctx.db) && seen_methods.insert(func.name(ctx.db)) { - acc.add_function(ctx, func); - } - None::<()> - }); + if let Some(krate) = ctx.module.map(|it| it.krate()) { + let mut seen_methods = FxHashSet::default(); + let traits_in_scope = ctx.analyzer.traits_in_scope(ctx.db); + receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| { + if func.has_self_param(ctx.db) && seen_methods.insert(func.name(ctx.db)) { + acc.add_function(ctx, func); + } + None::<()> + }); + } } #[cfg(test)] diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs index 0dce9dc2d..af24e9f48 100644 --- a/crates/ra_ide/src/completion/complete_path.rs +++ b/crates/ra_ide/src/completion/complete_path.rs @@ -49,22 +49,24 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db), _ => unreachable!(), }; - ctx.analyzer.iterate_path_candidates(ctx.db, &ty, None, |_ty, item| { - match item { - hir::AssocItem::Function(func) => { - if !func.has_self_param(ctx.db) { - acc.add_function(ctx, func); - } - } - hir::AssocItem::Const(ct) => acc.add_const(ctx, ct), - hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), - } - None::<()> - }); // Iterate assoc types separately // FIXME: complete T::AssocType let krate = ctx.module.map(|m| m.krate()); if let Some(krate) = krate { + let traits_in_scope = ctx.analyzer.traits_in_scope(ctx.db); + ty.iterate_path_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, item| { + match item { + hir::AssocItem::Function(func) => { + if !func.has_self_param(ctx.db) { + acc.add_function(ctx, func); + } + } + hir::AssocItem::Const(ct) => acc.add_const(ctx, ct), + hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), + } + None::<()> + }); + ty.iterate_impl_items(ctx.db, krate, |item| { match item { hir::AssocItem::Function(_) | hir::AssocItem::Const(_) => {} -- cgit v1.2.3