From c46be83a346eb2559420c2c880a52e7ce1787dde Mon Sep 17 00:00:00 2001 From: kjeremy Date: Thu, 31 Oct 2019 13:29:56 -0400 Subject: Fixes #2143 --- crates/ra_hir/src/source_binder.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/source_binder.rs') diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 152bc71bd..0008cb232 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -255,7 +255,9 @@ impl SourceAnalyzer { let items = self.resolver.resolve_module_path(db, &path).take_types().map(PathResolution::Def); - types.or(values).or(items) + types.or(values).or(items).or_else(|| { + self.resolver.resolve_path_as_macro(db, &path).map(|def| PathResolution::Macro(def)) + }) } pub fn resolve_path(&self, db: &impl HirDatabase, path: &ast::Path) -> Option { -- cgit v1.2.3 From 1173c3dab5f77a1afd367d547790dd82c558fe0d Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 31 Oct 2019 19:28:33 +0100 Subject: Refactor to unify with method resolution --- crates/ra_hir/src/source_binder.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/source_binder.rs') diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 0008cb232..0398806fd 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -28,8 +28,8 @@ use crate::{ ids::LocationCtx, resolve::{ScopeDef, TypeNs, ValueNs}, ty::method_resolution::implements_trait, - Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, Module, - Name, Path, Resolver, Static, Struct, Ty, + AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, + MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, }; fn try_get_resolver_for_node( @@ -327,7 +327,7 @@ impl SourceAnalyzer { db: &impl HirDatabase, ty: Ty, name: Option<&Name>, - callback: impl FnMut(&Ty, Function) -> Option, + callback: impl FnMut(&Ty, AssocItem) -> Option, ) -> Option { // There should be no inference vars in types passed here // FIXME check that? @@ -337,6 +337,7 @@ impl SourceAnalyzer { db, &self.resolver, name, + crate::ty::method_resolution::LookupMode::MethodCall, callback, ) } -- cgit v1.2.3 From 79cb0a0dab5fd8e3e84cf4a3b927ec29d2b6e65c Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 31 Oct 2019 21:21:48 +0100 Subject: Complete trait assoc items --- crates/ra_hir/src/source_binder.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/source_binder.rs') diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 0398806fd..82e6eb852 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -27,7 +27,7 @@ use crate::{ }, ids::LocationCtx, resolve::{ScopeDef, TypeNs, ValueNs}, - ty::method_resolution::implements_trait, + ty::method_resolution::{self, implements_trait}, AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, }; @@ -327,17 +327,19 @@ impl SourceAnalyzer { db: &impl HirDatabase, ty: Ty, name: Option<&Name>, + mode: method_resolution::LookupMode, callback: impl FnMut(&Ty, AssocItem) -> 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 }; - crate::ty::method_resolution::iterate_method_candidates( + method_resolution::iterate_method_candidates( &canonical, db, &self.resolver, name, - crate::ty::method_resolution::LookupMode::MethodCall, + mode, callback, ) } -- cgit v1.2.3 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/source_binder.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/source_binder.rs') 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