diff options
Diffstat (limited to 'crates/ide_completion/src/completions/qualified_path.rs')
-rw-r--r-- | crates/ide_completion/src/completions/qualified_path.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index c16bb215f..7a0e1ead3 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs | |||
@@ -7,7 +7,7 @@ use syntax::AstNode; | |||
7 | use crate::{CompletionContext, Completions}; | 7 | use crate::{CompletionContext, Completions}; |
8 | 8 | ||
9 | pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionContext) { | 9 | pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionContext) { |
10 | if ctx.is_path_disallowed() { | 10 | if ctx.is_path_disallowed() || ctx.expects_item() { |
11 | return; | 11 | return; |
12 | } | 12 | } |
13 | let path = match &ctx.path_qual { | 13 | let path = match &ctx.path_qual { |
@@ -20,13 +20,16 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon | |||
20 | None => return, | 20 | None => return, |
21 | }; | 21 | }; |
22 | let context_module = ctx.scope.module(); | 22 | let context_module = ctx.scope.module(); |
23 | if ctx.expects_item() || ctx.expects_assoc_item() { | 23 | if ctx.expects_assoc_item() { |
24 | if let PathResolution::Def(hir::ModuleDef::Module(module)) = resolution { | 24 | if let PathResolution::Def(hir::ModuleDef::Module(module)) = resolution { |
25 | let module_scope = module.scope(ctx.db, context_module); | 25 | let module_scope = module.scope(ctx.db, context_module); |
26 | for (name, def) in module_scope { | 26 | for (name, def) in module_scope { |
27 | if let ScopeDef::MacroDef(macro_def) = def { | 27 | if let ScopeDef::MacroDef(macro_def) = def { |
28 | acc.add_macro(ctx, Some(name.to_string()), macro_def); | 28 | acc.add_macro(ctx, Some(name.to_string()), macro_def); |
29 | } | 29 | } |
30 | if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { | ||
31 | acc.add_resolution(ctx, name.to_string(), &def); | ||
32 | } | ||
30 | } | 33 | } |
31 | } | 34 | } |
32 | return; | 35 | return; |
@@ -614,25 +617,44 @@ fn main() { let _ = crate::$0 } | |||
614 | } | 617 | } |
615 | 618 | ||
616 | #[test] | 619 | #[test] |
617 | fn completes_qualified_macros_in_impl() { | 620 | fn completes_in_assoc_item_list() { |
618 | check( | 621 | check( |
619 | r#" | 622 | r#" |
620 | #[macro_export] | 623 | #[macro_export] |
621 | macro_rules! foo { () => {} } | 624 | macro_rules! foo { () => {} } |
625 | mod bar {} | ||
622 | 626 | ||
623 | struct MyStruct {} | 627 | struct MyStruct {} |
624 | |||
625 | impl MyStruct { | 628 | impl MyStruct { |
626 | crate::$0 | 629 | crate::$0 |
627 | } | 630 | } |
628 | "#, | 631 | "#, |
629 | expect![[r##" | 632 | expect![[r##" |
633 | md bar | ||
630 | ma foo! #[macro_export] macro_rules! foo | 634 | ma foo! #[macro_export] macro_rules! foo |
631 | "##]], | 635 | "##]], |
632 | ); | 636 | ); |
633 | } | 637 | } |
634 | 638 | ||
635 | #[test] | 639 | #[test] |
640 | #[ignore] // FIXME doesn't complete anything atm | ||
641 | fn completes_in_item_list() { | ||
642 | check( | ||
643 | r#" | ||
644 | struct MyStruct {} | ||
645 | macro_rules! foo {} | ||
646 | mod bar {} | ||
647 | |||
648 | crate::$0 | ||
649 | "#, | ||
650 | expect![[r#" | ||
651 | md bar | ||
652 | ma foo! macro_rules! foo | ||
653 | "#]], | ||
654 | ) | ||
655 | } | ||
656 | |||
657 | #[test] | ||
636 | fn test_super_super_completion() { | 658 | fn test_super_super_completion() { |
637 | check( | 659 | check( |
638 | r#" | 660 | r#" |