aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/qualified_path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/completions/qualified_path.rs')
-rw-r--r--crates/ide_completion/src/completions/qualified_path.rs56
1 files changed, 54 insertions, 2 deletions
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs
index ed48f61af..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;
7use crate::{CompletionContext, Completions}; 7use crate::{CompletionContext, Completions};
8 8
9pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionContext) { 9pub(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,6 +20,20 @@ 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_assoc_item() {
24 if let PathResolution::Def(hir::ModuleDef::Module(module)) = resolution {
25 let module_scope = module.scope(ctx.db, context_module);
26 for (name, def) in module_scope {
27 if let ScopeDef::MacroDef(macro_def) = def {
28 acc.add_macro(ctx, Some(name.to_string()), macro_def);
29 }
30 if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
31 acc.add_resolution(ctx, name.to_string(), &def);
32 }
33 }
34 }
35 return;
36 }
23 37
24 // Add associated types on type parameters and `Self`. 38 // Add associated types on type parameters and `Self`.
25 resolution.assoc_type_shorthand_candidates(ctx.db, |_, alias| { 39 resolution.assoc_type_shorthand_candidates(ctx.db, |_, alias| {
@@ -594,7 +608,7 @@ fn main() { T::$0; }
594macro_rules! foo { () => {} } 608macro_rules! foo { () => {} }
595 609
596fn main() { let _ = crate::$0 } 610fn main() { let _ = crate::$0 }
597 "#, 611"#,
598 expect![[r##" 612 expect![[r##"
599 fn main() fn() 613 fn main() fn()
600 ma foo!(…) #[macro_export] macro_rules! foo 614 ma foo!(…) #[macro_export] macro_rules! foo
@@ -603,6 +617,44 @@ fn main() { let _ = crate::$0 }
603 } 617 }
604 618
605 #[test] 619 #[test]
620 fn completes_in_assoc_item_list() {
621 check(
622 r#"
623#[macro_export]
624macro_rules! foo { () => {} }
625mod bar {}
626
627struct MyStruct {}
628impl MyStruct {
629 crate::$0
630}
631"#,
632 expect![[r##"
633 md bar
634 ma foo! #[macro_export] macro_rules! foo
635 "##]],
636 );
637 }
638
639 #[test]
640 #[ignore] // FIXME doesn't complete anything atm
641 fn completes_in_item_list() {
642 check(
643 r#"
644struct MyStruct {}
645macro_rules! foo {}
646mod bar {}
647
648crate::$0
649"#,
650 expect![[r#"
651 md bar
652 ma foo! macro_rules! foo
653 "#]],
654 )
655 }
656
657 #[test]
606 fn test_super_super_completion() { 658 fn test_super_super_completion() {
607 check( 659 check(
608 r#" 660 r#"