Skip to content

Commit 534d71a

Browse files
committed
disable private editable in TEST_CONFIG by default
adjust test_visibility_filter test case
1 parent 549c810 commit 534d71a

File tree

3 files changed

+118
-30
lines changed

3 files changed

+118
-30
lines changed

crates/ide-completion/src/completions/dot.rs

+107-5
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,20 @@ fn complete_methods(
117117
mod tests {
118118
use expect_test::{expect, Expect};
119119

120-
use crate::tests::{check_edit, completion_list_no_kw};
120+
use crate::tests::{
121+
check_edit, completion_list_no_kw, completion_list_no_kw_with_private_editable,
122+
};
121123

122124
fn check(ra_fixture: &str, expect: Expect) {
123125
let actual = completion_list_no_kw(ra_fixture);
124126
expect.assert_eq(&actual);
125127
}
126128

129+
fn check_with_private_editable(ra_fixture: &str, expect: Expect) {
130+
let actual = completion_list_no_kw_with_private_editable(ra_fixture);
131+
expect.assert_eq(&actual);
132+
}
133+
127134
#[test]
128135
fn test_struct_field_and_method_completion() {
129136
check(
@@ -200,6 +207,101 @@ pub mod m {
200207
}
201208
//- /main.rs crate:main deps:lib new_source_root:local
202209
fn foo(a: lib::m::A) { a.$0 }
210+
"#,
211+
expect![[r#"
212+
fd pub_field u32
213+
"#]],
214+
);
215+
216+
check(
217+
r#"
218+
//- /lib.rs crate:lib new_source_root:library
219+
pub mod m {
220+
pub struct A {
221+
private_field: u32,
222+
pub pub_field: u32,
223+
pub(crate) crate_field: u32,
224+
pub(super) super_field: u32,
225+
}
226+
}
227+
//- /main.rs crate:main deps:lib new_source_root:local
228+
fn foo(a: lib::m::A) { a.$0 }
229+
"#,
230+
expect![[r#"
231+
fd pub_field u32
232+
"#]],
233+
);
234+
235+
check(
236+
r#"
237+
//- /lib.rs crate:lib new_source_root:library
238+
pub mod m {
239+
pub struct A(
240+
i32,
241+
pub f64,
242+
);
243+
}
244+
//- /main.rs crate:main deps:lib new_source_root:local
245+
fn foo(a: lib::m::A) { a.$0 }
246+
"#,
247+
expect![[r#"
248+
fd 1 f64
249+
"#]],
250+
);
251+
252+
check(
253+
r#"
254+
//- /lib.rs crate:lib new_source_root:local
255+
pub struct A {}
256+
mod m {
257+
impl super::A {
258+
fn private_method(&self) {}
259+
pub(crate) fn crate_method(&self) {}
260+
pub fn pub_method(&self) {}
261+
}
262+
}
263+
//- /main.rs crate:main deps:lib new_source_root:local
264+
fn foo(a: lib::A) { a.$0 }
265+
"#,
266+
expect![[r#"
267+
me pub_method() fn(&self)
268+
"#]],
269+
);
270+
check(
271+
r#"
272+
//- /lib.rs crate:lib new_source_root:library
273+
pub struct A {}
274+
mod m {
275+
impl super::A {
276+
fn private_method(&self) {}
277+
pub(crate) fn crate_method(&self) {}
278+
pub fn pub_method(&self) {}
279+
}
280+
}
281+
//- /main.rs crate:main deps:lib new_source_root:local
282+
fn foo(a: lib::A) { a.$0 }
283+
"#,
284+
expect![[r#"
285+
me pub_method() fn(&self)
286+
"#]],
287+
);
288+
}
289+
290+
#[test]
291+
fn test_visibility_filtering_with_private_editable_enabled() {
292+
check_with_private_editable(
293+
r#"
294+
//- /lib.rs crate:lib new_source_root:local
295+
pub mod m {
296+
pub struct A {
297+
private_field: u32,
298+
pub pub_field: u32,
299+
pub(crate) crate_field: u32,
300+
pub(super) super_field: u32,
301+
}
302+
}
303+
//- /main.rs crate:main deps:lib new_source_root:local
304+
fn foo(a: lib::m::A) { a.$0 }
203305
"#,
204306
expect![[r#"
205307
fd crate_field u32
@@ -209,7 +311,7 @@ fn foo(a: lib::m::A) { a.$0 }
209311
"#]],
210312
);
211313

212-
check(
314+
check_with_private_editable(
213315
r#"
214316
//- /lib.rs crate:lib new_source_root:library
215317
pub mod m {
@@ -228,7 +330,7 @@ fn foo(a: lib::m::A) { a.$0 }
228330
"#]],
229331
);
230332

231-
check(
333+
check_with_private_editable(
232334
r#"
233335
//- /lib.rs crate:lib new_source_root:library
234336
pub mod m {
@@ -245,7 +347,7 @@ fn foo(a: lib::m::A) { a.$0 }
245347
"#]],
246348
);
247349

248-
check(
350+
check_with_private_editable(
249351
r#"
250352
//- /lib.rs crate:lib new_source_root:local
251353
pub struct A {}
@@ -265,7 +367,7 @@ fn foo(a: lib::A) { a.$0 }
265367
me pub_method() fn(&self)
266368
"#]],
267369
);
268-
check(
370+
check_with_private_editable(
269371
r#"
270372
//- /lib.rs crate:lib new_source_root:library
271373
pub struct A {}

crates/ide-completion/src/tests.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
6565
enable_postfix_completions: true,
6666
enable_imports_on_the_fly: true,
6767
enable_self_on_the_fly: true,
68-
enable_private_editable: true,
68+
enable_private_editable: false,
6969
callable: Some(CallableSnippets::FillArguments),
7070
snippet_cap: SnippetCap::new(true),
7171
insert_use: InsertUseConfig {
@@ -86,6 +86,12 @@ pub(crate) fn completion_list_no_kw(ra_fixture: &str) -> String {
8686
completion_list_with_config(TEST_CONFIG, ra_fixture, false, None)
8787
}
8888

89+
pub(crate) fn completion_list_no_kw_with_private_editable(ra_fixture: &str) -> String {
90+
let mut config = TEST_CONFIG.clone();
91+
config.enable_private_editable = true;
92+
completion_list_with_config(config, ra_fixture, false, None)
93+
}
94+
8995
pub(crate) fn completion_list_with_trigger_character(
9096
ra_fixture: &str,
9197
trigger_character: Option<char>,

crates/ide-completion/src/tests/special.rs

+4-24
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@
22
33
use expect_test::{expect, Expect};
44

5-
use crate::{
6-
tests::{check_edit, completion_list_no_kw, completion_list_with_config, TEST_CONFIG},
7-
CompletionConfig,
8-
};
5+
use crate::tests::{check_edit, completion_list_no_kw};
96

107
fn check(ra_fixture: &str, expect: Expect) {
118
let actual = completion_list_no_kw(ra_fixture);
129
expect.assert_eq(&actual)
1310
}
1411

15-
fn check_with_config(config: CompletionConfig, ra_fixture: &str, expect: Expect) {
16-
let actual = completion_list_with_config(config, ra_fixture, false, None);
17-
expect.assert_eq(&actual)
18-
}
19-
2012
#[test]
2113
fn completes_if_prefix_is_keyword() {
2214
check_edit(
@@ -647,11 +639,7 @@ fn bar() -> Bar {
647639

648640
#[test]
649641
fn completes_fn_in_pub_trait_generated_by_macro() {
650-
let mut config = TEST_CONFIG.clone();
651-
config.enable_private_editable = false;
652-
653-
check_with_config(
654-
config,
642+
check(
655643
r#"
656644
mod other_mod {
657645
macro_rules! make_method {
@@ -685,11 +673,7 @@ fn main() {
685673

686674
#[test]
687675
fn completes_fn_in_pub_trait_generated_by_recursive_macro() {
688-
let mut config = TEST_CONFIG.clone();
689-
config.enable_private_editable = false;
690-
691-
check_with_config(
692-
config,
676+
check(
693677
r#"
694678
mod other_mod {
695679
macro_rules! make_method {
@@ -729,11 +713,7 @@ fn main() {
729713

730714
#[test]
731715
fn completes_const_in_pub_trait_generated_by_macro() {
732-
let mut config = TEST_CONFIG.clone();
733-
config.enable_private_editable = false;
734-
735-
check_with_config(
736-
config,
716+
check(
737717
r#"
738718
mod other_mod {
739719
macro_rules! make_const {

0 commit comments

Comments
 (0)