diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2022-02-03 17:02:12 +0100 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2022-02-03 17:02:12 +0100 |
| commit | 2310908df7f67f078c3d845db655d0bf7d5ecbef (patch) | |
| tree | c0645c7d6b053cfa946462b0c26439c34ed003fb | |
| parent | d6329f2171cecb8074dd50f931fc52a7b74aeeed (diff) | |
| download | rust-2310908df7f67f078c3d845db655d0bf7d5ecbef.tar.gz rust-2310908df7f67f078c3d845db655d0bf7d5ecbef.zip | |
fix: Fix vis restriction path completions always using the parent module
| -rw-r--r-- | crates/ide_completion/src/completions/vis.rs | 3 | ||||
| -rw-r--r-- | crates/ide_completion/src/tests/visibility.rs | 15 |
2 files changed, 17 insertions, 1 deletions
diff --git a/crates/ide_completion/src/completions/vis.rs b/crates/ide_completion/src/completions/vis.rs index 9cf96326588..c610dcd705d 100644 --- a/crates/ide_completion/src/completions/vis.rs +++ b/crates/ide_completion/src/completions/vis.rs @@ -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); diff --git a/crates/ide_completion/src/tests/visibility.rs b/crates/ide_completion/src/tests/visibility.rs index 2fd16235dc6..970eb707192 100644 --- a/crates/ide_completion/src/tests/visibility.rs +++ b/crates/ide_completion/src/tests/visibility.rs @@ -57,6 +57,21 @@ mod bar {} 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) } mod baz {} |
