fix: Fix vis restriction path completions always using the parent module

This commit is contained in:
Lukas Wirth 2022-02-03 17:02:12 +01:00
parent d6329f2171
commit 2310908df7
2 changed files with 17 additions and 1 deletions

View file

@ -20,13 +20,14 @@ pub(crate) fn complete_vis(acc: &mut Completions, ctx: &CompletionContext) {
match qualifier {
Some(PathQualifierCtx { resolution, is_super_chain, .. }) => {
// Try completing next child module of the path that is still a parent of the current module
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
if let Some(current_module) = ctx.module {
let next_towards_current = current_module
.path_to_root(ctx.db)
.into_iter()
.take_while(|it| it != module)
.next();
.last();
if let Some(next) = next_towards_current {
if let Some(name) = next.name(ctx.db) {
cov_mark::hit!(visibility_qualified);

View file

@ -55,6 +55,21 @@ mod bar {}
);
check(
r#"
mod qux {
mod foo {
pub(in crate::$0)
}
mod baz {}
}
mod bar {}
"#,
expect![[r#"
md qux
"#]],
);
check(
r#"
mod qux {
mod foo {
pub(in crate::qux::$0)