Skip to content

Commit 2310908

Browse files
committed
fix: Fix vis restriction path completions always using the parent module
1 parent d6329f2 commit 2310908

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

crates/ide_completion/src/completions/vis.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ pub(crate) fn complete_vis(acc: &mut Completions, ctx: &CompletionContext) {
2020

2121
match qualifier {
2222
Some(PathQualifierCtx { resolution, is_super_chain, .. }) => {
23+
// Try completing next child module of the path that is still a parent of the current module
2324
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
2425
if let Some(current_module) = ctx.module {
2526
let next_towards_current = current_module
2627
.path_to_root(ctx.db)
2728
.into_iter()
2829
.take_while(|it| it != module)
29-
.next();
30+
.last();
3031
if let Some(next) = next_towards_current {
3132
if let Some(name) = next.name(ctx.db) {
3233
cov_mark::hit!(visibility_qualified);

crates/ide_completion/src/tests/visibility.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ mod bar {}
5555
);
5656
check(
5757
r#"
58+
mod qux {
59+
mod foo {
60+
pub(in crate::$0)
61+
}
62+
mod baz {}
63+
}
64+
65+
mod bar {}
66+
"#,
67+
expect![[r#"
68+
md qux
69+
"#]],
70+
);
71+
check(
72+
r#"
5873
mod qux {
5974
mod foo {
6075
pub(in crate::qux::$0)

0 commit comments

Comments
 (0)