From 8cc4210278c93b9ccf0f825408d0d32bf68617bd Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 7 Mar 2020 15:47:10 +0100 Subject: Add more tests --- crates/ra_ide/src/completion/complete_path.rs | 33 ++++++++++++++++++++++++ crates/ra_ide/src/completion/complete_pattern.rs | 18 +++++++++++++ crates/ra_mbe/src/mbe_expander/matcher.rs | 4 ++- 3 files changed, 54 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs index 4fa47951a..8c2a28983 100644 --- a/crates/ra_ide/src/completion/complete_path.rs +++ b/crates/ra_ide/src/completion/complete_path.rs @@ -835,4 +835,37 @@ mod tests { "### ); } + + #[test] + fn completes_in_simple_macro_call() { + let completions = do_reference_completion( + r#" + macro_rules! m { ($e:expr) => { $e } } + fn main() { m!(self::f<|>); } + fn foo() {} + "#, + ); + assert_debug_snapshot!(completions, @r###" + [ + CompletionItem { + label: "foo()", + source_range: [93; 94), + delete: [93; 94), + insert: "foo()$0", + kind: Function, + lookup: "foo", + detail: "fn foo()", + }, + CompletionItem { + label: "main()", + source_range: [93; 94), + delete: [93; 94), + insert: "main()$0", + kind: Function, + lookup: "main", + detail: "fn main()", + }, + ] + "###); + } } diff --git a/crates/ra_ide/src/completion/complete_pattern.rs b/crates/ra_ide/src/completion/complete_pattern.rs index c2c6ca002..fa8aeceda 100644 --- a/crates/ra_ide/src/completion/complete_pattern.rs +++ b/crates/ra_ide/src/completion/complete_pattern.rs @@ -86,4 +86,22 @@ mod tests { ] "###); } + + #[test] + fn completes_in_simple_macro_call() { + // FIXME: doesn't work yet because of missing error recovery in macro expansion + let completions = complete( + r" + macro_rules! m { ($e:expr) => { $e } } + enum E { X } + + fn foo() { + m!(match E::X { + <|> + }) + } + ", + ); + assert_debug_snapshot!(completions, @r###"[]"###); + } } diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs index ffba03898..49c53183a 100644 --- a/crates/ra_mbe/src/mbe_expander/matcher.rs +++ b/crates/ra_mbe/src/mbe_expander/matcher.rs @@ -247,6 +247,7 @@ impl<'a> TtIter<'a> { ra_parser::parse_fragment(&mut src, &mut sink, fragment_kind); if !sink.cursor.is_root() || sink.error { + // FIXME better recovery in this case would help completion inside macros immensely return Err(()); } @@ -375,7 +376,8 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> Result, Ex return Ok(Some(Fragment::Tokens(tt))); } }; - let tt = input.expect_fragment(fragment).map_err(|()| err!())?; + let tt = + input.expect_fragment(fragment).map_err(|()| err!("fragment did not parse as {}", kind))?; let fragment = if kind == "expr" { Fragment::Ast(tt) } else { Fragment::Tokens(tt) }; Ok(Some(fragment)) } -- cgit v1.2.3