From b973158aeb337041d4e1434cf5d8c609a0b02bef Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 13 Mar 2020 13:03:31 +0100 Subject: Make MBE expansion more resilient (WIP) --- crates/ra_ide/src/completion/complete_dot.rs | 37 ++++++++++++++++++++++++++++ crates/ra_ide/src/expand_macro.rs | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs index f07611d88..a30d1c2de 100644 --- a/crates/ra_ide/src/completion/complete_dot.rs +++ b/crates/ra_ide/src/completion/complete_dot.rs @@ -751,6 +751,43 @@ mod tests { ); } + #[test] + fn macro_expansion_resilient() { + assert_debug_snapshot!( + do_ref_completion( + r" + macro_rules! dbg { + () => {}; + ($val:expr) => { + match $val { tmp => { tmp } } + }; + // Trailing comma with single argument is ignored + ($val:expr,) => { $crate::dbg!($val) }; + ($($val:expr),+ $(,)?) => { + ($($crate::dbg!($val)),+,) + }; + } + struct A { the_field: u32 } + fn foo(a: A) { + dbg!(a.<|>) + } + ", + ), + @r###" + [ + CompletionItem { + label: "the_field", + source_range: [552; 553), + delete: [552; 553), + insert: "the_field", + kind: Field, + detail: "u32", + }, + ] + "### + ); + } + #[test] fn test_method_completion_3547() { assert_debug_snapshot!( diff --git a/crates/ra_ide/src/expand_macro.rs b/crates/ra_ide/src/expand_macro.rs index f6667cb33..e58526f31 100644 --- a/crates/ra_ide/src/expand_macro.rs +++ b/crates/ra_ide/src/expand_macro.rs @@ -259,7 +259,7 @@ fn some_thing() -> u32 { ); assert_eq!(res.name, "foo"); - assert_snapshot!(res.expansion, @r###"bar!()"###); + assert_snapshot!(res.expansion, @r###""###); } #[test] -- cgit v1.2.3