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 +++++++-- crates/ide_completion/src/patterns.rs | 1 - 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'crates/ide_completion') 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 "#]], ) diff --git a/crates/ide_completion/src/patterns.rs b/crates/ide_completion/src/patterns.rs index ed289d561..19e42ba43 100644 --- a/crates/ide_completion/src/patterns.rs +++ b/crates/ide_completion/src/patterns.rs @@ -62,7 +62,6 @@ pub(crate) fn determine_location(tok: SyntaxToken) -> Option ast::SourceFile(_it) => ImmediateLocation::ItemList, ast::ItemList(_it) => ImmediateLocation::ItemList, ast::RefExpr(_it) => ImmediateLocation::RefExpr, - ast::RefPat(_it) => ImmediateLocation::RefExpr, ast::RecordField(_it) => ImmediateLocation::RecordField, ast::AssocItemList(it) => match it.syntax().parent().map(|it| it.kind()) { Some(IMPL) => ImmediateLocation::Impl, -- cgit v1.2.3