diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index 1d3a0ec8682..03b079ed7a0 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs @@ -28,22 +28,40 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon let context_module = ctx.scope.module(); - if let Some(ImmediateLocation::ItemList | ImmediateLocation::Trait | ImmediateLocation::Impl) = - ctx.completion_location - { - if let hir::PathResolution::Def(hir::ModuleDef::Module(module)) = resolution { - for (name, def) in module.scope(ctx.db, context_module) { - if let hir::ScopeDef::MacroDef(macro_def) = def { - if macro_def.is_fn_like() { - acc.add_macro(ctx, Some(name.clone()), macro_def); + match ctx.completion_location { + Some(ImmediateLocation::ItemList | ImmediateLocation::Trait | ImmediateLocation::Impl) => { + if let hir::PathResolution::Def(hir::ModuleDef::Module(module)) = resolution { + for (name, def) in module.scope(ctx.db, context_module) { + if let hir::ScopeDef::MacroDef(macro_def) = def { + if macro_def.is_fn_like() { + acc.add_macro(ctx, Some(name.clone()), macro_def); + } + } + if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { + acc.add_resolution(ctx, name, &def); } } - if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { - acc.add_resolution(ctx, name, &def); + } + return; + } + Some(ImmediateLocation::Visibility(_)) => { + if let hir::PathResolution::Def(hir::ModuleDef::Module(resolved)) = resolution { + if let Some(current_module) = ctx.scope.module() { + if let Some(next) = current_module + .path_to_root(ctx.db) + .into_iter() + .take_while(|&it| it != resolved) + .next() + { + if let Some(name) = next.name(ctx.db) { + acc.add_resolution(ctx, name, &hir::ScopeDef::ModuleDef(next.into())); + } + } } } + return; } - return; + _ => (), } if ctx.in_use_tree() { diff --git a/crates/ide_completion/src/tests/visibility.rs b/crates/ide_completion/src/tests/visibility.rs index 984155cfd2f..8a024af24b8 100644 --- a/crates/ide_completion/src/tests/visibility.rs +++ b/crates/ide_completion/src/tests/visibility.rs @@ -40,7 +40,6 @@ pub(in $0) #[test] fn qualified() { - // FIXME: only show parent modules check( r#" mod foo { @@ -50,7 +49,21 @@ mod foo { mod bar {} "#, expect![[r#" - md bar + md foo + "#]], + ); + check( + r#" +mod qux { + mod foo { + pub(in crate::qux::$0) + } + mod baz {} +} + +mod bar {} +"#, + expect![[r#" md foo "#]], );