From 7ad378fec06dae4ba2417f2a109e4759bbcf75db Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 27 May 2021 20:53:38 +0200 Subject: Complete modules in assoc item lists --- crates/ide_completion/src/completions/qualified_path.rs | 8 ++++++-- crates/ide_completion/src/completions/unqualified_path.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'crates/ide_completion/src/completions') diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index c16bb215f..4aa37df91 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs @@ -27,6 +27,9 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon if let ScopeDef::MacroDef(macro_def) = def { acc.add_macro(ctx, Some(name.to_string()), macro_def); } + if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { + acc.add_resolution(ctx, name.to_string(), &def); + } } } return; @@ -614,19 +617,20 @@ fn main() { let _ = crate::$0 } } #[test] - fn completes_qualified_macros_in_impl() { + fn completes_in_assoc_item_list() { check( r#" #[macro_export] macro_rules! foo { () => {} } +mod bar {} struct MyStruct {} - impl MyStruct { crate::$0 } "#, expect![[r##" + md bar ma foo! #[macro_export] macro_rules! foo "##]], ); diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index cbac88240..dc93e368d 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs @@ -17,6 +17,9 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC if let ScopeDef::MacroDef(macro_def) = def { acc.add_macro(ctx, Some(name.to_string()), macro_def); } + if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { + acc.add_resolution(ctx, name.to_string(), &def); + } }); return; } @@ -672,17 +675,19 @@ impl My$0 } #[test] - fn only_completes_macros_in_assoc_item_list() { + fn completes_in_assoc_item_list() { check( r#" -struct MyStruct {} macro_rules! foo {} +mod bar {} +struct MyStruct {} impl MyStruct { $0 } "#, expect![[r#" + md bar ma foo! macro_rules! foo "#]], ) -- cgit v1.2.3