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 +++- crates/ra_ide_api/src/goto_definition.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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 { diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 1f3fa6c57..323faab33 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -315,6 +315,25 @@ mod tests { ); } + #[test] + fn goto_definition_works_for_macros_in_use_tree() { + check_goto( + " + //- /lib.rs + use foo::foo<|>; + + //- /foo/lib.rs + #[macro_export] + macro_rules! foo { + () => { + {} + }; + } + ", + "foo MACRO_CALL FileId(2) [0; 66) [29; 32)", + ); + } + #[test] fn goto_definition_works_for_methods() { covers!(goto_definition_works_for_methods); -- cgit v1.2.3