diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_scope.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_scope.rs | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 1baa5227a..07c2e5f94 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs | |||
@@ -122,7 +122,7 @@ impl ImportResolver { | |||
122 | #[cfg(test)] | 122 | #[cfg(test)] |
123 | mod tests { | 123 | mod tests { |
124 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 124 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; |
125 | use insta::assert_debug_snapshot_matches; | 125 | use insta::assert_debug_snapshot_matches; |
126 | 126 | ||
127 | fn do_reference_completion(code: &str) -> Vec<CompletionItem> { | 127 | fn do_reference_completion(code: &str) -> Vec<CompletionItem> { |
128 | do_completion(code, CompletionKind::Reference) | 128 | do_completion(code, CompletionKind::Reference) |
@@ -131,16 +131,16 @@ mod tests { | |||
131 | #[test] | 131 | #[test] |
132 | fn completes_bindings_from_let() { | 132 | fn completes_bindings_from_let() { |
133 | assert_debug_snapshot_matches!( | 133 | assert_debug_snapshot_matches!( |
134 | do_reference_completion( | 134 | do_reference_completion( |
135 | r" | 135 | r" |
136 | fn quux(x: i32) { | 136 | fn quux(x: i32) { |
137 | let y = 92; | 137 | let y = 92; |
138 | 1 + <|>; | 138 | 1 + <|>; |
139 | let z = (); | 139 | let z = (); |
140 | } | 140 | } |
141 | " | 141 | " |
142 | ), | 142 | ), |
143 | @r###" | 143 | @r###" |
144 | ⋮[ | 144 | ⋮[ |
145 | ⋮ CompletionItem { | 145 | ⋮ CompletionItem { |
146 | ⋮ label: "quux", | 146 | ⋮ label: "quux", |
@@ -168,14 +168,14 @@ mod tests { | |||
168 | ⋮ }, | 168 | ⋮ }, |
169 | ⋮] | 169 | ⋮] |
170 | "### | 170 | "### |
171 | ); | 171 | ); |
172 | } | 172 | } |
173 | 173 | ||
174 | #[test] | 174 | #[test] |
175 | fn completes_bindings_from_if_let() { | 175 | fn completes_bindings_from_if_let() { |
176 | assert_debug_snapshot_matches!( | 176 | assert_debug_snapshot_matches!( |
177 | do_reference_completion( | 177 | do_reference_completion( |
178 | r" | 178 | r" |
179 | fn quux() { | 179 | fn quux() { |
180 | if let Some(x) = foo() { | 180 | if let Some(x) = foo() { |
181 | let y = 92; | 181 | let y = 92; |
@@ -186,8 +186,8 @@ mod tests { | |||
186 | } | 186 | } |
187 | } | 187 | } |
188 | " | 188 | " |
189 | ), | 189 | ), |
190 | @r###" | 190 | @r###" |
191 | ⋮[ | 191 | ⋮[ |
192 | ⋮ CompletionItem { | 192 | ⋮ CompletionItem { |
193 | ⋮ label: "a", | 193 | ⋮ label: "a", |
@@ -214,22 +214,22 @@ mod tests { | |||
214 | ⋮ }, | 214 | ⋮ }, |
215 | ⋮] | 215 | ⋮] |
216 | "### | 216 | "### |
217 | ); | 217 | ); |
218 | } | 218 | } |
219 | 219 | ||
220 | #[test] | 220 | #[test] |
221 | fn completes_bindings_from_for() { | 221 | fn completes_bindings_from_for() { |
222 | assert_debug_snapshot_matches!( | 222 | assert_debug_snapshot_matches!( |
223 | do_reference_completion( | 223 | do_reference_completion( |
224 | r" | 224 | r" |
225 | fn quux() { | 225 | fn quux() { |
226 | for x in &[1, 2, 3] { | 226 | for x in &[1, 2, 3] { |
227 | <|> | 227 | <|> |
228 | } | 228 | } |
229 | } | 229 | } |
230 | " | 230 | " |
231 | ), | 231 | ), |
232 | @r###" | 232 | @r###" |
233 | ⋮[ | 233 | ⋮[ |
234 | ⋮ CompletionItem { | 234 | ⋮ CompletionItem { |
235 | ⋮ label: "quux", | 235 | ⋮ label: "quux", |
@@ -248,20 +248,20 @@ mod tests { | |||
248 | ⋮ }, | 248 | ⋮ }, |
249 | ⋮] | 249 | ⋮] |
250 | "### | 250 | "### |
251 | ); | 251 | ); |
252 | } | 252 | } |
253 | 253 | ||
254 | #[test] | 254 | #[test] |
255 | fn completes_generic_params() { | 255 | fn completes_generic_params() { |
256 | assert_debug_snapshot_matches!( | 256 | assert_debug_snapshot_matches!( |
257 | do_reference_completion( | 257 | do_reference_completion( |
258 | r" | 258 | r" |
259 | fn quux<T>() { | 259 | fn quux<T>() { |
260 | <|> | 260 | <|> |
261 | } | 261 | } |
262 | " | 262 | " |
263 | ), | 263 | ), |
264 | @r###" | 264 | @r###" |
265 | ⋮[ | 265 | ⋮[ |
266 | ⋮ CompletionItem { | 266 | ⋮ CompletionItem { |
267 | ⋮ label: "T", | 267 | ⋮ label: "T", |
@@ -280,20 +280,20 @@ mod tests { | |||
280 | ⋮ }, | 280 | ⋮ }, |
281 | ⋮] | 281 | ⋮] |
282 | "### | 282 | "### |
283 | ); | 283 | ); |
284 | } | 284 | } |
285 | 285 | ||
286 | #[test] | 286 | #[test] |
287 | fn completes_generic_params_in_struct() { | 287 | fn completes_generic_params_in_struct() { |
288 | assert_debug_snapshot_matches!( | 288 | assert_debug_snapshot_matches!( |
289 | do_reference_completion( | 289 | do_reference_completion( |
290 | r" | 290 | r" |
291 | struct X<T> { | 291 | struct X<T> { |
292 | x: <|> | 292 | x: <|> |
293 | } | 293 | } |
294 | " | 294 | " |
295 | ), | 295 | ), |
296 | @r###" | 296 | @r###" |
297 | ⋮[ | 297 | ⋮[ |
298 | ⋮ CompletionItem { | 298 | ⋮ CompletionItem { |
299 | ⋮ label: "T", | 299 | ⋮ label: "T", |
@@ -311,22 +311,22 @@ mod tests { | |||
311 | ⋮ }, | 311 | ⋮ }, |
312 | ⋮] | 312 | ⋮] |
313 | "### | 313 | "### |
314 | ); | 314 | ); |
315 | } | 315 | } |
316 | 316 | ||
317 | #[test] | 317 | #[test] |
318 | fn completes_module_items() { | 318 | fn completes_module_items() { |
319 | assert_debug_snapshot_matches!( | 319 | assert_debug_snapshot_matches!( |
320 | do_reference_completion( | 320 | do_reference_completion( |
321 | r" | 321 | r" |
322 | struct Foo; | 322 | struct Foo; |
323 | enum Baz {} | 323 | enum Baz {} |
324 | fn quux() { | 324 | fn quux() { |
325 | <|> | 325 | <|> |
326 | } | 326 | } |
327 | " | 327 | " |
328 | ), | 328 | ), |
329 | @r###" | 329 | @r###" |
330 | ⋮[ | 330 | ⋮[ |
331 | ⋮ CompletionItem { | 331 | ⋮ CompletionItem { |
332 | ⋮ label: "Baz", | 332 | ⋮ label: "Baz", |
@@ -352,22 +352,22 @@ mod tests { | |||
352 | ⋮ }, | 352 | ⋮ }, |
353 | ⋮] | 353 | ⋮] |
354 | "### | 354 | "### |
355 | ); | 355 | ); |
356 | } | 356 | } |
357 | 357 | ||
358 | #[test] | 358 | #[test] |
359 | fn completes_extern_prelude() { | 359 | fn completes_extern_prelude() { |
360 | assert_debug_snapshot_matches!( | 360 | assert_debug_snapshot_matches!( |
361 | do_reference_completion( | 361 | do_reference_completion( |
362 | r" | 362 | r" |
363 | //- /lib.rs | 363 | //- /lib.rs |
364 | use <|>; | 364 | use <|>; |
365 | 365 | ||
366 | //- /other_crate/lib.rs | 366 | //- /other_crate/lib.rs |
367 | // nothing here | 367 | // nothing here |
368 | " | 368 | " |
369 | ), | 369 | ), |
370 | @r#"[ | 370 | @r#"[ |
371 | CompletionItem { | 371 | CompletionItem { |
372 | label: "other_crate", | 372 | label: "other_crate", |
373 | source_range: [4; 4), | 373 | source_range: [4; 4), |
@@ -376,22 +376,22 @@ mod tests { | |||
376 | kind: Module, | 376 | kind: Module, |
377 | }, | 377 | }, |
378 | ]"# | 378 | ]"# |
379 | ); | 379 | ); |
380 | } | 380 | } |
381 | 381 | ||
382 | #[test] | 382 | #[test] |
383 | fn completes_module_items_in_nested_modules() { | 383 | fn completes_module_items_in_nested_modules() { |
384 | assert_debug_snapshot_matches!( | 384 | assert_debug_snapshot_matches!( |
385 | do_reference_completion( | 385 | do_reference_completion( |
386 | r" | 386 | r" |
387 | struct Foo; | 387 | struct Foo; |
388 | mod m { | 388 | mod m { |
389 | struct Bar; | 389 | struct Bar; |
390 | fn quux() { <|> } | 390 | fn quux() { <|> } |
391 | } | 391 | } |
392 | " | 392 | " |
393 | ), | 393 | ), |
394 | @r###" | 394 | @r###" |
395 | ⋮[ | 395 | ⋮[ |
396 | ⋮ CompletionItem { | 396 | ⋮ CompletionItem { |
397 | ⋮ label: "Bar", | 397 | ⋮ label: "Bar", |
@@ -410,19 +410,19 @@ mod tests { | |||
410 | ⋮ }, | 410 | ⋮ }, |
411 | ⋮] | 411 | ⋮] |
412 | "### | 412 | "### |
413 | ); | 413 | ); |
414 | } | 414 | } |
415 | 415 | ||
416 | #[test] | 416 | #[test] |
417 | fn completes_return_type() { | 417 | fn completes_return_type() { |
418 | assert_debug_snapshot_matches!( | 418 | assert_debug_snapshot_matches!( |
419 | do_reference_completion( | 419 | do_reference_completion( |
420 | r" | 420 | r" |
421 | struct Foo; | 421 | struct Foo; |
422 | fn x() -> <|> | 422 | fn x() -> <|> |
423 | " | 423 | " |
424 | ), | 424 | ), |
425 | @r###" | 425 | @r###" |
426 | ⋮[ | 426 | ⋮[ |
427 | ⋮ CompletionItem { | 427 | ⋮ CompletionItem { |
428 | ⋮ label: "Foo", | 428 | ⋮ label: "Foo", |
@@ -441,14 +441,14 @@ mod tests { | |||
441 | ⋮ }, | 441 | ⋮ }, |
442 | ⋮] | 442 | ⋮] |
443 | "### | 443 | "### |
444 | ); | 444 | ); |
445 | } | 445 | } |
446 | 446 | ||
447 | #[test] | 447 | #[test] |
448 | fn dont_show_both_completions_for_shadowing() { | 448 | fn dont_show_both_completions_for_shadowing() { |
449 | assert_debug_snapshot_matches!( | 449 | assert_debug_snapshot_matches!( |
450 | do_reference_completion( | 450 | do_reference_completion( |
451 | r" | 451 | r" |
452 | fn foo() { | 452 | fn foo() { |
453 | let bar = 92; | 453 | let bar = 92; |
454 | { | 454 | { |
@@ -457,8 +457,8 @@ mod tests { | |||
457 | } | 457 | } |
458 | } | 458 | } |
459 | " | 459 | " |
460 | ), | 460 | ), |
461 | @r###" | 461 | @r###" |
462 | ⋮[ | 462 | ⋮[ |
463 | ⋮ CompletionItem { | 463 | ⋮ CompletionItem { |
464 | ⋮ label: "bar", | 464 | ⋮ label: "bar", |
@@ -478,14 +478,14 @@ mod tests { | |||
478 | ⋮ }, | 478 | ⋮ }, |
479 | ⋮] | 479 | ⋮] |
480 | "### | 480 | "### |
481 | ); | 481 | ); |
482 | } | 482 | } |
483 | 483 | ||
484 | #[test] | 484 | #[test] |
485 | fn completes_self_in_methods() { | 485 | fn completes_self_in_methods() { |
486 | assert_debug_snapshot_matches!( | 486 | assert_debug_snapshot_matches!( |
487 | do_reference_completion(r"impl S { fn foo(&self) { <|> } }"), | 487 | do_reference_completion(r"impl S { fn foo(&self) { <|> } }"), |
488 | @r#"[ | 488 | @r#"[ |
489 | CompletionItem { | 489 | CompletionItem { |
490 | label: "Self", | 490 | label: "Self", |
491 | source_range: [25; 25), | 491 | source_range: [25; 25), |
@@ -502,14 +502,14 @@ mod tests { | |||
502 | detail: "&{unknown}", | 502 | detail: "&{unknown}", |
503 | }, | 503 | }, |
504 | ]"# | 504 | ]"# |
505 | ); | 505 | ); |
506 | } | 506 | } |
507 | 507 | ||
508 | #[test] | 508 | #[test] |
509 | fn completes_prelude() { | 509 | fn completes_prelude() { |
510 | assert_debug_snapshot_matches!( | 510 | assert_debug_snapshot_matches!( |
511 | do_reference_completion( | 511 | do_reference_completion( |
512 | " | 512 | " |
513 | //- /main.rs | 513 | //- /main.rs |
514 | fn foo() { let x: <|> } | 514 | fn foo() { let x: <|> } |
515 | 515 | ||
@@ -521,8 +521,8 @@ mod tests { | |||
521 | struct Option; | 521 | struct Option; |
522 | } | 522 | } |
523 | " | 523 | " |
524 | ), | 524 | ), |
525 | @r#"[ | 525 | @r#"[ |
526 | CompletionItem { | 526 | CompletionItem { |
527 | label: "Option", | 527 | label: "Option", |
528 | source_range: [18; 18), | 528 | source_range: [18; 18), |
@@ -546,6 +546,6 @@ mod tests { | |||
546 | kind: Module, | 546 | kind: Module, |
547 | }, | 547 | }, |
548 | ]"# | 548 | ]"# |
549 | ); | 549 | ); |
550 | } | 550 | } |
551 | } | 551 | } |