diff options
Diffstat (limited to 'crates/ide_completion/src/completions/unqualified_path.rs')
-rw-r--r-- | crates/ide_completion/src/completions/unqualified_path.rs | 50 |
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 8b22933e0..52f40d496 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 | ||
@@ -427,6 +435,44 @@ mod macros { | |||
427 | } | 435 | } |
428 | 436 | ||
429 | #[test] | 437 | #[test] |
438 | fn does_not_complete_non_fn_macros() { | ||
439 | check( | ||
440 | r#" | ||
441 | #[rustc_builtin_macro] | ||
442 | pub macro Clone {} | ||
443 | |||
444 | fn f() {$0} | ||
445 | "#, | ||
446 | expect![[r#" | ||
447 | fn f() fn() | ||
448 | "#]], | ||
449 | ); | ||
450 | check( | ||
451 | r#" | ||
452 | #[rustc_builtin_macro] | ||
453 | pub macro Clone {} | ||
454 | |||
455 | struct S; | ||
456 | impl S { | ||
457 | $0 | ||
458 | } | ||
459 | "#, | ||
460 | expect![[r#""#]], | ||
461 | ); | ||
462 | check( | ||
463 | r#" | ||
464 | mod m { | ||
465 | #[rustc_builtin_macro] | ||
466 | pub macro Clone {} | ||
467 | } | ||
468 | |||
469 | fn f() {m::$0} | ||
470 | "#, | ||
471 | expect![[r#""#]], | ||
472 | ); | ||
473 | } | ||
474 | |||
475 | #[test] | ||
430 | fn completes_std_prelude_if_core_is_defined() { | 476 | fn completes_std_prelude_if_core_is_defined() { |
431 | check( | 477 | check( |
432 | r#" | 478 | r#" |