diff options
Diffstat (limited to 'crates/ra_ide/src/completion/complete_unqualified_path.rs')
-rw-r--r-- | crates/ra_ide/src/completion/complete_unqualified_path.rs | 1615 |
1 files changed, 424 insertions, 1191 deletions
diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index a0a04bb58..bd9551f35 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs | |||
@@ -1,11 +1,10 @@ | |||
1 | //! Completion of names from the current scope, e.g. locals and imported items. | 1 | //! Completion of names from the current scope, e.g. locals and imported items. |
2 | 2 | ||
3 | use hir::ScopeDef; | 3 | use hir::{Adt, ModuleDef, ScopeDef, Type}; |
4 | use ra_syntax::AstNode; | ||
4 | use test_utils::mark; | 5 | use test_utils::mark; |
5 | 6 | ||
6 | use crate::completion::{CompletionContext, Completions}; | 7 | use crate::completion::{CompletionContext, Completions}; |
7 | use hir::{Adt, ModuleDef, Type}; | ||
8 | use ra_syntax::AstNode; | ||
9 | 8 | ||
10 | pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { | 9 | pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { |
11 | if !(ctx.is_trivial_path || ctx.is_pat_binding_or_const) { | 10 | if !(ctx.is_trivial_path || ctx.is_pat_binding_or_const) { |
@@ -26,7 +25,7 @@ pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
26 | return; | 25 | return; |
27 | } | 26 | } |
28 | 27 | ||
29 | ctx.scope().process_all_names(&mut |name, res| { | 28 | ctx.scope.process_all_names(&mut |name, res| { |
30 | if ctx.use_item_syntax.is_some() { | 29 | if ctx.use_item_syntax.is_some() { |
31 | if let (ScopeDef::Unknown, Some(name_ref)) = (&res, &ctx.name_ref_syntax) { | 30 | if let (ScopeDef::Unknown, Some(name_ref)) = (&res, &ctx.name_ref_syntax) { |
32 | if name_ref.syntax().text() == name.to_string().as_str() { | 31 | if name_ref.syntax().text() == name.to_string().as_str() { |
@@ -43,7 +42,7 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T | |||
43 | if let Some(Adt::Enum(enum_data)) = ty.as_adt() { | 42 | if let Some(Adt::Enum(enum_data)) = ty.as_adt() { |
44 | let variants = enum_data.variants(ctx.db); | 43 | let variants = enum_data.variants(ctx.db); |
45 | 44 | ||
46 | let module = if let Some(module) = ctx.scope().module() { | 45 | let module = if let Some(module) = ctx.scope.module() { |
47 | // Compute path from the completion site if available. | 46 | // Compute path from the completion site if available. |
48 | module | 47 | module |
49 | } else { | 48 | } else { |
@@ -65,1361 +64,595 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T | |||
65 | 64 | ||
66 | #[cfg(test)] | 65 | #[cfg(test)] |
67 | mod tests { | 66 | mod tests { |
68 | use insta::assert_debug_snapshot; | 67 | use expect::{expect, Expect}; |
69 | use test_utils::mark; | 68 | use test_utils::mark; |
70 | 69 | ||
71 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | 70 | use crate::completion::{ |
71 | test_utils::{check_edit, completion_list}, | ||
72 | CompletionKind, | ||
73 | }; | ||
72 | 74 | ||
73 | fn do_reference_completion(ra_fixture: &str) -> Vec<CompletionItem> { | 75 | fn check(ra_fixture: &str, expect: Expect) { |
74 | do_completion(ra_fixture, CompletionKind::Reference) | 76 | let actual = completion_list(ra_fixture, CompletionKind::Reference); |
77 | expect.assert_eq(&actual) | ||
75 | } | 78 | } |
76 | 79 | ||
77 | #[test] | 80 | #[test] |
78 | fn self_fulfilling_completion() { | 81 | fn self_fulfilling_completion() { |
79 | mark::check!(self_fulfilling_completion); | 82 | mark::check!(self_fulfilling_completion); |
80 | assert_debug_snapshot!( | 83 | check( |
81 | do_reference_completion( | 84 | r#" |
82 | r#" | 85 | use foo<|> |
83 | use foo<|> | 86 | use std::collections; |
84 | use std::collections; | 87 | "#, |
85 | "#, | 88 | expect![[r#" |
86 | ), | 89 | ?? collections |
87 | @r###" | 90 | "#]], |
88 | [ | ||
89 | CompletionItem { | ||
90 | label: "collections", | ||
91 | source_range: 4..7, | ||
92 | delete: 4..7, | ||
93 | insert: "collections", | ||
94 | }, | ||
95 | ] | ||
96 | "### | ||
97 | ); | 91 | ); |
98 | } | 92 | } |
99 | 93 | ||
100 | #[test] | 94 | #[test] |
101 | fn bind_pat_and_path_ignore_at() { | 95 | fn bind_pat_and_path_ignore_at() { |
102 | assert_debug_snapshot!( | 96 | check( |
103 | do_reference_completion( | 97 | r#" |
104 | r" | 98 | enum Enum { A, B } |
105 | enum Enum { | 99 | fn quux(x: Option<Enum>) { |
106 | A, | 100 | match x { |
107 | B, | 101 | None => (), |
108 | } | 102 | Some(en<|> @ Enum::A) => (), |
109 | fn quux(x: Option<Enum>) { | 103 | } |
110 | match x { | 104 | } |
111 | None => (), | 105 | "#, |
112 | Some(en<|> @ Enum::A) => (), | 106 | expect![[""]], |
113 | } | ||
114 | } | ||
115 | " | ||
116 | ), | ||
117 | @"[]" | ||
118 | ); | 107 | ); |
119 | } | 108 | } |
120 | 109 | ||
121 | #[test] | 110 | #[test] |
122 | fn bind_pat_and_path_ignore_ref() { | 111 | fn bind_pat_and_path_ignore_ref() { |
123 | assert_debug_snapshot!( | 112 | check( |
124 | do_reference_completion( | 113 | r#" |
125 | r" | 114 | enum Enum { A, B } |
126 | enum Enum { | 115 | fn quux(x: Option<Enum>) { |
127 | A, | 116 | match x { |
128 | B, | 117 | None => (), |
129 | } | 118 | Some(ref en<|>) => (), |
130 | fn quux(x: Option<Enum>) { | 119 | } |
131 | match x { | 120 | } |
132 | None => (), | 121 | "#, |
133 | Some(ref en<|>) => (), | 122 | expect![[""]], |
134 | } | ||
135 | } | ||
136 | " | ||
137 | ), | ||
138 | @r###"[]"### | ||
139 | ); | 123 | ); |
140 | } | 124 | } |
141 | 125 | ||
142 | #[test] | 126 | #[test] |
143 | fn bind_pat_and_path() { | 127 | fn bind_pat_and_path() { |
144 | assert_debug_snapshot!( | 128 | check( |
145 | do_reference_completion( | 129 | r#" |
146 | r" | 130 | enum Enum { A, B } |
147 | enum Enum { | 131 | fn quux(x: Option<Enum>) { |
148 | A, | 132 | match x { |
149 | B, | 133 | None => (), |
150 | } | 134 | Some(En<|>) => (), |
151 | fn quux(x: Option<Enum>) { | 135 | } |
152 | match x { | 136 | } |
153 | None => (), | 137 | "#, |
154 | Some(En<|>) => (), | 138 | expect![[r#" |
155 | } | 139 | en Enum |
156 | } | 140 | "#]], |
157 | " | ||
158 | ), | ||
159 | @r###" | ||
160 | [ | ||
161 | CompletionItem { | ||
162 | label: "Enum", | ||
163 | source_range: 102..104, | ||
164 | delete: 102..104, | ||
165 | insert: "Enum", | ||
166 | kind: Enum, | ||
167 | }, | ||
168 | ] | ||
169 | "### | ||
170 | ); | 141 | ); |
171 | } | 142 | } |
172 | 143 | ||
173 | #[test] | 144 | #[test] |
174 | fn completes_bindings_from_let() { | 145 | fn completes_bindings_from_let() { |
175 | assert_debug_snapshot!( | 146 | check( |
176 | do_reference_completion( | 147 | r#" |
177 | r" | 148 | fn quux(x: i32) { |
178 | fn quux(x: i32) { | 149 | let y = 92; |
179 | let y = 92; | 150 | 1 + <|>; |
180 | 1 + <|>; | 151 | let z = (); |
181 | let z = (); | 152 | } |
182 | } | 153 | "#, |
183 | " | 154 | expect![[r#" |
184 | ), | 155 | fn quux(…) fn quux(x: i32) |
185 | @r###" | 156 | bn x i32 |
186 | [ | 157 | bn y i32 |
187 | CompletionItem { | 158 | "#]], |
188 | label: "quux(…)", | ||
189 | source_range: 42..42, | ||
190 | delete: 42..42, | ||
191 | insert: "quux(${1:x})$0", | ||
192 | kind: Function, | ||
193 | lookup: "quux", | ||
194 | detail: "fn quux(x: i32)", | ||
195 | trigger_call_info: true, | ||
196 | }, | ||
197 | CompletionItem { | ||
198 | label: "x", | ||
199 | source_range: 42..42, | ||
200 | delete: 42..42, | ||
201 | insert: "x", | ||
202 | kind: Binding, | ||
203 | detail: "i32", | ||
204 | }, | ||
205 | CompletionItem { | ||
206 | label: "y", | ||
207 | source_range: 42..42, | ||
208 | delete: 42..42, | ||
209 | insert: "y", | ||
210 | kind: Binding, | ||
211 | detail: "i32", | ||
212 | }, | ||
213 | ] | ||
214 | "### | ||
215 | ); | 159 | ); |
216 | } | 160 | } |
217 | 161 | ||
218 | #[test] | 162 | #[test] |
219 | fn completes_bindings_from_if_let() { | 163 | fn completes_bindings_from_if_let() { |
220 | assert_debug_snapshot!( | 164 | check( |
221 | do_reference_completion( | 165 | r#" |
222 | r" | 166 | fn quux() { |
223 | fn quux() { | 167 | if let Some(x) = foo() { |
224 | if let Some(x) = foo() { | 168 | let y = 92; |
225 | let y = 92; | 169 | }; |
226 | }; | 170 | if let Some(a) = bar() { |
227 | if let Some(a) = bar() { | 171 | let b = 62; |
228 | let b = 62; | 172 | 1 + <|> |
229 | 1 + <|> | 173 | } |
230 | } | 174 | } |
231 | } | 175 | "#, |
232 | " | 176 | expect![[r#" |
233 | ), | 177 | bn a |
234 | @r###" | 178 | bn b i32 |
235 | [ | 179 | fn quux() fn quux() |
236 | CompletionItem { | 180 | "#]], |
237 | label: "a", | ||
238 | source_range: 129..129, | ||
239 | delete: 129..129, | ||
240 | insert: "a", | ||
241 | kind: Binding, | ||
242 | }, | ||
243 | CompletionItem { | ||
244 | label: "b", | ||
245 | source_range: 129..129, | ||
246 | delete: 129..129, | ||
247 | insert: "b", | ||
248 | kind: Binding, | ||
249 | detail: "i32", | ||
250 | }, | ||
251 | CompletionItem { | ||
252 | label: "quux()", | ||
253 | source_range: 129..129, | ||
254 | delete: 129..129, | ||
255 | insert: "quux()$0", | ||
256 | kind: Function, | ||
257 | lookup: "quux", | ||
258 | detail: "fn quux()", | ||
259 | }, | ||
260 | ] | ||
261 | "### | ||
262 | ); | 181 | ); |
263 | } | 182 | } |
264 | 183 | ||
265 | #[test] | 184 | #[test] |
266 | fn completes_bindings_from_for() { | 185 | fn completes_bindings_from_for() { |
267 | assert_debug_snapshot!( | 186 | check( |
268 | do_reference_completion( | 187 | r#" |
269 | r" | 188 | fn quux() { |
270 | fn quux() { | 189 | for x in &[1, 2, 3] { <|> } |
271 | for x in &[1, 2, 3] { | 190 | } |
272 | <|> | 191 | "#, |
273 | } | 192 | expect![[r#" |
274 | } | 193 | fn quux() fn quux() |
275 | " | 194 | bn x |
276 | ), | 195 | "#]], |
277 | @r###" | ||
278 | [ | ||
279 | CompletionItem { | ||
280 | label: "quux()", | ||
281 | source_range: 46..46, | ||
282 | delete: 46..46, | ||
283 | insert: "quux()$0", | ||
284 | kind: Function, | ||
285 | lookup: "quux", | ||
286 | detail: "fn quux()", | ||
287 | }, | ||
288 | CompletionItem { | ||
289 | label: "x", | ||
290 | source_range: 46..46, | ||
291 | delete: 46..46, | ||
292 | insert: "x", | ||
293 | kind: Binding, | ||
294 | }, | ||
295 | ] | ||
296 | "### | ||
297 | ); | 196 | ); |
298 | } | 197 | } |
299 | 198 | ||
300 | #[test] | 199 | #[test] |
301 | fn completes_bindings_from_for_with_in_prefix() { | 200 | fn completes_if_prefix_is_keyword() { |
302 | mark::check!(completes_bindings_from_for_with_in_prefix); | 201 | mark::check!(completes_if_prefix_is_keyword); |
303 | assert_debug_snapshot!( | 202 | check_edit( |
304 | do_reference_completion( | 203 | "wherewolf", |
305 | r" | 204 | r#" |
306 | fn test() { | 205 | fn main() { |
307 | for index in &[1, 2, 3] { | 206 | let wherewolf = 92; |
308 | let t = in<|> | 207 | drop(where<|>) |
309 | } | 208 | } |
310 | } | 209 | "#, |
311 | " | 210 | r#" |
312 | ), | 211 | fn main() { |
313 | @r###" | 212 | let wherewolf = 92; |
314 | [ | 213 | drop(wherewolf) |
315 | CompletionItem { | 214 | } |
316 | label: "index", | 215 | "#, |
317 | source_range: 58..58, | 216 | ) |
318 | delete: 58..58, | ||
319 | insert: "index", | ||
320 | kind: Binding, | ||
321 | }, | ||
322 | CompletionItem { | ||
323 | label: "test()", | ||
324 | source_range: 58..58, | ||
325 | delete: 58..58, | ||
326 | insert: "test()$0", | ||
327 | kind: Function, | ||
328 | lookup: "test", | ||
329 | detail: "fn test()", | ||
330 | }, | ||
331 | ] | ||
332 | "### | ||
333 | ); | ||
334 | } | 217 | } |
335 | 218 | ||
336 | #[test] | 219 | #[test] |
337 | fn completes_generic_params() { | 220 | fn completes_generic_params() { |
338 | assert_debug_snapshot!( | 221 | check( |
339 | do_reference_completion( | 222 | r#"fn quux<T>() { <|> }"#, |
340 | r" | 223 | expect![[r#" |
341 | fn quux<T>() { | 224 | tp T |
342 | <|> | 225 | fn quux() fn quux<T>() |
343 | } | 226 | "#]], |
344 | " | ||
345 | ), | ||
346 | @r###" | ||
347 | [ | ||
348 | CompletionItem { | ||
349 | label: "T", | ||
350 | source_range: 19..19, | ||
351 | delete: 19..19, | ||
352 | insert: "T", | ||
353 | kind: TypeParam, | ||
354 | }, | ||
355 | CompletionItem { | ||
356 | label: "quux()", | ||
357 | source_range: 19..19, | ||
358 | delete: 19..19, | ||
359 | insert: "quux()$0", | ||
360 | kind: Function, | ||
361 | lookup: "quux", | ||
362 | detail: "fn quux<T>()", | ||
363 | }, | ||
364 | ] | ||
365 | "### | ||
366 | ); | 227 | ); |
367 | } | 228 | } |
368 | 229 | ||
369 | #[test] | 230 | #[test] |
370 | fn completes_generic_params_in_struct() { | 231 | fn completes_generic_params_in_struct() { |
371 | assert_debug_snapshot!( | 232 | check( |
372 | do_reference_completion( | 233 | r#"struct S<T> { x: <|>}"#, |
373 | r" | 234 | expect![[r#" |
374 | struct X<T> { | 235 | st S<…> |
375 | x: <|> | 236 | tp Self |
376 | } | 237 | tp T |
377 | " | 238 | "#]], |
378 | ), | ||
379 | @r###" | ||
380 | [ | ||
381 | CompletionItem { | ||
382 | label: "Self", | ||
383 | source_range: 21..21, | ||
384 | delete: 21..21, | ||
385 | insert: "Self", | ||
386 | kind: TypeParam, | ||
387 | }, | ||
388 | CompletionItem { | ||
389 | label: "T", | ||
390 | source_range: 21..21, | ||
391 | delete: 21..21, | ||
392 | insert: "T", | ||
393 | kind: TypeParam, | ||
394 | }, | ||
395 | CompletionItem { | ||
396 | label: "X<…>", | ||
397 | source_range: 21..21, | ||
398 | delete: 21..21, | ||
399 | insert: "X<$0>", | ||
400 | kind: Struct, | ||
401 | lookup: "X", | ||
402 | }, | ||
403 | ] | ||
404 | "### | ||
405 | ); | 239 | ); |
406 | } | 240 | } |
407 | 241 | ||
408 | #[test] | 242 | #[test] |
409 | fn completes_self_in_enum() { | 243 | fn completes_self_in_enum() { |
410 | assert_debug_snapshot!( | 244 | check( |
411 | do_reference_completion( | 245 | r#"enum X { Y(<|>) }"#, |
412 | r" | 246 | expect![[r#" |
413 | enum X { | 247 | tp Self |
414 | Y(<|>) | 248 | en X |
415 | } | 249 | "#]], |
416 | " | ||
417 | ), | ||
418 | @r###" | ||
419 | [ | ||
420 | CompletionItem { | ||
421 | label: "Self", | ||
422 | source_range: 15..15, | ||
423 | delete: 15..15, | ||
424 | insert: "Self", | ||
425 | kind: TypeParam, | ||
426 | }, | ||
427 | CompletionItem { | ||
428 | label: "X", | ||
429 | source_range: 15..15, | ||
430 | delete: 15..15, | ||
431 | insert: "X", | ||
432 | kind: Enum, | ||
433 | }, | ||
434 | ] | ||
435 | "### | ||
436 | ); | 250 | ); |
437 | } | 251 | } |
438 | 252 | ||
439 | #[test] | 253 | #[test] |
440 | fn completes_module_items() { | 254 | fn completes_module_items() { |
441 | assert_debug_snapshot!( | 255 | check( |
442 | do_reference_completion( | 256 | r#" |
443 | r" | 257 | struct S; |
444 | struct Foo; | 258 | enum E {} |
445 | enum Baz {} | 259 | fn quux() { <|> } |
446 | fn quux() { | 260 | "#, |
447 | <|> | 261 | expect![[r#" |
448 | } | 262 | en E |
449 | " | 263 | st S |
450 | ), | 264 | fn quux() fn quux() |
451 | @r###" | 265 | "#]], |
452 | [ | 266 | ); |
453 | CompletionItem { | ||
454 | label: "Baz", | ||
455 | source_range: 40..40, | ||
456 | delete: 40..40, | ||
457 | insert: "Baz", | ||
458 | kind: Enum, | ||
459 | }, | ||
460 | CompletionItem { | ||
461 | label: "Foo", | ||
462 | source_range: 40..40, | ||
463 | delete: 40..40, | ||
464 | insert: "Foo", | ||
465 | kind: Struct, | ||
466 | }, | ||
467 | CompletionItem { | ||
468 | label: "quux()", | ||
469 | source_range: 40..40, | ||
470 | delete: 40..40, | ||
471 | insert: "quux()$0", | ||
472 | kind: Function, | ||
473 | lookup: "quux", | ||
474 | detail: "fn quux()", | ||
475 | }, | ||
476 | ] | ||
477 | "### | ||
478 | ); | ||
479 | } | 267 | } |
480 | 268 | ||
481 | #[test] | 269 | #[test] |
482 | fn completes_extern_prelude() { | 270 | fn completes_extern_prelude() { |
483 | assert_debug_snapshot!( | 271 | check( |
484 | do_reference_completion( | 272 | r#" |
485 | r" | 273 | //- /lib.rs |
486 | //- /lib.rs | 274 | use <|>; |
487 | use <|>; | 275 | |
488 | 276 | //- /other_crate/lib.rs | |
489 | //- /other_crate/lib.rs | 277 | // nothing here |
490 | // nothing here | 278 | "#, |
491 | " | 279 | expect![[r#" |
492 | ), | 280 | md other_crate |
493 | @r###" | 281 | "#]], |
494 | [ | ||
495 | CompletionItem { | ||
496 | label: "other_crate", | ||
497 | source_range: 4..4, | ||
498 | delete: 4..4, | ||
499 | insert: "other_crate", | ||
500 | kind: Module, | ||
501 | }, | ||
502 | ] | ||
503 | "### | ||
504 | ); | 282 | ); |
505 | } | 283 | } |
506 | 284 | ||
507 | #[test] | 285 | #[test] |
508 | fn completes_module_items_in_nested_modules() { | 286 | fn completes_module_items_in_nested_modules() { |
509 | assert_debug_snapshot!( | 287 | check( |
510 | do_reference_completion( | 288 | r#" |
511 | r" | 289 | struct Foo; |
512 | struct Foo; | 290 | mod m { |
513 | mod m { | 291 | struct Bar; |
514 | struct Bar; | 292 | fn quux() { <|> } |
515 | fn quux() { <|> } | 293 | } |
516 | } | 294 | "#, |
517 | " | 295 | expect![[r#" |
518 | ), | 296 | st Bar |
519 | @r###" | 297 | fn quux() fn quux() |
520 | [ | 298 | "#]], |
521 | CompletionItem { | ||
522 | label: "Bar", | ||
523 | source_range: 52..52, | ||
524 | delete: 52..52, | ||
525 | insert: "Bar", | ||
526 | kind: Struct, | ||
527 | }, | ||
528 | CompletionItem { | ||
529 | label: "quux()", | ||
530 | source_range: 52..52, | ||
531 | delete: 52..52, | ||
532 | insert: "quux()$0", | ||
533 | kind: Function, | ||
534 | lookup: "quux", | ||
535 | detail: "fn quux()", | ||
536 | }, | ||
537 | ] | ||
538 | "### | ||
539 | ); | 299 | ); |
540 | } | 300 | } |
541 | 301 | ||
542 | #[test] | 302 | #[test] |
543 | fn completes_return_type() { | 303 | fn completes_return_type() { |
544 | assert_debug_snapshot!( | 304 | check( |
545 | do_reference_completion( | 305 | r#" |
546 | r" | 306 | struct Foo; |
547 | struct Foo; | 307 | fn x() -> <|> |
548 | fn x() -> <|> | 308 | "#, |
549 | " | 309 | expect![[r#" |
550 | ), | 310 | st Foo |
551 | @r###" | 311 | fn x() fn x() |
552 | [ | 312 | "#]], |
553 | CompletionItem { | ||
554 | label: "Foo", | ||
555 | source_range: 22..22, | ||
556 | delete: 22..22, | ||
557 | insert: "Foo", | ||
558 | kind: Struct, | ||
559 | }, | ||
560 | CompletionItem { | ||
561 | label: "x()", | ||
562 | source_range: 22..22, | ||
563 | delete: 22..22, | ||
564 | insert: "x()$0", | ||
565 | kind: Function, | ||
566 | lookup: "x", | ||
567 | detail: "fn x()", | ||
568 | }, | ||
569 | ] | ||
570 | "### | ||
571 | ); | 313 | ); |
572 | } | 314 | } |
573 | 315 | ||
574 | #[test] | 316 | #[test] |
575 | fn dont_show_both_completions_for_shadowing() { | 317 | fn dont_show_both_completions_for_shadowing() { |
576 | assert_debug_snapshot!( | 318 | check( |
577 | do_reference_completion( | 319 | r#" |
578 | r" | 320 | fn foo() { |
579 | fn foo() { | 321 | let bar = 92; |
580 | let bar = 92; | 322 | { |
581 | { | 323 | let bar = 62; |
582 | let bar = 62; | 324 | drop(<|>) |
583 | <|> | 325 | } |
584 | } | 326 | } |
585 | } | 327 | "#, |
586 | " | 328 | // FIXME: should be only one bar here |
587 | ), | 329 | expect![[r#" |
588 | @r###" | 330 | bn bar i32 |
589 | [ | 331 | bn bar i32 |
590 | CompletionItem { | 332 | fn foo() fn foo() |
591 | label: "bar", | 333 | "#]], |
592 | source_range: 65..65, | ||
593 | delete: 65..65, | ||
594 | insert: "bar", | ||
595 | kind: Binding, | ||
596 | detail: "i32", | ||
597 | }, | ||
598 | CompletionItem { | ||
599 | label: "foo()", | ||
600 | source_range: 65..65, | ||
601 | delete: 65..65, | ||
602 | insert: "foo()$0", | ||
603 | kind: Function, | ||
604 | lookup: "foo", | ||
605 | detail: "fn foo()", | ||
606 | }, | ||
607 | ] | ||
608 | "### | ||
609 | ); | 334 | ); |
610 | } | 335 | } |
611 | 336 | ||
612 | #[test] | 337 | #[test] |
613 | fn completes_self_in_methods() { | 338 | fn completes_self_in_methods() { |
614 | assert_debug_snapshot!( | 339 | check( |
615 | do_reference_completion(r"impl S { fn foo(&self) { <|> } }"), | 340 | r#"impl S { fn foo(&self) { <|> } }"#, |
616 | @r###" | 341 | expect![[r#" |
617 | [ | 342 | tp Self |
618 | CompletionItem { | 343 | bn self &{unknown} |
619 | label: "Self", | 344 | "#]], |
620 | source_range: 25..25, | ||
621 | delete: 25..25, | ||
622 | insert: "Self", | ||
623 | kind: TypeParam, | ||
624 | }, | ||
625 | CompletionItem { | ||
626 | label: "self", | ||
627 | source_range: 25..25, | ||
628 | delete: 25..25, | ||
629 | insert: "self", | ||
630 | kind: Binding, | ||
631 | detail: "&{unknown}", | ||
632 | }, | ||
633 | ] | ||
634 | "### | ||
635 | ); | 345 | ); |
636 | } | 346 | } |
637 | 347 | ||
638 | #[test] | 348 | #[test] |
639 | fn completes_prelude() { | 349 | fn completes_prelude() { |
640 | assert_debug_snapshot!( | 350 | check( |
641 | do_reference_completion( | 351 | r#" |
642 | " | 352 | //- /main.rs |
643 | //- /main.rs | 353 | fn foo() { let x: <|> } |
644 | fn foo() { let x: <|> } | 354 | |
645 | 355 | //- /std/lib.rs | |
646 | //- /std/lib.rs | 356 | #[prelude_import] |
647 | #[prelude_import] | 357 | use prelude::*; |
648 | use prelude::*; | 358 | |
649 | 359 | mod prelude { struct Option; } | |
650 | mod prelude { | 360 | "#, |
651 | struct Option; | 361 | expect![[r#" |
652 | } | 362 | st Option |
653 | " | 363 | fn foo() fn foo() |
654 | ), | 364 | md std |
655 | @r###" | 365 | "#]], |
656 | [ | ||
657 | CompletionItem { | ||
658 | label: "Option", | ||
659 | source_range: 18..18, | ||
660 | delete: 18..18, | ||
661 | insert: "Option", | ||
662 | kind: Struct, | ||
663 | }, | ||
664 | CompletionItem { | ||
665 | label: "foo()", | ||
666 | source_range: 18..18, | ||
667 | delete: 18..18, | ||
668 | insert: "foo()$0", | ||
669 | kind: Function, | ||
670 | lookup: "foo", | ||
671 | detail: "fn foo()", | ||
672 | }, | ||
673 | CompletionItem { | ||
674 | label: "std", | ||
675 | source_range: 18..18, | ||
676 | delete: 18..18, | ||
677 | insert: "std", | ||
678 | kind: Module, | ||
679 | }, | ||
680 | ] | ||
681 | "### | ||
682 | ); | 366 | ); |
683 | } | 367 | } |
684 | 368 | ||
685 | #[test] | 369 | #[test] |
686 | fn completes_std_prelude_if_core_is_defined() { | 370 | fn completes_std_prelude_if_core_is_defined() { |
687 | assert_debug_snapshot!( | 371 | check( |
688 | do_reference_completion( | 372 | r#" |
689 | " | 373 | //- /main.rs |
690 | //- /main.rs | 374 | fn foo() { let x: <|> } |
691 | fn foo() { let x: <|> } | 375 | |
692 | 376 | //- /core/lib.rs | |
693 | //- /core/lib.rs | 377 | #[prelude_import] |
694 | #[prelude_import] | 378 | use prelude::*; |
695 | use prelude::*; | 379 | |
696 | 380 | mod prelude { struct Option; } | |
697 | mod prelude { | 381 | |
698 | struct Option; | 382 | //- /std/lib.rs |
699 | } | 383 | #[prelude_import] |
700 | 384 | use prelude::*; | |
701 | //- /std/lib.rs | 385 | |
702 | #[prelude_import] | 386 | mod prelude { struct String; } |
703 | use prelude::*; | 387 | "#, |
704 | 388 | expect![[r#" | |
705 | mod prelude { | 389 | st String |
706 | struct String; | 390 | md core |
707 | } | 391 | fn foo() fn foo() |
708 | " | 392 | md std |
709 | ), | 393 | "#]], |
710 | @r###" | ||
711 | [ | ||
712 | CompletionItem { | ||
713 | label: "String", | ||
714 | source_range: 18..18, | ||
715 | delete: 18..18, | ||
716 | insert: "String", | ||
717 | kind: Struct, | ||
718 | }, | ||
719 | CompletionItem { | ||
720 | label: "core", | ||
721 | source_range: 18..18, | ||
722 | delete: 18..18, | ||
723 | insert: "core", | ||
724 | kind: Module, | ||
725 | }, | ||
726 | CompletionItem { | ||
727 | label: "foo()", | ||
728 | source_range: 18..18, | ||
729 | delete: 18..18, | ||
730 | insert: "foo()$0", | ||
731 | kind: Function, | ||
732 | lookup: "foo", | ||
733 | detail: "fn foo()", | ||
734 | }, | ||
735 | CompletionItem { | ||
736 | label: "std", | ||
737 | source_range: 18..18, | ||
738 | delete: 18..18, | ||
739 | insert: "std", | ||
740 | kind: Module, | ||
741 | }, | ||
742 | ] | ||
743 | "### | ||
744 | ); | 394 | ); |
745 | } | 395 | } |
746 | 396 | ||
747 | #[test] | 397 | #[test] |
748 | fn completes_macros_as_value() { | 398 | fn completes_macros_as_value() { |
749 | assert_debug_snapshot!( | 399 | check( |
750 | do_reference_completion( | 400 | r#" |
751 | " | 401 | macro_rules! foo { () => {} } |
752 | //- /main.rs | ||
753 | macro_rules! foo { | ||
754 | () => {} | ||
755 | } | ||
756 | 402 | ||
757 | #[macro_use] | 403 | #[macro_use] |
758 | mod m1 { | 404 | mod m1 { |
759 | macro_rules! bar { | 405 | macro_rules! bar { () => {} } |
760 | () => {} | 406 | } |
761 | } | ||
762 | } | ||
763 | 407 | ||
764 | mod m2 { | 408 | mod m2 { |
765 | macro_rules! nope { | 409 | macro_rules! nope { () => {} } |
766 | () => {} | ||
767 | } | ||
768 | 410 | ||
769 | #[macro_export] | 411 | #[macro_export] |
770 | macro_rules! baz { | 412 | macro_rules! baz { () => {} } |
771 | () => {} | 413 | } |
772 | } | ||
773 | } | ||
774 | 414 | ||
775 | fn main() { | 415 | fn main() { let v = <|> } |
776 | let v = <|> | 416 | "#, |
777 | } | 417 | expect![[r##" |
778 | " | 418 | ma bar!(…) macro_rules! bar |
779 | ), | 419 | ma baz!(…) #[macro_export] |
780 | @r###" | 420 | macro_rules! baz |
781 | [ | 421 | ma foo!(…) macro_rules! foo |
782 | CompletionItem { | 422 | md m1 |
783 | label: "bar!(…)", | 423 | md m2 |
784 | source_range: 256..256, | 424 | fn main() fn main() |
785 | delete: 256..256, | 425 | "##]], |
786 | insert: "bar!($0)", | ||
787 | kind: Macro, | ||
788 | detail: "macro_rules! bar", | ||
789 | }, | ||
790 | CompletionItem { | ||
791 | label: "baz!(…)", | ||
792 | source_range: 256..256, | ||
793 | delete: 256..256, | ||
794 | insert: "baz!($0)", | ||
795 | kind: Macro, | ||
796 | detail: "#[macro_export]\nmacro_rules! baz", | ||
797 | }, | ||
798 | CompletionItem { | ||
799 | label: "foo!(…)", | ||
800 | source_range: 256..256, | ||
801 | delete: 256..256, | ||
802 | insert: "foo!($0)", | ||
803 | kind: Macro, | ||
804 | detail: "macro_rules! foo", | ||
805 | }, | ||
806 | CompletionItem { | ||
807 | label: "m1", | ||
808 | source_range: 256..256, | ||
809 | delete: 256..256, | ||
810 | insert: "m1", | ||
811 | kind: Module, | ||
812 | }, | ||
813 | CompletionItem { | ||
814 | label: "m2", | ||
815 | source_range: 256..256, | ||
816 | delete: 256..256, | ||
817 | insert: "m2", | ||
818 | kind: Module, | ||
819 | }, | ||
820 | CompletionItem { | ||
821 | label: "main()", | ||
822 | source_range: 256..256, | ||
823 | delete: 256..256, | ||
824 | insert: "main()$0", | ||
825 | kind: Function, | ||
826 | lookup: "main", | ||
827 | detail: "fn main()", | ||
828 | }, | ||
829 | ] | ||
830 | "### | ||
831 | ); | 426 | ); |
832 | } | 427 | } |
833 | 428 | ||
834 | #[test] | 429 | #[test] |
835 | fn completes_both_macro_and_value() { | 430 | fn completes_both_macro_and_value() { |
836 | assert_debug_snapshot!( | 431 | check( |
837 | do_reference_completion( | 432 | r#" |
838 | " | 433 | macro_rules! foo { () => {} } |
839 | //- /main.rs | 434 | fn foo() { <|> } |
840 | macro_rules! foo { | 435 | "#, |
841 | () => {} | 436 | expect![[r#" |
842 | } | 437 | ma foo!(…) macro_rules! foo |
843 | 438 | fn foo() fn foo() | |
844 | fn foo() { | 439 | "#]], |
845 | <|> | ||
846 | } | ||
847 | " | ||
848 | ), | ||
849 | @r###" | ||
850 | [ | ||
851 | CompletionItem { | ||
852 | label: "foo!(…)", | ||
853 | source_range: 50..50, | ||
854 | delete: 50..50, | ||
855 | insert: "foo!($0)", | ||
856 | kind: Macro, | ||
857 | detail: "macro_rules! foo", | ||
858 | }, | ||
859 | CompletionItem { | ||
860 | label: "foo()", | ||
861 | source_range: 50..50, | ||
862 | delete: 50..50, | ||
863 | insert: "foo()$0", | ||
864 | kind: Function, | ||
865 | lookup: "foo", | ||
866 | detail: "fn foo()", | ||
867 | }, | ||
868 | ] | ||
869 | "### | ||
870 | ); | 440 | ); |
871 | } | 441 | } |
872 | 442 | ||
873 | #[test] | 443 | #[test] |
874 | fn completes_macros_as_type() { | 444 | fn completes_macros_as_type() { |
875 | assert_debug_snapshot!( | 445 | check( |
876 | do_reference_completion( | 446 | r#" |
877 | " | 447 | macro_rules! foo { () => {} } |
878 | //- /main.rs | 448 | fn main() { let x: <|> } |
879 | macro_rules! foo { | 449 | "#, |
880 | () => {} | 450 | expect![[r#" |
881 | } | 451 | ma foo!(…) macro_rules! foo |
882 | 452 | fn main() fn main() | |
883 | fn main() { | 453 | "#]], |
884 | let x: <|> | ||
885 | } | ||
886 | " | ||
887 | ), | ||
888 | @r###" | ||
889 | [ | ||
890 | CompletionItem { | ||
891 | label: "foo!(…)", | ||
892 | source_range: 58..58, | ||
893 | delete: 58..58, | ||
894 | insert: "foo!($0)", | ||
895 | kind: Macro, | ||
896 | detail: "macro_rules! foo", | ||
897 | }, | ||
898 | CompletionItem { | ||
899 | label: "main()", | ||
900 | source_range: 58..58, | ||
901 | delete: 58..58, | ||
902 | insert: "main()$0", | ||
903 | kind: Function, | ||
904 | lookup: "main", | ||
905 | detail: "fn main()", | ||
906 | }, | ||
907 | ] | ||
908 | "### | ||
909 | ); | 454 | ); |
910 | } | 455 | } |
911 | 456 | ||
912 | #[test] | 457 | #[test] |
913 | fn completes_macros_as_stmt() { | 458 | fn completes_macros_as_stmt() { |
914 | assert_debug_snapshot!( | 459 | check( |
915 | do_reference_completion( | 460 | r#" |
916 | " | 461 | macro_rules! foo { () => {} } |
917 | //- /main.rs | 462 | fn main() { <|> } |
918 | macro_rules! foo { | 463 | "#, |
919 | () => {} | 464 | expect![[r#" |
920 | } | 465 | ma foo!(…) macro_rules! foo |
921 | 466 | fn main() fn main() | |
922 | fn main() { | 467 | "#]], |
923 | <|> | ||
924 | } | ||
925 | " | ||
926 | ), | ||
927 | @r###" | ||
928 | [ | ||
929 | CompletionItem { | ||
930 | label: "foo!(…)", | ||
931 | source_range: 51..51, | ||
932 | delete: 51..51, | ||
933 | insert: "foo!($0)", | ||
934 | kind: Macro, | ||
935 | detail: "macro_rules! foo", | ||
936 | }, | ||
937 | CompletionItem { | ||
938 | label: "main()", | ||
939 | source_range: 51..51, | ||
940 | delete: 51..51, | ||
941 | insert: "main()$0", | ||
942 | kind: Function, | ||
943 | lookup: "main", | ||
944 | detail: "fn main()", | ||
945 | }, | ||
946 | ] | ||
947 | "### | ||
948 | ); | 468 | ); |
949 | } | 469 | } |
950 | 470 | ||
951 | #[test] | 471 | #[test] |
952 | fn completes_local_item() { | 472 | fn completes_local_item() { |
953 | assert_debug_snapshot!( | 473 | check( |
954 | do_reference_completion( | 474 | r#" |
955 | " | 475 | fn main() { |
956 | //- /main.rs | 476 | return f<|>; |
957 | fn main() { | 477 | fn frobnicate() {} |
958 | return f<|>; | 478 | } |
959 | fn frobnicate() {} | 479 | "#, |
960 | } | 480 | expect![[r#" |
961 | " | 481 | fn frobnicate() fn frobnicate() |
962 | ), | 482 | fn main() fn main() |
963 | @r###" | 483 | "#]], |
964 | [ | 484 | ); |
965 | CompletionItem { | ||
966 | label: "frobnicate()", | ||
967 | source_range: 23..24, | ||
968 | delete: 23..24, | ||
969 | insert: "frobnicate()$0", | ||
970 | kind: Function, | ||
971 | lookup: "frobnicate", | ||
972 | detail: "fn frobnicate()", | ||
973 | }, | ||
974 | CompletionItem { | ||
975 | label: "main()", | ||
976 | source_range: 23..24, | ||
977 | delete: 23..24, | ||
978 | insert: "main()$0", | ||
979 | kind: Function, | ||
980 | lookup: "main", | ||
981 | detail: "fn main()", | ||
982 | }, | ||
983 | ] | ||
984 | "### | ||
985 | ) | ||
986 | } | 485 | } |
987 | 486 | ||
988 | #[test] | 487 | #[test] |
989 | fn completes_in_simple_macro_1() { | 488 | fn completes_in_simple_macro_1() { |
990 | assert_debug_snapshot!( | 489 | check( |
991 | do_reference_completion( | 490 | r#" |
992 | r" | 491 | macro_rules! m { ($e:expr) => { $e } } |
993 | macro_rules! m { ($e:expr) => { $e } } | 492 | fn quux(x: i32) { |
994 | fn quux(x: i32) { | 493 | let y = 92; |
995 | let y = 92; | 494 | m!(<|>); |
996 | m!(<|>); | 495 | } |
997 | } | 496 | "#, |
998 | " | 497 | expect![[r#" |
999 | ), | 498 | ma m!(…) macro_rules! m |
1000 | @r###" | 499 | fn quux(…) fn quux(x: i32) |
1001 | [ | 500 | bn x i32 |
1002 | CompletionItem { | 501 | bn y i32 |
1003 | label: "m!(…)", | 502 | "#]], |
1004 | source_range: 80..80, | ||
1005 | delete: 80..80, | ||
1006 | insert: "m!($0)", | ||
1007 | kind: Macro, | ||
1008 | detail: "macro_rules! m", | ||
1009 | }, | ||
1010 | CompletionItem { | ||
1011 | label: "quux(…)", | ||
1012 | source_range: 80..80, | ||
1013 | delete: 80..80, | ||
1014 | insert: "quux(${1:x})$0", | ||
1015 | kind: Function, | ||
1016 | lookup: "quux", | ||
1017 | detail: "fn quux(x: i32)", | ||
1018 | trigger_call_info: true, | ||
1019 | }, | ||
1020 | CompletionItem { | ||
1021 | label: "x", | ||
1022 | source_range: 80..80, | ||
1023 | delete: 80..80, | ||
1024 | insert: "x", | ||
1025 | kind: Binding, | ||
1026 | detail: "i32", | ||
1027 | }, | ||
1028 | CompletionItem { | ||
1029 | label: "y", | ||
1030 | source_range: 80..80, | ||
1031 | delete: 80..80, | ||
1032 | insert: "y", | ||
1033 | kind: Binding, | ||
1034 | detail: "i32", | ||
1035 | }, | ||
1036 | ] | ||
1037 | "### | ||
1038 | ); | 503 | ); |
1039 | } | 504 | } |
1040 | 505 | ||
1041 | #[test] | 506 | #[test] |
1042 | fn completes_in_simple_macro_2() { | 507 | fn completes_in_simple_macro_2() { |
1043 | assert_debug_snapshot!( | 508 | check( |
1044 | do_reference_completion( | 509 | r" |
1045 | r" | 510 | macro_rules! m { ($e:expr) => { $e } } |
1046 | macro_rules! m { ($e:expr) => { $e } } | 511 | fn quux(x: i32) { |
1047 | fn quux(x: i32) { | 512 | let y = 92; |
1048 | let y = 92; | 513 | m!(x<|>); |
1049 | m!(x<|>); | 514 | } |
1050 | } | 515 | ", |
1051 | " | 516 | expect![[r#" |
1052 | ), | 517 | ma m!(…) macro_rules! m |
1053 | @r###" | 518 | fn quux(…) fn quux(x: i32) |
1054 | [ | 519 | bn x i32 |
1055 | CompletionItem { | 520 | bn y i32 |
1056 | label: "m!(…)", | 521 | "#]], |
1057 | source_range: 80..81, | ||
1058 | delete: 80..81, | ||
1059 | insert: "m!($0)", | ||
1060 | kind: Macro, | ||
1061 | detail: "macro_rules! m", | ||
1062 | }, | ||
1063 | CompletionItem { | ||
1064 | label: "quux(…)", | ||
1065 | source_range: 80..81, | ||
1066 | delete: 80..81, | ||
1067 | insert: "quux(${1:x})$0", | ||
1068 | kind: Function, | ||
1069 | lookup: "quux", | ||
1070 | detail: "fn quux(x: i32)", | ||
1071 | trigger_call_info: true, | ||
1072 | }, | ||
1073 | CompletionItem { | ||
1074 | label: "x", | ||
1075 | source_range: 80..81, | ||
1076 | delete: 80..81, | ||
1077 | insert: "x", | ||
1078 | kind: Binding, | ||
1079 | detail: "i32", | ||
1080 | }, | ||
1081 | CompletionItem { | ||
1082 | label: "y", | ||
1083 | source_range: 80..81, | ||
1084 | delete: 80..81, | ||
1085 | insert: "y", | ||
1086 | kind: Binding, | ||
1087 | detail: "i32", | ||
1088 | }, | ||
1089 | ] | ||
1090 | "### | ||
1091 | ); | 522 | ); |
1092 | } | 523 | } |
1093 | 524 | ||
1094 | #[test] | 525 | #[test] |
1095 | fn completes_in_simple_macro_without_closing_parens() { | 526 | fn completes_in_simple_macro_without_closing_parens() { |
1096 | assert_debug_snapshot!( | 527 | check( |
1097 | do_reference_completion( | 528 | r#" |
1098 | r" | 529 | macro_rules! m { ($e:expr) => { $e } } |
1099 | macro_rules! m { ($e:expr) => { $e } } | 530 | fn quux(x: i32) { |
1100 | fn quux(x: i32) { | 531 | let y = 92; |
1101 | let y = 92; | 532 | m!(x<|> |
1102 | m!(x<|> | 533 | } |
1103 | } | 534 | "#, |
1104 | " | 535 | expect![[r#" |
1105 | ), | 536 | ma m!(…) macro_rules! m |
1106 | @r###" | 537 | fn quux(…) fn quux(x: i32) |
1107 | [ | 538 | bn x i32 |
1108 | CompletionItem { | 539 | bn y i32 |
1109 | label: "m!(…)", | 540 | "#]], |
1110 | source_range: 80..81, | ||
1111 | delete: 80..81, | ||
1112 | insert: "m!($0)", | ||
1113 | kind: Macro, | ||
1114 | detail: "macro_rules! m", | ||
1115 | }, | ||
1116 | CompletionItem { | ||
1117 | label: "quux(…)", | ||
1118 | source_range: 80..81, | ||
1119 | delete: 80..81, | ||
1120 | insert: "quux(${1:x})$0", | ||
1121 | kind: Function, | ||
1122 | lookup: "quux", | ||
1123 | detail: "fn quux(x: i32)", | ||
1124 | trigger_call_info: true, | ||
1125 | }, | ||
1126 | CompletionItem { | ||
1127 | label: "x", | ||
1128 | source_range: 80..81, | ||
1129 | delete: 80..81, | ||
1130 | insert: "x", | ||
1131 | kind: Binding, | ||
1132 | detail: "i32", | ||
1133 | }, | ||
1134 | CompletionItem { | ||
1135 | label: "y", | ||
1136 | source_range: 80..81, | ||
1137 | delete: 80..81, | ||
1138 | insert: "y", | ||
1139 | kind: Binding, | ||
1140 | detail: "i32", | ||
1141 | }, | ||
1142 | ] | ||
1143 | "### | ||
1144 | ); | 541 | ); |
1145 | } | 542 | } |
1146 | 543 | ||
1147 | #[test] | 544 | #[test] |
1148 | fn completes_unresolved_uses() { | 545 | fn completes_unresolved_uses() { |
1149 | assert_debug_snapshot!( | 546 | check( |
1150 | do_reference_completion( | 547 | r#" |
1151 | r" | 548 | use spam::Quux; |
1152 | use spam::Quux; | 549 | |
1153 | 550 | fn main() { <|> } | |
1154 | fn main() { | 551 | "#, |
1155 | <|> | 552 | expect![[r#" |
1156 | } | 553 | ?? Quux |
1157 | " | 554 | fn main() fn main() |
1158 | ), | 555 | "#]], |
1159 | @r###" | ||
1160 | [ | ||
1161 | CompletionItem { | ||
1162 | label: "Quux", | ||
1163 | source_range: 33..33, | ||
1164 | delete: 33..33, | ||
1165 | insert: "Quux", | ||
1166 | }, | ||
1167 | CompletionItem { | ||
1168 | label: "main()", | ||
1169 | source_range: 33..33, | ||
1170 | delete: 33..33, | ||
1171 | insert: "main()$0", | ||
1172 | kind: Function, | ||
1173 | lookup: "main", | ||
1174 | detail: "fn main()", | ||
1175 | }, | ||
1176 | ] | ||
1177 | "### | ||
1178 | ); | 556 | ); |
1179 | } | 557 | } |
1180 | #[test] | 558 | #[test] |
1181 | fn completes_enum_variant_matcharm() { | 559 | fn completes_enum_variant_matcharm() { |
1182 | assert_debug_snapshot!( | 560 | check( |
1183 | do_reference_completion( | 561 | r#" |
1184 | r" | 562 | enum Foo { Bar, Baz, Quux } |
1185 | enum Foo { | ||
1186 | Bar, | ||
1187 | Baz, | ||
1188 | Quux | ||
1189 | } | ||
1190 | |||
1191 | fn main() { | ||
1192 | let foo = Foo::Quux; | ||
1193 | 563 | ||
1194 | match foo { | 564 | fn main() { |
1195 | Qu<|> | 565 | let foo = Foo::Quux; |
1196 | } | 566 | match foo { Qu<|> } |
1197 | } | 567 | } |
1198 | " | 568 | "#, |
1199 | ), | 569 | expect![[r#" |
1200 | @r###" | 570 | en Foo |
1201 | [ | 571 | ev Foo::Bar () |
1202 | CompletionItem { | 572 | ev Foo::Baz () |
1203 | label: "Foo", | 573 | ev Foo::Quux () |
1204 | source_range: 103..105, | 574 | "#]], |
1205 | delete: 103..105, | ||
1206 | insert: "Foo", | ||
1207 | kind: Enum, | ||
1208 | }, | ||
1209 | CompletionItem { | ||
1210 | label: "Foo::Bar", | ||
1211 | source_range: 103..105, | ||
1212 | delete: 103..105, | ||
1213 | insert: "Foo::Bar", | ||
1214 | kind: EnumVariant, | ||
1215 | lookup: "Bar", | ||
1216 | detail: "()", | ||
1217 | }, | ||
1218 | CompletionItem { | ||
1219 | label: "Foo::Baz", | ||
1220 | source_range: 103..105, | ||
1221 | delete: 103..105, | ||
1222 | insert: "Foo::Baz", | ||
1223 | kind: EnumVariant, | ||
1224 | lookup: "Baz", | ||
1225 | detail: "()", | ||
1226 | }, | ||
1227 | CompletionItem { | ||
1228 | label: "Foo::Quux", | ||
1229 | source_range: 103..105, | ||
1230 | delete: 103..105, | ||
1231 | insert: "Foo::Quux", | ||
1232 | kind: EnumVariant, | ||
1233 | lookup: "Quux", | ||
1234 | detail: "()", | ||
1235 | }, | ||
1236 | ] | ||
1237 | "### | ||
1238 | ) | 575 | ) |
1239 | } | 576 | } |
1240 | 577 | ||
1241 | #[test] | 578 | #[test] |
1242 | fn completes_enum_variant_iflet() { | 579 | fn completes_enum_variant_iflet() { |
1243 | assert_debug_snapshot!( | 580 | check( |
1244 | do_reference_completion( | 581 | r#" |
1245 | r" | 582 | enum Foo { Bar, Baz, Quux } |
1246 | enum Foo { | ||
1247 | Bar, | ||
1248 | Baz, | ||
1249 | Quux | ||
1250 | } | ||
1251 | 583 | ||
1252 | fn main() { | 584 | fn main() { |
1253 | let foo = Foo::Quux; | 585 | let foo = Foo::Quux; |
1254 | 586 | if let Qu<|> = foo { } | |
1255 | if let Qu<|> = foo { | 587 | } |
1256 | 588 | "#, | |
1257 | } | 589 | expect![[r#" |
1258 | } | 590 | en Foo |
1259 | " | 591 | ev Foo::Bar () |
1260 | ), | 592 | ev Foo::Baz () |
1261 | @r###" | 593 | ev Foo::Quux () |
1262 | [ | 594 | "#]], |
1263 | CompletionItem { | ||
1264 | label: "Foo", | ||
1265 | source_range: 90..92, | ||
1266 | delete: 90..92, | ||
1267 | insert: "Foo", | ||
1268 | kind: Enum, | ||
1269 | }, | ||
1270 | CompletionItem { | ||
1271 | label: "Foo::Bar", | ||
1272 | source_range: 90..92, | ||
1273 | delete: 90..92, | ||
1274 | insert: "Foo::Bar", | ||
1275 | kind: EnumVariant, | ||
1276 | lookup: "Bar", | ||
1277 | detail: "()", | ||
1278 | }, | ||
1279 | CompletionItem { | ||
1280 | label: "Foo::Baz", | ||
1281 | source_range: 90..92, | ||
1282 | delete: 90..92, | ||
1283 | insert: "Foo::Baz", | ||
1284 | kind: EnumVariant, | ||
1285 | lookup: "Baz", | ||
1286 | detail: "()", | ||
1287 | }, | ||
1288 | CompletionItem { | ||
1289 | label: "Foo::Quux", | ||
1290 | source_range: 90..92, | ||
1291 | delete: 90..92, | ||
1292 | insert: "Foo::Quux", | ||
1293 | kind: EnumVariant, | ||
1294 | lookup: "Quux", | ||
1295 | detail: "()", | ||
1296 | }, | ||
1297 | ] | ||
1298 | "### | ||
1299 | ) | 595 | ) |
1300 | } | 596 | } |
1301 | 597 | ||
1302 | #[test] | 598 | #[test] |
1303 | fn completes_enum_variant_basic_expr() { | 599 | fn completes_enum_variant_basic_expr() { |
1304 | assert_debug_snapshot!( | 600 | check( |
1305 | do_reference_completion( | 601 | r#" |
1306 | r" | 602 | enum Foo { Bar, Baz, Quux } |
1307 | enum Foo { | 603 | fn main() { let foo: Foo = Q<|> } |
1308 | Bar, | 604 | "#, |
1309 | Baz, | 605 | expect![[r#" |
1310 | Quux | 606 | en Foo |
1311 | } | 607 | ev Foo::Bar () |
1312 | 608 | ev Foo::Baz () | |
1313 | fn main() { | 609 | ev Foo::Quux () |
1314 | let foo: Foo = Q<|> | 610 | fn main() fn main() |
1315 | } | 611 | "#]], |
1316 | " | ||
1317 | ), | ||
1318 | @r###" | ||
1319 | [ | ||
1320 | CompletionItem { | ||
1321 | label: "Foo", | ||
1322 | source_range: 72..73, | ||
1323 | delete: 72..73, | ||
1324 | insert: "Foo", | ||
1325 | kind: Enum, | ||
1326 | }, | ||
1327 | CompletionItem { | ||
1328 | label: "Foo::Bar", | ||
1329 | source_range: 72..73, | ||
1330 | delete: 72..73, | ||
1331 | insert: "Foo::Bar", | ||
1332 | kind: EnumVariant, | ||
1333 | lookup: "Bar", | ||
1334 | detail: "()", | ||
1335 | }, | ||
1336 | CompletionItem { | ||
1337 | label: "Foo::Baz", | ||
1338 | source_range: 72..73, | ||
1339 | delete: 72..73, | ||
1340 | insert: "Foo::Baz", | ||
1341 | kind: EnumVariant, | ||
1342 | lookup: "Baz", | ||
1343 | detail: "()", | ||
1344 | }, | ||
1345 | CompletionItem { | ||
1346 | label: "Foo::Quux", | ||
1347 | source_range: 72..73, | ||
1348 | delete: 72..73, | ||
1349 | insert: "Foo::Quux", | ||
1350 | kind: EnumVariant, | ||
1351 | lookup: "Quux", | ||
1352 | detail: "()", | ||
1353 | }, | ||
1354 | CompletionItem { | ||
1355 | label: "main()", | ||
1356 | source_range: 72..73, | ||
1357 | delete: 72..73, | ||
1358 | insert: "main()$0", | ||
1359 | kind: Function, | ||
1360 | lookup: "main", | ||
1361 | detail: "fn main()", | ||
1362 | }, | ||
1363 | ] | ||
1364 | "### | ||
1365 | ) | 612 | ) |
1366 | } | 613 | } |
1367 | 614 | ||
1368 | #[test] | 615 | #[test] |
1369 | fn completes_enum_variant_from_module() { | 616 | fn completes_enum_variant_from_module() { |
1370 | assert_debug_snapshot!( | 617 | check( |
1371 | do_reference_completion( | 618 | r#" |
1372 | r" | 619 | mod m { pub enum E { V } } |
1373 | mod m { pub enum E { V } } | 620 | fn f() -> m::E { V<|> } |
1374 | 621 | "#, | |
1375 | fn f() -> m::E { | 622 | expect![[r#" |
1376 | V<|> | 623 | fn f() fn f() -> m::E |
1377 | } | 624 | md m |
1378 | " | 625 | ev m::E::V () |
1379 | ), | 626 | "#]], |
1380 | @r###" | ||
1381 | [ | ||
1382 | CompletionItem { | ||
1383 | label: "f()", | ||
1384 | source_range: 49..50, | ||
1385 | delete: 49..50, | ||
1386 | insert: "f()$0", | ||
1387 | kind: Function, | ||
1388 | lookup: "f", | ||
1389 | detail: "fn f() -> m::E", | ||
1390 | }, | ||
1391 | CompletionItem { | ||
1392 | label: "m", | ||
1393 | source_range: 49..50, | ||
1394 | delete: 49..50, | ||
1395 | insert: "m", | ||
1396 | kind: Module, | ||
1397 | }, | ||
1398 | CompletionItem { | ||
1399 | label: "m::E::V", | ||
1400 | source_range: 49..50, | ||
1401 | delete: 49..50, | ||
1402 | insert: "m::E::V", | ||
1403 | kind: EnumVariant, | ||
1404 | lookup: "V", | ||
1405 | detail: "()", | ||
1406 | }, | ||
1407 | ] | ||
1408 | "### | ||
1409 | ) | 627 | ) |
1410 | } | 628 | } |
1411 | 629 | ||
1412 | #[test] | 630 | #[test] |
1413 | fn dont_complete_attr() { | 631 | fn dont_complete_attr() { |
1414 | assert_debug_snapshot!( | 632 | check( |
1415 | do_reference_completion( | 633 | r#" |
1416 | r" | 634 | struct Foo; |
1417 | struct Foo; | 635 | #[<|>] |
1418 | #[<|>] | 636 | fn f() {} |
1419 | fn f() {} | 637 | "#, |
1420 | " | 638 | expect![[""]], |
1421 | ), | 639 | ) |
1422 | @r###"[]"### | 640 | } |
641 | |||
642 | #[test] | ||
643 | fn completes_type_or_trait_in_impl_block() { | ||
644 | check( | ||
645 | r#" | ||
646 | trait MyTrait {} | ||
647 | struct MyStruct {} | ||
648 | |||
649 | impl My<|> | ||
650 | "#, | ||
651 | expect![[r#" | ||
652 | st MyStruct | ||
653 | tt MyTrait | ||
654 | tp Self | ||
655 | "#]], | ||
1423 | ) | 656 | ) |
1424 | } | 657 | } |
1425 | } | 658 | } |