Only complete ancestors and self in visibility path completions

This commit is contained in:
Lukas Wirth 2021-07-21 18:54:12 +02:00
parent 3956a5b757
commit ccde0bcd1f
2 changed files with 44 additions and 13 deletions

View file

@ -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() {

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