mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-31 17:12:53 +00:00
Fix record literal completion
This commit is contained in:
parent
6bea6199b3
commit
b719e211cf
@ -153,4 +153,29 @@ mod tests {
|
||||
]
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_record_literal_field_in_simple_macro() {
|
||||
let completions = complete(
|
||||
r"
|
||||
macro_rules! m { ($e:expr) => { $e } }
|
||||
struct A { the_field: u32 }
|
||||
fn foo() {
|
||||
m!(A { the<|> })
|
||||
}
|
||||
",
|
||||
);
|
||||
assert_debug_snapshot!(completions, @r###"
|
||||
[
|
||||
CompletionItem {
|
||||
label: "the_field",
|
||||
source_range: [137; 140),
|
||||
delete: [137; 140),
|
||||
insert: "the_field",
|
||||
kind: Field,
|
||||
detail: "u32",
|
||||
},
|
||||
]
|
||||
"###);
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ impl<'a> CompletionContext<'a> {
|
||||
self.is_param = true;
|
||||
return;
|
||||
}
|
||||
self.classify_name_ref(original_file, name_ref);
|
||||
self.classify_name_ref(original_file, name_ref, offset);
|
||||
}
|
||||
|
||||
// Otherwise, see if this is a declaration. We can use heuristics to
|
||||
@ -190,13 +190,18 @@ impl<'a> CompletionContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn classify_name_ref(&mut self, original_file: &SyntaxNode, name_ref: ast::NameRef) {
|
||||
fn classify_name_ref(
|
||||
&mut self,
|
||||
original_file: &SyntaxNode,
|
||||
name_ref: ast::NameRef,
|
||||
offset: TextUnit,
|
||||
) {
|
||||
self.name_ref_syntax =
|
||||
find_node_at_offset(&original_file, name_ref.syntax().text_range().start());
|
||||
let name_range = name_ref.syntax().text_range();
|
||||
if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() {
|
||||
self.record_lit_syntax =
|
||||
self.sema.find_node_at_offset_with_macros(&original_file, self.offset);
|
||||
self.sema.find_node_at_offset_with_macros(&original_file, offset);
|
||||
}
|
||||
|
||||
self.impl_def = self
|
||||
|
Loading…
Reference in New Issue
Block a user