From 4a7e19946a60b4cba6ef9d9916ae0fbec65c74da Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 20 Dec 2019 23:11:07 +0800 Subject: Fix parser for macro call in pattern position --- crates/ra_ide/src/goto_definition.rs | 36 ++++++++++++++++++++++ crates/ra_parser/src/grammar/patterns.rs | 2 +- .../test_data/parser/inline/ok/0129_marco_pat.txt | 9 +++--- 3 files changed, 41 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 9b5744789..79d332e8c 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -424,6 +424,42 @@ mod tests { ); } + #[test] + fn goto_definition_works_for_macro_inside_pattern() { + check_goto( + " + //- /lib.rs + macro_rules! foo {() => {0}} + + fn bar() { + match (0,1) { + (<|>foo!(), _) => {} + } + } + ", + "foo MACRO_CALL FileId(1) [0; 28) [13; 16)", + "macro_rules! foo {() => {0}}|foo", + ); + } + + #[test] + fn goto_definition_works_for_macro_inside_match_arm_lhs() { + check_goto( + " + //- /lib.rs + macro_rules! foo {() => {0}} + + fn bar() { + match 0 { + <|>foo!() => {} + } + } + ", + "foo MACRO_CALL FileId(1) [0; 28) [13; 16)", + "macro_rules! foo {() => {0}}|foo", + ); + } + #[test] fn goto_def_for_methods() { covers!(goto_def_for_methods); diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index f5d12278c..422a4e3dc 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs @@ -50,7 +50,7 @@ pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) { // let m!(x) = 0; // } if lhs.kind() == PATH_PAT && p.at(T![!]) { - let m = lhs.precede(p); + let m = lhs.undo_completion(p); items::macro_call_after_excl(p); m.complete(p, MACRO_CALL); } diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0129_marco_pat.txt b/crates/ra_syntax/test_data/parser/inline/ok/0129_marco_pat.txt index 4a714ad6b..b05ccc0ed 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0129_marco_pat.txt +++ b/crates/ra_syntax/test_data/parser/inline/ok/0129_marco_pat.txt @@ -16,11 +16,10 @@ SOURCE_FILE@[0; 33) LET_KW@[16; 19) "let" WHITESPACE@[19; 20) " " MACRO_CALL@[20; 25) - PATH_PAT@[20; 21) - PATH@[20; 21) - PATH_SEGMENT@[20; 21) - NAME_REF@[20; 21) - IDENT@[20; 21) "m" + PATH@[20; 21) + PATH_SEGMENT@[20; 21) + NAME_REF@[20; 21) + IDENT@[20; 21) "m" EXCL@[21; 22) "!" TOKEN_TREE@[22; 25) L_PAREN@[22; 23) "(" -- cgit v1.2.3