Skip to content

Commit cbca4ef

Browse files
committed
Fix record pattern completion
1 parent b719e21 commit cbca4ef

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

crates/ra_ide/src/completion/complete_keyword.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
7979
}
8080

8181
fn is_in_loop_body(leaf: &SyntaxToken) -> bool {
82+
// FIXME move this to CompletionContext and make it handle macros
8283
for node in leaf.parent().ancestors() {
8384
if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR {
8485
break;

crates/ra_ide/src/completion/complete_record_pattern.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,32 @@ mod tests {
8787
]
8888
"###);
8989
}
90+
91+
#[test]
92+
fn test_record_pattern_field_in_simple_macro() {
93+
let completions = complete(
94+
r"
95+
macro_rules! m { ($e:expr) => { $e } }
96+
struct S { foo: u32 }
97+
98+
fn process(f: S) {
99+
m!(match f {
100+
S { f<|>: 92 } => (),
101+
})
102+
}
103+
",
104+
);
105+
assert_debug_snapshot!(completions, @r###"
106+
[
107+
CompletionItem {
108+
label: "foo",
109+
source_range: [171; 172),
110+
delete: [171; 172),
111+
insert: "foo",
112+
kind: Field,
113+
detail: "u32",
114+
},
115+
]
116+
"###);
117+
}
90118
}

crates/ra_ide/src/completion/completion_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl<'a> CompletionContext<'a> {
185185
}
186186
if name.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() {
187187
self.record_lit_pat =
188-
self.sema.find_node_at_offset_with_macros(&original_file, self.offset);
188+
self.sema.find_node_at_offset_with_macros(&original_file, offset);
189189
}
190190
}
191191
}

0 commit comments

Comments
 (0)