diff options
author | Lukas Wirth <[email protected]> | 2021-05-27 03:34:21 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-05-27 11:23:36 +0100 |
commit | f41c98342476087d0a4387e7d337ce2d897e0346 (patch) | |
tree | 1c9b8e9f5a3d26d921337f6f20501b38de6fcb94 /crates/ide_completion/src/completions/unqualified_path.rs | |
parent | 30948e1ecb2fb4fe35bf9c5c1e49464d4ea1d064 (diff) |
Don't complete non-macro item paths in impls and modules
Diffstat (limited to 'crates/ide_completion/src/completions/unqualified_path.rs')
-rw-r--r-- | crates/ide_completion/src/completions/unqualified_path.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index 046a393ae..cbac88240 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs | |||
@@ -12,6 +12,14 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
12 | if ctx.is_path_disallowed() { | 12 | if ctx.is_path_disallowed() { |
13 | return; | 13 | return; |
14 | } | 14 | } |
15 | if ctx.expects_item() || ctx.expects_assoc_item() { | ||
16 | ctx.scope.process_all_names(&mut |name, def| { | ||
17 | if let ScopeDef::MacroDef(macro_def) = def { | ||
18 | acc.add_macro(ctx, Some(name.to_string()), macro_def); | ||
19 | } | ||
20 | }); | ||
21 | return; | ||
22 | } | ||
15 | 23 | ||
16 | if let Some(hir::Adt::Enum(e)) = | 24 | if let Some(hir::Adt::Enum(e)) = |
17 | ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) | 25 | ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) |
@@ -647,7 +655,7 @@ fn f() {} | |||
647 | } | 655 | } |
648 | 656 | ||
649 | #[test] | 657 | #[test] |
650 | fn completes_type_or_trait_in_impl_block() { | 658 | fn completes_target_type_or_trait_in_impl_block() { |
651 | check( | 659 | check( |
652 | r#" | 660 | r#" |
653 | trait MyTrait {} | 661 | trait MyTrait {} |
@@ -662,4 +670,21 @@ impl My$0 | |||
662 | "#]], | 670 | "#]], |
663 | ) | 671 | ) |
664 | } | 672 | } |
673 | |||
674 | #[test] | ||
675 | fn only_completes_macros_in_assoc_item_list() { | ||
676 | check( | ||
677 | r#" | ||
678 | struct MyStruct {} | ||
679 | macro_rules! foo {} | ||
680 | |||
681 | impl MyStruct { | ||
682 | $0 | ||
683 | } | ||
684 | "#, | ||
685 | expect![[r#" | ||
686 | ma foo! macro_rules! foo | ||
687 | "#]], | ||
688 | ) | ||
689 | } | ||
665 | } | 690 | } |