From a565072ddeac519eea3b415a57e9fd208e20e562 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 6 Dec 2019 19:30:15 +0100 Subject: Try to make go to definition work in format! SourceAnalyzer didn't work properly within expression macro expansions because it didn't find the enclosing function. Fix this by going up the expansion chain to find ancestors. This makes the test work, but apparently in real usage it's still not working. --- crates/ra_ide/src/goto_definition.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 76a741207..b1d567ca7 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -693,4 +693,31 @@ mod tests { "foo FN_DEF FileId(1) [52; 63) [55; 58)", ); } + + #[test] + fn goto_through_format() { + check_goto( + " + //- /lib.rs + #[macro_export] + macro_rules! format { + ($($arg:tt)*) => ($crate::fmt::format($crate::__export::format_args!($($arg)*))) + } + #[rustc_builtin_macro] + #[macro_export] + macro_rules! format_args { + ($fmt:expr) => ({ /* compiler built-in */ }); + ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ }) + } + pub mod __export { + pub use crate::format_args; + } + fn foo() -> i8 {} + fn test() { + format!(\"{}\", fo<|>o()) + } + ", + "foo FN_DEF FileId(1) [359; 376) [362; 365)", + ); + } } -- cgit v1.2.3 From c80dc0ad3aee717f9d15c11d300d0eb1c10f1cc8 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 6 Dec 2019 21:24:41 +0100 Subject: Make the goto_through_format test actually fail :( --- crates/ra_ide/src/goto_definition.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'crates/ra_ide/src/goto_definition.rs') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index b1d567ca7..d3c198813 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -689,11 +689,13 @@ mod tests { fo<|>o(); } } + mod confuse_index { fn foo(); } ", "foo FN_DEF FileId(1) [52; 63) [55; 58)", ); } + #[should_panic] // currently failing because of expr mapping problems #[test] fn goto_through_format() { check_goto( @@ -711,6 +713,7 @@ mod tests { } pub mod __export { pub use crate::format_args; + fn foo() {} // for index confusion } fn foo() -> i8 {} fn test() { -- cgit v1.2.3