aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-03-07 15:48:39 +0000
committerFlorian Diebold <[email protected]>2020-03-07 15:48:39 +0000
commitb719e211cf6c39f80b8b402e9b46eddedf6b2200 (patch)
tree51fe240c3ae1569bfc5950f8131fbf47dccac4af /crates
parent6bea6199b34ba7282aa148d9afcf52a8f2c7d6f5 (diff)
Fix record literal completion
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/completion/complete_record_literal.rs25
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs11
2 files changed, 33 insertions, 3 deletions
diff --git a/crates/ra_ide/src/completion/complete_record_literal.rs b/crates/ra_ide/src/completion/complete_record_literal.rs
index f98353d76..be6e4194f 100644
--- a/crates/ra_ide/src/completion/complete_record_literal.rs
+++ b/crates/ra_ide/src/completion/complete_record_literal.rs
@@ -153,4 +153,29 @@ mod tests {
153 ] 153 ]
154 "###); 154 "###);
155 } 155 }
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 }
156} 181}
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index 81a033fcb..fe9777487 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -165,7 +165,7 @@ impl<'a> CompletionContext<'a> {
165 self.is_param = true; 165 self.is_param = true;
166 return; 166 return;
167 } 167 }
168 self.classify_name_ref(original_file, name_ref); 168 self.classify_name_ref(original_file, name_ref, offset);
169 } 169 }
170 170
171 // Otherwise, see if this is a declaration. We can use heuristics to 171 // Otherwise, see if this is a declaration. We can use heuristics to
@@ -190,13 +190,18 @@ impl<'a> CompletionContext<'a> {
190 } 190 }
191 } 191 }
192 192
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 ) {
194 self.name_ref_syntax = 199 self.name_ref_syntax =
195 find_node_at_offset(&original_file, name_ref.syntax().text_range().start()); 200 find_node_at_offset(&original_file, name_ref.syntax().text_range().start());
196 let name_range = name_ref.syntax().text_range(); 201 let name_range = name_ref.syntax().text_range();
197 if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() { 202 if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() {
198 self.record_lit_syntax = 203 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);
200 } 205 }
201 206
202 self.impl_def = self 207 self.impl_def = self