Fix record pattern completion

This commit is contained in:
Florian Diebold 2020-03-07 16:50:30 +01:00
parent b719e211cf
commit cbca4effce
3 changed files with 30 additions and 1 deletions

View file

@ -79,6 +79,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
}
fn is_in_loop_body(leaf: &SyntaxToken) -> bool {
// FIXME move this to CompletionContext and make it handle macros
for node in leaf.parent().ancestors() {
if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR {
break;

View file

@ -87,4 +87,32 @@ mod tests {
]
"###);
}
#[test]
fn test_record_pattern_field_in_simple_macro() {
let completions = complete(
r"
macro_rules! m { ($e:expr) => { $e } }
struct S { foo: u32 }
fn process(f: S) {
m!(match f {
S { f<|>: 92 } => (),
})
}
",
);
assert_debug_snapshot!(completions, @r###"
[
CompletionItem {
label: "foo",
source_range: [171; 172),
delete: [171; 172),
insert: "foo",
kind: Field,
detail: "u32",
},
]
"###);
}
}

View file

@ -185,7 +185,7 @@ impl<'a> CompletionContext<'a> {
}
if name.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() {
self.record_lit_pat =
self.sema.find_node_at_offset_with_macros(&original_file, self.offset);
self.sema.find_node_at_offset_with_macros(&original_file, offset);
}
}
}