Add more tests

This commit is contained in:
Florian Diebold 2020-03-07 15:47:10 +01:00
parent 24e98121d8
commit 8cc4210278
3 changed files with 54 additions and 1 deletions

View file

@ -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()",
},
]
"###);
}
}

View file

@ -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###"[]"###);
}
}

View file

@ -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<Option<Fragment>, 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))
}