mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
disable private editable in TEST_CONFIG by default
adjust test_visibility_filter test case
This commit is contained in:
parent
549c810436
commit
534d71a852
3 changed files with 119 additions and 31 deletions
|
@ -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,10 +209,7 @@ pub mod m {
|
|||
fn foo(a: lib::m::A) { a.$0 }
|
||||
"#,
|
||||
expect![[r#"
|
||||
fd crate_field u32
|
||||
fd private_field u32
|
||||
fd pub_field u32
|
||||
fd super_field u32
|
||||
fd pub_field u32
|
||||
"#]],
|
||||
);
|
||||
|
||||
|
@ -258,6 +262,104 @@ mod m {
|
|||
}
|
||||
//- /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
|
||||
fd super_field u32
|
||||
"#]],
|
||||
);
|
||||
|
||||
check_with_private_editable(
|
||||
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_with_private_editable(
|
||||
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_with_private_editable(
|
||||
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 crate_method() fn(&self)
|
||||
|
@ -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 {}
|
||||
|
|
|
@ -65,7 +65,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
|||
enable_postfix_completions: true,
|
||||
enable_imports_on_the_fly: true,
|
||||
enable_self_on_the_fly: true,
|
||||
enable_private_editable: true,
|
||||
enable_private_editable: false,
|
||||
callable: Some(CallableSnippets::FillArguments),
|
||||
snippet_cap: SnippetCap::new(true),
|
||||
insert_use: InsertUseConfig {
|
||||
|
@ -86,6 +86,12 @@ pub(crate) fn completion_list_no_kw(ra_fixture: &str) -> String {
|
|||
completion_list_with_config(TEST_CONFIG, ra_fixture, false, None)
|
||||
}
|
||||
|
||||
pub(crate) fn completion_list_no_kw_with_private_editable(ra_fixture: &str) -> String {
|
||||
let mut config = TEST_CONFIG.clone();
|
||||
config.enable_private_editable = true;
|
||||
completion_list_with_config(config, ra_fixture, false, None)
|
||||
}
|
||||
|
||||
pub(crate) fn completion_list_with_trigger_character(
|
||||
ra_fixture: &str,
|
||||
trigger_character: Option<char>,
|
||||
|
|
|
@ -2,21 +2,13 @@
|
|||
|
||||
use expect_test::{expect, Expect};
|
||||
|
||||
use crate::{
|
||||
tests::{check_edit, completion_list_no_kw, completion_list_with_config, TEST_CONFIG},
|
||||
CompletionConfig,
|
||||
};
|
||||
use crate::tests::{check_edit, completion_list_no_kw};
|
||||
|
||||
fn check(ra_fixture: &str, expect: Expect) {
|
||||
let actual = completion_list_no_kw(ra_fixture);
|
||||
expect.assert_eq(&actual)
|
||||
}
|
||||
|
||||
fn check_with_config(config: CompletionConfig, ra_fixture: &str, expect: Expect) {
|
||||
let actual = completion_list_with_config(config, ra_fixture, false, None);
|
||||
expect.assert_eq(&actual)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completes_if_prefix_is_keyword() {
|
||||
check_edit(
|
||||
|
@ -647,11 +639,7 @@ fn bar() -> Bar {
|
|||
|
||||
#[test]
|
||||
fn completes_fn_in_pub_trait_generated_by_macro() {
|
||||
let mut config = TEST_CONFIG.clone();
|
||||
config.enable_private_editable = false;
|
||||
|
||||
check_with_config(
|
||||
config,
|
||||
check(
|
||||
r#"
|
||||
mod other_mod {
|
||||
macro_rules! make_method {
|
||||
|
@ -685,11 +673,7 @@ fn main() {
|
|||
|
||||
#[test]
|
||||
fn completes_fn_in_pub_trait_generated_by_recursive_macro() {
|
||||
let mut config = TEST_CONFIG.clone();
|
||||
config.enable_private_editable = false;
|
||||
|
||||
check_with_config(
|
||||
config,
|
||||
check(
|
||||
r#"
|
||||
mod other_mod {
|
||||
macro_rules! make_method {
|
||||
|
@ -729,11 +713,7 @@ fn main() {
|
|||
|
||||
#[test]
|
||||
fn completes_const_in_pub_trait_generated_by_macro() {
|
||||
let mut config = TEST_CONFIG.clone();
|
||||
config.enable_private_editable = false;
|
||||
|
||||
check_with_config(
|
||||
config,
|
||||
check(
|
||||
r#"
|
||||
mod other_mod {
|
||||
macro_rules! make_const {
|
||||
|
|
Loading…
Reference in a new issue