11402: fix: Fix vis restriction path completions always using the parent module r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2022-02-03 16:02:51 +00:00 committed by GitHub
commit 6ef6fa019c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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)