From c46be83a346eb2559420c2c880a52e7ce1787dde Mon Sep 17 00:00:00 2001 From: kjeremy Date: Thu, 31 Oct 2019 13:29:56 -0400 Subject: [PATCH] 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 152bc71bd28..0008cb232dd 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -255,7 +255,9 @@ pub fn resolve_hir_path( 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 1f3fa6c57be..323faab3358 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -315,6 +315,25 @@ macro_rules! foo { ); } + #[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);