9665: Only complete ancestors and self in visibility path completions r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-07-21 17:05:44 +00:00 committed by GitHub
commit 4d457e26e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 13 deletions

View file

@ -28,9 +28,8 @@ 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
{
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 {
@ -45,6 +44,25 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
}
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;
}
_ => (),
}
if ctx.in_use_tree() {
if iter::successors(Some(path.clone()), |p| p.qualifier())

View file

@ -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
"#]],
);