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.rs50
1 files changed, 48 insertions, 2 deletions
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs
index 2105bb428..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
@@ -447,6 +455,44 @@ mod macros {
447 } 455 }
448 456
449 #[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]
450 fn completes_std_prelude_if_core_is_defined() { 496 fn completes_std_prelude_if_core_is_defined() {
451 check( 497 check(
452 r#" 498 r#"