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.rs76
1 files changed, 70 insertions, 6 deletions
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs
index 8b22933e0..1f6c4069f 100644
--- a/crates/ide_completion/src/completions/unqualified_path.rs
+++ b/crates/ide_completion/src/completions/unqualified_path.rs
@@ -13,7 +13,9 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
13 // only show macros in {Assoc}ItemList 13 // only show macros in {Assoc}ItemList
14 ctx.scope.process_all_names(&mut |name, res| { 14 ctx.scope.process_all_names(&mut |name, res| {
15 if let hir::ScopeDef::MacroDef(mac) = res { 15 if let hir::ScopeDef::MacroDef(mac) = res {
16 acc.add_macro(ctx, Some(name.clone()), mac); 16 if mac.is_fn_like() {
17 acc.add_macro(ctx, Some(name.clone()), mac);
18 }
17 } 19 }
18 if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { 20 if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res {
19 acc.add_resolution(ctx, name, &res); 21 acc.add_resolution(ctx, name, &res);
@@ -46,7 +48,13 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
46 cov_mark::hit!(skip_lifetime_completion); 48 cov_mark::hit!(skip_lifetime_completion);
47 return; 49 return;
48 } 50 }
49 acc.add_resolution(ctx, name, &res); 51 let add_resolution = match res {
52 ScopeDef::MacroDef(mac) => mac.is_fn_like(),
53 _ => true,
54 };
55 if add_resolution {
56 acc.add_resolution(ctx, name, &res);
57 }
50 }); 58 });
51} 59}
52 60
@@ -69,6 +77,28 @@ mod tests {
69 } 77 }
70 78
71 #[test] 79 #[test]
80 fn dont_complete_values_in_type_pos() {
81 check(
82 r#"
83const FOO: () = ();
84static BAR: () = ();
85enum Foo {
86 Bar
87}
88struct Baz;
89fn foo() {
90 let local = ();
91 let _: $0;
92}
93"#,
94 expect![[r#"
95 en Foo
96 st Baz
97 "#]],
98 );
99 }
100
101 #[test]
72 fn only_completes_modules_in_import() { 102 fn only_completes_modules_in_import() {
73 cov_mark::check!(only_completes_modules_in_import); 103 cov_mark::check!(only_completes_modules_in_import);
74 check( 104 check(
@@ -339,7 +369,6 @@ fn x() -> $0
339"#, 369"#,
340 expect![[r#" 370 expect![[r#"
341 st Foo 371 st Foo
342 fn x() fn()
343 "#]], 372 "#]],
344 ); 373 );
345 } 374 }
@@ -391,7 +420,6 @@ pub mod prelude {
391} 420}
392"#, 421"#,
393 expect![[r#" 422 expect![[r#"
394 fn foo() fn()
395 md std 423 md std
396 st Option 424 st Option
397 "#]], 425 "#]],
@@ -427,6 +455,44 @@ mod macros {
427 } 455 }
428 456
429 #[test] 457 #[test]
458 fn does_not_complete_non_fn_macros() {
459 check(
460 r#"
461#[rustc_builtin_macro]
462pub macro Clone {}
463
464fn f() {$0}
465"#,
466 expect![[r#"
467 fn f() fn()
468 "#]],
469 );
470 check(
471 r#"
472#[rustc_builtin_macro]
473pub macro Clone {}
474
475struct S;
476impl S {
477 $0
478}
479"#,
480 expect![[r#""#]],
481 );
482 check(
483 r#"
484mod m {
485 #[rustc_builtin_macro]
486 pub macro Clone {}
487}
488
489fn f() {m::$0}
490"#,
491 expect![[r#""#]],
492 );
493 }
494
495 #[test]
430 fn completes_std_prelude_if_core_is_defined() { 496 fn completes_std_prelude_if_core_is_defined() {
431 check( 497 check(
432 r#" 498 r#"
@@ -448,7 +514,6 @@ pub mod prelude {
448} 514}
449"#, 515"#,
450 expect![[r#" 516 expect![[r#"
451 fn foo() fn()
452 md std 517 md std
453 md core 518 md core
454 st String 519 st String
@@ -509,7 +574,6 @@ macro_rules! foo { () => {} }
509fn main() { let x: $0 } 574fn main() { let x: $0 }
510"#, 575"#,
511 expect![[r#" 576 expect![[r#"
512 fn main() fn()
513 ma foo!(…) macro_rules! foo 577 ma foo!(…) macro_rules! foo
514 "#]], 578 "#]],
515 ); 579 );