Skip to content

Commit 8cc4210

Browse files
committed
Add more tests
1 parent 24e9812 commit 8cc4210

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

crates/ra_ide/src/completion/complete_path.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,4 +835,37 @@ mod tests {
835835
"###
836836
);
837837
}
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+
}
838871
}

crates/ra_ide/src/completion/complete_pattern.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,22 @@ mod tests {
8686
]
8787
"###);
8888
}
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+
}
89107
}

crates/ra_mbe/src/mbe_expander/matcher.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ impl<'a> TtIter<'a> {
247247
ra_parser::parse_fragment(&mut src, &mut sink, fragment_kind);
248248

249249
if !sink.cursor.is_root() || sink.error {
250+
// FIXME better recovery in this case would help completion inside macros immensely
250251
return Err(());
251252
}
252253

@@ -375,7 +376,8 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> Result<Option<Fragment>, Ex
375376
return Ok(Some(Fragment::Tokens(tt)));
376377
}
377378
};
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))?;
379381
let fragment = if kind == "expr" { Fragment::Ast(tt) } else { Fragment::Tokens(tt) };
380382
Ok(Some(fragment))
381383
}

0 commit comments

Comments
 (0)