aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/unqualified_path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/completions/unqualified_path.rs')
-rw-r--r--crates/ide_completion/src/completions/unqualified_path.rs138
1 files changed, 26 insertions, 112 deletions
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs
index 044dfd160..1b8b063e7 100644
--- a/crates/ide_completion/src/completions/unqualified_path.rs
+++ b/crates/ide_completion/src/completions/unqualified_path.rs
@@ -6,7 +6,7 @@ use syntax::AstNode;
6use crate::{CompletionContext, Completions}; 6use crate::{CompletionContext, Completions};
7 7
8pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { 8pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) {
9 if !(ctx.is_trivial_path || ctx.is_pat_binding_or_const) { 9 if !ctx.is_trivial_path {
10 return; 10 return;
11 } 11 }
12 if ctx.record_lit_syntax.is_some() 12 if ctx.record_lit_syntax.is_some()
@@ -23,10 +23,6 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
23 }); 23 });
24 } 24 }
25 25
26 if ctx.is_pat_binding_or_const {
27 return;
28 }
29
30 ctx.scope.process_all_names(&mut |name, res| { 26 ctx.scope.process_all_names(&mut |name, res| {
31 if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res { 27 if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res {
32 cov_mark::hit!(skip_lifetime_completion); 28 cov_mark::hit!(skip_lifetime_completion);
@@ -139,7 +135,7 @@ fn quux(x: i32) {
139 expect![[r#" 135 expect![[r#"
140 lc y i32 136 lc y i32
141 lc x i32 137 lc x i32
142 fn quux(…) -> () 138 fn quux(…) fn(i32)
143 "#]], 139 "#]],
144 ); 140 );
145 } 141 }
@@ -161,7 +157,7 @@ fn quux() {
161 expect![[r#" 157 expect![[r#"
162 lc b i32 158 lc b i32
163 lc a 159 lc a
164 fn quux() -> () 160 fn quux() fn()
165 "#]], 161 "#]],
166 ); 162 );
167 } 163 }
@@ -176,7 +172,7 @@ fn quux() {
176"#, 172"#,
177 expect![[r#" 173 expect![[r#"
178 lc x 174 lc x
179 fn quux() -> () 175 fn quux() fn()
180 "#]], 176 "#]],
181 ); 177 );
182 } 178 }
@@ -207,14 +203,14 @@ fn main() {
207 r#"fn quux<T>() { $0 }"#, 203 r#"fn quux<T>() { $0 }"#,
208 expect![[r#" 204 expect![[r#"
209 tp T 205 tp T
210 fn quux() -> () 206 fn quux() fn()
211 "#]], 207 "#]],
212 ); 208 );
213 check( 209 check(
214 r#"fn quux<const C: usize>() { $0 }"#, 210 r#"fn quux<const C: usize>() { $0 }"#,
215 expect![[r#" 211 expect![[r#"
216 cp C 212 cp C
217 fn quux() -> () 213 fn quux() fn()
218 "#]], 214 "#]],
219 ); 215 );
220 } 216 }
@@ -225,7 +221,7 @@ fn main() {
225 check( 221 check(
226 r#"fn quux<'a>() { $0 }"#, 222 r#"fn quux<'a>() { $0 }"#,
227 expect![[r#" 223 expect![[r#"
228 fn quux() -> () 224 fn quux() fn()
229 "#]], 225 "#]],
230 ); 226 );
231 } 227 }
@@ -263,7 +259,7 @@ fn quux() { $0 }
263"#, 259"#,
264 expect![[r#" 260 expect![[r#"
265 st S 261 st S
266 fn quux() -> () 262 fn quux() fn()
267 en E 263 en E
268 "#]], 264 "#]],
269 ); 265 );
@@ -316,7 +312,7 @@ mod m {
316} 312}
317"#, 313"#,
318 expect![[r#" 314 expect![[r#"
319 fn quux() -> () 315 fn quux() fn()
320 st Bar 316 st Bar
321 "#]], 317 "#]],
322 ); 318 );
@@ -331,7 +327,7 @@ fn x() -> $0
331"#, 327"#,
332 expect![[r#" 328 expect![[r#"
333 st Foo 329 st Foo
334 fn x() -> () 330 fn x() fn()
335 "#]], 331 "#]],
336 ); 332 );
337 } 333 }
@@ -352,7 +348,7 @@ fn foo() {
352 expect![[r#" 348 expect![[r#"
353 lc bar i32 349 lc bar i32
354 lc bar i32 350 lc bar i32
355 fn foo() -> () 351 fn foo() fn()
356 "#]], 352 "#]],
357 ); 353 );
358 } 354 }
@@ -382,7 +378,7 @@ use prelude::*;
382mod prelude { struct Option; } 378mod prelude { struct Option; }
383"#, 379"#,
384 expect![[r#" 380 expect![[r#"
385 fn foo() -> () 381 fn foo() fn()
386 md std 382 md std
387 st Option 383 st Option
388 "#]], 384 "#]],
@@ -412,7 +408,7 @@ mod macros {
412} 408}
413"#, 409"#,
414 expect![[r##" 410 expect![[r##"
415 fn f() -> () 411 fn f() fn()
416 ma concat!(…) #[macro_export] macro_rules! concat 412 ma concat!(…) #[macro_export] macro_rules! concat
417 md std 413 md std
418 "##]], 414 "##]],
@@ -439,7 +435,7 @@ use prelude::*;
439mod prelude { struct String; } 435mod prelude { struct String; }
440"#, 436"#,
441 expect![[r#" 437 expect![[r#"
442 fn foo() -> () 438 fn foo() fn()
443 md std 439 md std
444 md core 440 md core
445 st String 441 st String
@@ -470,7 +466,7 @@ fn main() { let v = $0 }
470 expect![[r##" 466 expect![[r##"
471 md m1 467 md m1
472 ma baz!(…) #[macro_export] macro_rules! baz 468 ma baz!(…) #[macro_export] macro_rules! baz
473 fn main() -> () 469 fn main() fn()
474 md m2 470 md m2
475 ma bar!(…) macro_rules! bar 471 ma bar!(…) macro_rules! bar
476 ma foo!(…) macro_rules! foo 472 ma foo!(…) macro_rules! foo
@@ -486,7 +482,7 @@ macro_rules! foo { () => {} }
486fn foo() { $0 } 482fn foo() { $0 }
487"#, 483"#,
488 expect![[r#" 484 expect![[r#"
489 fn foo() -> () 485 fn foo() fn()
490 ma foo!(…) macro_rules! foo 486 ma foo!(…) macro_rules! foo
491 "#]], 487 "#]],
492 ); 488 );
@@ -500,7 +496,7 @@ macro_rules! foo { () => {} }
500fn main() { let x: $0 } 496fn main() { let x: $0 }
501"#, 497"#,
502 expect![[r#" 498 expect![[r#"
503 fn main() -> () 499 fn main() fn()
504 ma foo!(…) macro_rules! foo 500 ma foo!(…) macro_rules! foo
505 "#]], 501 "#]],
506 ); 502 );
@@ -514,7 +510,7 @@ macro_rules! foo { () => {} }
514fn main() { $0 } 510fn main() { $0 }
515"#, 511"#,
516 expect![[r#" 512 expect![[r#"
517 fn main() -> () 513 fn main() fn()
518 ma foo!(…) macro_rules! foo 514 ma foo!(…) macro_rules! foo
519 "#]], 515 "#]],
520 ); 516 );
@@ -530,8 +526,8 @@ fn main() {
530} 526}
531"#, 527"#,
532 expect![[r#" 528 expect![[r#"
533 fn frobnicate() -> () 529 fn frobnicate() fn()
534 fn main() -> () 530 fn main() fn()
535 "#]], 531 "#]],
536 ); 532 );
537 } 533 }
@@ -549,7 +545,7 @@ fn quux(x: i32) {
549 expect![[r#" 545 expect![[r#"
550 lc y i32 546 lc y i32
551 lc x i32 547 lc x i32
552 fn quux(…) -> () 548 fn quux(…) fn(i32)
553 ma m!(…) macro_rules! m 549 ma m!(…) macro_rules! m
554 "#]], 550 "#]],
555 ); 551 );
@@ -568,7 +564,7 @@ fn quux(x: i32) {
568 expect![[r#" 564 expect![[r#"
569 lc y i32 565 lc y i32
570 lc x i32 566 lc x i32
571 fn quux(…) -> () 567 fn quux(…) fn(i32)
572 ma m!(…) macro_rules! m 568 ma m!(…) macro_rules! m
573 "#]], 569 "#]],
574 ); 570 );
@@ -587,7 +583,7 @@ fn quux(x: i32) {
587 expect![[r#" 583 expect![[r#"
588 lc y i32 584 lc y i32
589 lc x i32 585 lc x i32
590 fn quux(…) -> () 586 fn quux(…) fn(i32)
591 ma m!(…) macro_rules! m 587 ma m!(…) macro_rules! m
592 "#]], 588 "#]],
593 ); 589 );
@@ -602,73 +598,13 @@ use spam::Quux;
602fn main() { $0 } 598fn main() { $0 }
603"#, 599"#,
604 expect![[r#" 600 expect![[r#"
605 fn main() -> () 601 fn main() fn()
606 ?? Quux 602 ?? Quux
607 "#]], 603 "#]],
608 ); 604 );
609 } 605 }
610 606
611 #[test] 607 #[test]
612 fn completes_enum_variant_matcharm() {
613 check(
614 r#"
615enum Foo { Bar, Baz, Quux }
616
617fn main() {
618 let foo = Foo::Quux;
619 match foo { Qu$0 }
620}
621"#,
622 expect![[r#"
623 ev Foo::Bar ()
624 ev Foo::Baz ()
625 ev Foo::Quux ()
626 en Foo
627 "#]],
628 )
629 }
630
631 #[test]
632 fn completes_enum_variant_matcharm_ref() {
633 check(
634 r#"
635enum Foo { Bar, Baz, Quux }
636
637fn main() {
638 let foo = Foo::Quux;
639 match &foo { Qu$0 }
640}
641"#,
642 expect![[r#"
643 ev Foo::Bar ()
644 ev Foo::Baz ()
645 ev Foo::Quux ()
646 en Foo
647 "#]],
648 )
649 }
650
651 #[test]
652 fn completes_enum_variant_iflet() {
653 check(
654 r#"
655enum Foo { Bar, Baz, Quux }
656
657fn main() {
658 let foo = Foo::Quux;
659 if let Qu$0 = foo { }
660}
661"#,
662 expect![[r#"
663 ev Foo::Bar ()
664 ev Foo::Baz ()
665 ev Foo::Quux ()
666 en Foo
667 "#]],
668 )
669 }
670
671 #[test]
672 fn completes_enum_variant_basic_expr() { 608 fn completes_enum_variant_basic_expr() {
673 check( 609 check(
674 r#" 610 r#"
@@ -680,7 +616,7 @@ fn main() { let foo: Foo = Q$0 }
680 ev Foo::Baz () 616 ev Foo::Baz ()
681 ev Foo::Quux () 617 ev Foo::Quux ()
682 en Foo 618 en Foo
683 fn main() -> () 619 fn main() fn()
684 "#]], 620 "#]],
685 ) 621 )
686 } 622 }
@@ -695,29 +631,7 @@ fn f() -> m::E { V$0 }
695 expect![[r#" 631 expect![[r#"
696 ev m::E::V () 632 ev m::E::V ()
697 md m 633 md m
698 fn f() -> E 634 fn f() fn() -> E
699 "#]],
700 )
701 }
702
703 #[test]
704 fn completes_enum_variant_impl() {
705 check(
706 r#"
707enum Foo { Bar, Baz, Quux }
708impl Foo {
709 fn foo() { match Foo::Bar { Q$0 } }
710}
711"#,
712 expect![[r#"
713 ev Self::Bar ()
714 ev Self::Baz ()
715 ev Self::Quux ()
716 ev Foo::Bar ()
717 ev Foo::Baz ()
718 ev Foo::Quux ()
719 sp Self
720 en Foo
721 "#]], 635 "#]],
722 ) 636 )
723 } 637 }