diff options
author | Florian Diebold <[email protected]> | 2020-03-07 14:47:10 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-03-07 14:48:06 +0000 |
commit | 8cc4210278c93b9ccf0f825408d0d32bf68617bd (patch) | |
tree | a1e2b69a751c441414837c9421c4455153ba4a42 | |
parent | 24e98121d81b75bafcd9c6005548776c00de8401 (diff) |
Add more tests
-rw-r--r-- | crates/ra_ide/src/completion/complete_path.rs | 33 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_pattern.rs | 18 | ||||
-rw-r--r-- | crates/ra_mbe/src/mbe_expander/matcher.rs | 4 |
3 files changed, 54 insertions, 1 deletions
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 { | |||
835 | "### | 835 | "### |
836 | ); | 836 | ); |
837 | } | 837 | } |
838 | |||
839 | #[test] | ||
840 | fn completes_in_simple_macro_call() { | ||
841 | let completions = do_reference_completion( | ||
842 | r#" | ||
843 | macro_rules! m { ($e:expr) => { $e } } | ||
844 | fn main() { m!(self::f<|>); } | ||
845 | fn foo() {} | ||
846 | "#, | ||
847 | ); | ||
848 | assert_debug_snapshot!(completions, @r###" | ||
849 | [ | ||
850 | CompletionItem { | ||
851 | label: "foo()", | ||
852 | source_range: [93; 94), | ||
853 | delete: [93; 94), | ||
854 | insert: "foo()$0", | ||
855 | kind: Function, | ||
856 | lookup: "foo", | ||
857 | detail: "fn foo()", | ||
858 | }, | ||
859 | CompletionItem { | ||
860 | label: "main()", | ||
861 | source_range: [93; 94), | ||
862 | delete: [93; 94), | ||
863 | insert: "main()$0", | ||
864 | kind: Function, | ||
865 | lookup: "main", | ||
866 | detail: "fn main()", | ||
867 | }, | ||
868 | ] | ||
869 | "###); | ||
870 | } | ||
838 | } | 871 | } |
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 { | |||
86 | ] | 86 | ] |
87 | "###); | 87 | "###); |
88 | } | 88 | } |
89 | |||
90 | #[test] | ||
91 | fn completes_in_simple_macro_call() { | ||
92 | // FIXME: doesn't work yet because of missing error recovery in macro expansion | ||
93 | let completions = complete( | ||
94 | r" | ||
95 | macro_rules! m { ($e:expr) => { $e } } | ||
96 | enum E { X } | ||
97 | |||
98 | fn foo() { | ||
99 | m!(match E::X { | ||
100 | <|> | ||
101 | }) | ||
102 | } | ||
103 | ", | ||
104 | ); | ||
105 | assert_debug_snapshot!(completions, @r###"[]"###); | ||
106 | } | ||
89 | } | 107 | } |
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> { | |||
247 | ra_parser::parse_fragment(&mut src, &mut sink, fragment_kind); | 247 | ra_parser::parse_fragment(&mut src, &mut sink, fragment_kind); |
248 | 248 | ||
249 | if !sink.cursor.is_root() || sink.error { | 249 | if !sink.cursor.is_root() || sink.error { |
250 | // FIXME better recovery in this case would help completion inside macros immensely | ||
250 | return Err(()); | 251 | return Err(()); |
251 | } | 252 | } |
252 | 253 | ||
@@ -375,7 +376,8 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> Result<Option<Fragment>, Ex | |||
375 | return Ok(Some(Fragment::Tokens(tt))); | 376 | return Ok(Some(Fragment::Tokens(tt))); |
376 | } | 377 | } |
377 | }; | 378 | }; |
378 | let tt = input.expect_fragment(fragment).map_err(|()| err!())?; | 379 | let tt = |
380 | input.expect_fragment(fragment).map_err(|()| err!("fragment did not parse as {}", kind))?; | ||
379 | let fragment = if kind == "expr" { Fragment::Ast(tt) } else { Fragment::Tokens(tt) }; | 381 | let fragment = if kind == "expr" { Fragment::Ast(tt) } else { Fragment::Tokens(tt) }; |
380 | Ok(Some(fragment)) | 382 | Ok(Some(fragment)) |
381 | } | 383 | } |