aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-14 16:46:01 +0100
committerGitHub <[email protected]>2020-07-14 16:46:01 +0100
commitff6cf4f84914529f112b5bbefbefb2fb33c7f67a (patch)
tree5279549a39259d7c3d19ca5d72c59093c2cf7e8a /crates
parent408b5fafc5fa6e18dc61a6e7a514692ae4352b0e (diff)
parent2163ceb7ef0fc3c5268c9ca5f48bb50ae311947f (diff)
Merge #5377
5377: Fix classify_name_ref on multi-path macro calls r=matklad a=jonas-schievink Previously, "go to definition" on `log<|>::info!(...)` would go to the `info!` macro, not to the `log` crate. This fixes that. Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/goto_definition.rs18
-rw-r--r--crates/ra_ide_db/src/defs.rs10
2 files changed, 26 insertions, 2 deletions
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index f575d738f..c30b20611 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -866,4 +866,22 @@ type Alias<T> = T<|>;
866"#, 866"#,
867 ) 867 )
868 } 868 }
869
870 #[test]
871 fn goto_def_for_macro_container() {
872 check(
873 r#"
874//- /lib.rs
875foo::module<|>::mac!();
876
877//- /foo/lib.rs
878pub mod module {
879 //^^^^^^
880 #[macro_export]
881 macro_rules! _mac { () => { () } }
882 pub use crate::_mac as mac;
883}
884"#,
885 );
886 }
869} 887}
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs
index 3ef5e74b6..bcaabca92 100644
--- a/crates/ra_ide_db/src/defs.rs
+++ b/crates/ra_ide_db/src/defs.rs
@@ -255,8 +255,14 @@ pub fn classify_name_ref(
255 } 255 }
256 256
257 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { 257 if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
258 if let Some(macro_def) = sema.resolve_macro_call(&macro_call) { 258 if let Some(path) = macro_call.path() {
259 return Some(NameRefClass::Definition(Definition::Macro(macro_def))); 259 if path.qualifier().is_none() {
260 // Only use this to resolve single-segment macro calls like `foo!()`. Multi-segment
261 // paths are handled below (allowing `log<|>::info!` to resolve to the log crate).
262 if let Some(macro_def) = sema.resolve_macro_call(&macro_call) {
263 return Some(NameRefClass::Definition(Definition::Macro(macro_def)));
264 }
265 }
260 } 266 }
261 } 267 }
262 268