Merge pull request #20025 from SoxPopuli/hide_private_imports_without_pe

Hide imported privates if private editable is disabled
This commit is contained in:
Laurențiu Nicola 2025-06-17 15:27:27 +00:00 committed by GitHub
commit 20a62ab2a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 98 additions and 5 deletions

View file

@ -145,10 +145,16 @@ pub(crate) fn complete_expr_path(
});
match resolution {
hir::PathResolution::Def(hir::ModuleDef::Module(module)) => {
// Set visible_from to None so private items are returned.
// They will be possibly filtered out in add_path_resolution()
// via def_is_visible().
let module_scope = module.scope(ctx.db, None);
let visible_from = if ctx.config.enable_private_editable {
// Set visible_from to None so private items are returned.
// They will be possibly filtered out in add_path_resolution()
// via def_is_visible().
None
} else {
Some(ctx.module)
};
let module_scope = module.scope(ctx.db, visible_from);
for (name, def) in module_scope {
if scope_def_applicable(def) {
acc.add_path_resolution(

View file

@ -1,7 +1,7 @@
//! Completion tests for visibility modifiers.
use expect_test::expect;
use crate::tests::{check, check_with_trigger_character};
use crate::tests::{check, check_with_private_editable, check_with_trigger_character};
#[test]
fn empty_pub() {
@ -78,3 +78,90 @@ mod bar {}
"#]],
);
}
#[test]
fn use_inner_public_function() {
check(
r#"
//- /inner.rs crate:inner
pub fn inner_public() {}
fn inner_private() {}
//- /foo.rs crate:foo deps:inner
use inner::inner_public;
pub fn outer_public() {}
//- /lib.rs crate:lib deps:foo
fn x() {
foo::$0
}
"#,
expect![[r#"
fn outer_public() fn()
"#]],
);
}
#[test]
fn pub_use_inner_public_function() {
check(
r#"
//- /inner.rs crate:inner
pub fn inner_public() {}
fn inner_private() {}
//- /foo.rs crate:foo deps:inner
pub use inner::inner_public;
pub fn outer_public() {}
//- /lib.rs crate:lib deps:foo
fn x() {
foo::$0
}
"#,
expect![[r#"
fn inner_public() fn()
fn outer_public() fn()
"#]],
);
}
#[test]
fn use_inner_public_function_private_editable() {
check_with_private_editable(
r#"
//- /inner.rs crate:inner
pub fn inner_public() {}
fn inner_private() {}
//- /foo.rs crate:foo deps:inner
use inner::inner_public;
pub fn outer_public() {}
//- /lib.rs crate:lib deps:foo
fn x() {
foo::$0
}
"#,
expect![[r#"
fn inner_public() fn()
fn outer_public() fn()
"#]],
);
}
#[test]
fn pub_use_inner_public_function_private_editable() {
check_with_private_editable(
r#"
//- /inner.rs crate:inner
pub fn inner_public() {}
fn inner_private() {}
//- /foo.rs crate:foo deps:inner
pub use inner::inner_public;
pub fn outer_public() {}
//- /lib.rs crate:lib deps:foo
fn x() {
foo::$0
}
"#,
expect![[r#"
fn inner_public() fn()
fn outer_public() fn()
"#]],
);
}