File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
crates/ra_ide/src/completion Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -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
}
Original file line number Diff line number Diff line change @@ -165,7 +165,7 @@ impl<'a> CompletionContext<'a> {
165
165
self . is_param = true ;
166
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
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
199
self . name_ref_syntax =
195
200
find_node_at_offset ( & original_file, name_ref. syntax ( ) . text_range ( ) . start ( ) ) ;
196
201
let name_range = name_ref. syntax ( ) . text_range ( ) ;
197
202
if name_ref. syntax ( ) . parent ( ) . and_then ( ast:: RecordField :: cast) . is_some ( ) {
198
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
207
self . impl_def = self
You can’t perform that action at this time.
0 commit comments