Skip to content

Commit b719e21

Browse files
committed
Fix record literal completion
1 parent 6bea619 commit b719e21

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

crates/ra_ide/src/completion/complete_record_literal.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,29 @@ mod tests {
153153
]
154154
"###);
155155
}
156+
157+
#[test]
158+
fn test_record_literal_field_in_simple_macro() {
159+
let completions = complete(
160+
r"
161+
macro_rules! m { ($e:expr) => { $e } }
162+
struct A { the_field: u32 }
163+
fn foo() {
164+
m!(A { the<|> })
165+
}
166+
",
167+
);
168+
assert_debug_snapshot!(completions, @r###"
169+
[
170+
CompletionItem {
171+
label: "the_field",
172+
source_range: [137; 140),
173+
delete: [137; 140),
174+
insert: "the_field",
175+
kind: Field,
176+
detail: "u32",
177+
},
178+
]
179+
"###);
180+
}
156181
}

crates/ra_ide/src/completion/completion_context.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'a> CompletionContext<'a> {
165165
self.is_param = true;
166166
return;
167167
}
168-
self.classify_name_ref(original_file, name_ref);
168+
self.classify_name_ref(original_file, name_ref, offset);
169169
}
170170

171171
// Otherwise, see if this is a declaration. We can use heuristics to
@@ -190,13 +190,18 @@ impl<'a> CompletionContext<'a> {
190190
}
191191
}
192192

193-
fn classify_name_ref(&mut self, original_file: &SyntaxNode, name_ref: ast::NameRef) {
193+
fn classify_name_ref(
194+
&mut self,
195+
original_file: &SyntaxNode,
196+
name_ref: ast::NameRef,
197+
offset: TextUnit,
198+
) {
194199
self.name_ref_syntax =
195200
find_node_at_offset(&original_file, name_ref.syntax().text_range().start());
196201
let name_range = name_ref.syntax().text_range();
197202
if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() {
198203
self.record_lit_syntax =
199-
self.sema.find_node_at_offset_with_macros(&original_file, self.offset);
204+
self.sema.find_node_at_offset_with_macros(&original_file, offset);
200205
}
201206

202207
self.impl_def = self

0 commit comments

Comments
 (0)