aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-11-01 19:01:21 +0000
committerFlorian Diebold <[email protected]>2019-11-01 19:01:21 +0000
commit895238088417b292e35705e72182ff8cc3ab6f63 (patch)
treef560ab731b9da35902d3da720e19731b51ab62df /crates
parentb29092ade31d7ff37532649dfbe1dc811edf3651 (diff)
Change SourceAnalyzer method resoltion API
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/lib.rs3
-rw-r--r--crates/ra_hir/src/source_binder.rs27
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs22
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs28
4 files changed, 44 insertions, 36 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 4cace432e..40f5562b4 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -76,8 +76,7 @@ pub use crate::{
76 resolve::ScopeDef, 76 resolve::ScopeDef,
77 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, 77 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
78 ty::{ 78 ty::{
79 display::HirDisplay, method_resolution::LookupMode, ApplicationTy, CallableDef, Substs, 79 display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
80 TraitRef, Ty, TypeCtor, TypeWalk,
81 }, 80 },
82}; 81};
83 82
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 82e6eb852..a4ca59bba 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -327,7 +327,30 @@ impl SourceAnalyzer {
327 db: &impl HirDatabase, 327 db: &impl HirDatabase,
328 ty: Ty, 328 ty: Ty,
329 name: Option<&Name>, 329 name: Option<&Name>,
330 mode: method_resolution::LookupMode, 330 mut callback: impl FnMut(&Ty, Function) -> Option<T>,
331 ) -> Option<T> {
332 // There should be no inference vars in types passed here
333 // FIXME check that?
334 // FIXME replace Unknown by bound vars here
335 let canonical = crate::ty::Canonical { value: ty, num_vars: 0 };
336 method_resolution::iterate_method_candidates(
337 &canonical,
338 db,
339 &self.resolver,
340 name,
341 method_resolution::LookupMode::MethodCall,
342 |ty, it| match it {
343 AssocItem::Function(f) => callback(ty, f),
344 _ => None,
345 },
346 )
347 }
348
349 pub fn iterate_path_candidates<T>(
350 &self,
351 db: &impl HirDatabase,
352 ty: Ty,
353 name: Option<&Name>,
331 callback: impl FnMut(&Ty, AssocItem) -> Option<T>, 354 callback: impl FnMut(&Ty, AssocItem) -> Option<T>,
332 ) -> Option<T> { 355 ) -> Option<T> {
333 // There should be no inference vars in types passed here 356 // There should be no inference vars in types passed here
@@ -339,7 +362,7 @@ impl SourceAnalyzer {
339 db, 362 db,
340 &self.resolver, 363 &self.resolver,
341 name, 364 name,
342 mode, 365 method_resolution::LookupMode::Path,
343 callback, 366 callback,
344 ) 367 )
345 } 368 }
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index fe32e7366..b4df6ee2a 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -58,21 +58,13 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
58 58
59fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { 59fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) {
60 let mut seen_methods = FxHashSet::default(); 60 let mut seen_methods = FxHashSet::default();
61 ctx.analyzer.iterate_method_candidates( 61 ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| {
62 ctx.db, 62 let data = func.data(ctx.db);
63 receiver, 63 if data.has_self_param() && seen_methods.insert(data.name().clone()) {
64 None, 64 acc.add_function(ctx, func);
65 hir::LookupMode::MethodCall, 65 }
66 |_ty, item| { 66 None::<()>
67 if let hir::AssocItem::Function(func) = item { 67 });
68 let data = func.data(ctx.db);
69 if data.has_self_param() && seen_methods.insert(data.name().clone()) {
70 acc.add_function(ctx, func);
71 }
72 }
73 None::<()>
74 },
75 );
76} 68}
77 69
78#[cfg(test)] 70#[cfg(test)]
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index 2aec8eb26..9ac9768af 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -50,25 +50,19 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
50 hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db), 50 hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db),
51 _ => unreachable!(), 51 _ => unreachable!(),
52 }; 52 };
53 ctx.analyzer.iterate_method_candidates( 53 ctx.analyzer.iterate_path_candidates(ctx.db, ty.clone(), None, |_ty, item| {
54 ctx.db, 54 match item {
55 ty.clone(), 55 hir::AssocItem::Function(func) => {
56 None, 56 let data = func.data(ctx.db);
57 hir::LookupMode::Path, 57 if !data.has_self_param() {
58 |_ty, item| { 58 acc.add_function(ctx, func);
59 match item {
60 hir::AssocItem::Function(func) => {
61 let data = func.data(ctx.db);
62 if !data.has_self_param() {
63 acc.add_function(ctx, func);
64 }
65 } 59 }
66 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
67 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
68 } 60 }
69 None::<()> 61 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
70 }, 62 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
71 ); 63 }
64 None::<()>
65 });
72 // Iterate assoc types separately 66 // Iterate assoc types separately
73 // FIXME: complete T::AssocType 67 // FIXME: complete T::AssocType
74 let krate = ctx.module.map(|m| m.krate()); 68 let krate = ctx.module.map(|m| m.krate());