From 895238088417b292e35705e72182ff8cc3ab6f63 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 1 Nov 2019 20:01:21 +0100 Subject: Change SourceAnalyzer method resoltion API --- crates/ra_hir/src/lib.rs | 3 +-- crates/ra_hir/src/source_binder.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir/src') 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::{ resolve::ScopeDef, source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, ty::{ - display::HirDisplay, method_resolution::LookupMode, ApplicationTy, CallableDef, Substs, - TraitRef, Ty, TypeCtor, TypeWalk, + display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk, }, }; 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 { db: &impl HirDatabase, ty: Ty, name: Option<&Name>, - mode: method_resolution::LookupMode, + mut callback: impl FnMut(&Ty, Function) -> Option, + ) -> Option { + // There should be no inference vars in types passed here + // FIXME check that? + // FIXME replace Unknown by bound vars here + let canonical = crate::ty::Canonical { value: ty, num_vars: 0 }; + method_resolution::iterate_method_candidates( + &canonical, + db, + &self.resolver, + name, + method_resolution::LookupMode::MethodCall, + |ty, it| match it { + AssocItem::Function(f) => callback(ty, f), + _ => None, + }, + ) + } + + pub fn iterate_path_candidates( + &self, + db: &impl HirDatabase, + ty: Ty, + name: Option<&Name>, callback: impl FnMut(&Ty, AssocItem) -> Option, ) -> Option { // There should be no inference vars in types passed here @@ -339,7 +362,7 @@ impl SourceAnalyzer { db, &self.resolver, name, - mode, + method_resolution::LookupMode::Path, callback, ) } -- cgit v1.2.3