Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/completions/dot.rs')
| -rw-r--r-- | crates/ide-completion/src/completions/dot.rs | 112 |
1 files changed, 107 insertions, 5 deletions
diff --git a/crates/ide-completion/src/completions/dot.rs b/crates/ide-completion/src/completions/dot.rs index a11652ca30..4eb1fccd7d 100644 --- a/crates/ide-completion/src/completions/dot.rs +++ b/crates/ide-completion/src/completions/dot.rs @@ -117,13 +117,20 @@ fn complete_methods( mod tests { use expect_test::{expect, Expect}; - use crate::tests::{check_edit, completion_list_no_kw}; + use crate::tests::{ + check_edit, completion_list_no_kw, completion_list_no_kw_with_private_editable, + }; fn check(ra_fixture: &str, expect: Expect) { let actual = completion_list_no_kw(ra_fixture); expect.assert_eq(&actual); } + fn check_with_private_editable(ra_fixture: &str, expect: Expect) { + let actual = completion_list_no_kw_with_private_editable(ra_fixture); + expect.assert_eq(&actual); + } + #[test] fn test_struct_field_and_method_completion() { check( @@ -202,6 +209,101 @@ pub mod m { fn foo(a: lib::m::A) { a.$0 } "#, expect![[r#" + fd pub_field u32 + "#]], + ); + + check( + r#" +//- /lib.rs crate:lib new_source_root:library +pub mod m { + pub struct A { + private_field: u32, + pub pub_field: u32, + pub(crate) crate_field: u32, + pub(super) super_field: u32, + } +} +//- /main.rs crate:main deps:lib new_source_root:local +fn foo(a: lib::m::A) { a.$0 } +"#, + expect![[r#" + fd pub_field u32 + "#]], + ); + + check( + r#" +//- /lib.rs crate:lib new_source_root:library +pub mod m { + pub struct A( + i32, + pub f64, + ); +} +//- /main.rs crate:main deps:lib new_source_root:local +fn foo(a: lib::m::A) { a.$0 } +"#, + expect![[r#" + fd 1 f64 + "#]], + ); + + check( + r#" +//- /lib.rs crate:lib new_source_root:local +pub struct A {} +mod m { + impl super::A { + fn private_method(&self) {} + pub(crate) fn crate_method(&self) {} + pub fn pub_method(&self) {} + } +} +//- /main.rs crate:main deps:lib new_source_root:local +fn foo(a: lib::A) { a.$0 } +"#, + expect![[r#" + me pub_method() fn(&self) + "#]], + ); + check( + r#" +//- /lib.rs crate:lib new_source_root:library +pub struct A {} +mod m { + impl super::A { + fn private_method(&self) {} + pub(crate) fn crate_method(&self) {} + pub fn pub_method(&self) {} + } +} +//- /main.rs crate:main deps:lib new_source_root:local +fn foo(a: lib::A) { a.$0 } +"#, + expect![[r#" + me pub_method() fn(&self) + "#]], + ); + } + + #[test] + fn test_visibility_filtering_with_private_editable_enabled() { + check_with_private_editable( + r#" +//- /lib.rs crate:lib new_source_root:local +pub mod m { + pub struct A { + private_field: u32, + pub pub_field: u32, + pub(crate) crate_field: u32, + pub(super) super_field: u32, + } +} +//- /main.rs crate:main deps:lib new_source_root:local +fn foo(a: lib::m::A) { a.$0 } +"#, + expect![[r#" fd crate_field u32 fd private_field u32 fd pub_field u32 @@ -209,7 +311,7 @@ fn foo(a: lib::m::A) { a.$0 } "#]], ); - check( + check_with_private_editable( r#" //- /lib.rs crate:lib new_source_root:library pub mod m { @@ -228,7 +330,7 @@ fn foo(a: lib::m::A) { a.$0 } "#]], ); - check( + check_with_private_editable( r#" //- /lib.rs crate:lib new_source_root:library pub mod m { @@ -245,7 +347,7 @@ fn foo(a: lib::m::A) { a.$0 } "#]], ); - check( + check_with_private_editable( r#" //- /lib.rs crate:lib new_source_root:local pub struct A {} @@ -265,7 +367,7 @@ fn foo(a: lib::A) { a.$0 } me pub_method() fn(&self) "#]], ); - check( + check_with_private_editable( r#" //- /lib.rs crate:lib new_source_root:library pub struct A {} |