mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
use check_assist_by_label
to pick assist
This commit is contained in:
parent
a723acf346
commit
929544ef28
1 changed files with 213 additions and 7 deletions
|
@ -287,7 +287,8 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tests::{
|
use crate::tests::{
|
||||||
check_assist, check_assist_not_applicable, check_assist_target, TEST_CONFIG,
|
check_assist, check_assist_by_label, check_assist_not_applicable, check_assist_target,
|
||||||
|
TEST_CONFIG,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn check_auto_import_order(before: &str, order: &[&str]) {
|
fn check_auto_import_order(before: &str, order: &[&str]) {
|
||||||
|
@ -739,7 +740,44 @@ fn main() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn associated_trait_function() {
|
fn associated_trait_function() {
|
||||||
check_assist(
|
check_assist_by_label(
|
||||||
|
auto_import,
|
||||||
|
r"
|
||||||
|
mod test_mod {
|
||||||
|
pub trait TestTrait {
|
||||||
|
fn test_function();
|
||||||
|
}
|
||||||
|
pub struct TestStruct {}
|
||||||
|
impl TestTrait for TestStruct {
|
||||||
|
fn test_function() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
test_mod::TestStruct::test_function$0
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
use test_mod::TestTrait;
|
||||||
|
|
||||||
|
mod test_mod {
|
||||||
|
pub trait TestTrait {
|
||||||
|
fn test_function();
|
||||||
|
}
|
||||||
|
pub struct TestStruct {}
|
||||||
|
impl TestTrait for TestStruct {
|
||||||
|
fn test_function() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
test_mod::TestStruct::test_function
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Import `test_mod::TestTrait`",
|
||||||
|
);
|
||||||
|
|
||||||
|
check_assist_by_label(
|
||||||
auto_import,
|
auto_import,
|
||||||
r"
|
r"
|
||||||
mod test_mod {
|
mod test_mod {
|
||||||
|
@ -773,6 +811,7 @@ fn main() {
|
||||||
test_mod::TestStruct::test_function
|
test_mod::TestStruct::test_function
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
|
"Import `test_mod::TestTrait as _`",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,7 +849,7 @@ fn main() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn associated_trait_const() {
|
fn associated_trait_const() {
|
||||||
check_assist(
|
check_assist_by_label(
|
||||||
auto_import,
|
auto_import,
|
||||||
r"
|
r"
|
||||||
mod test_mod {
|
mod test_mod {
|
||||||
|
@ -844,6 +883,44 @@ fn main() {
|
||||||
test_mod::TestStruct::TEST_CONST
|
test_mod::TestStruct::TEST_CONST
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
|
"Import `test_mod::TestTrait as _`",
|
||||||
|
);
|
||||||
|
|
||||||
|
check_assist_by_label(
|
||||||
|
auto_import,
|
||||||
|
r"
|
||||||
|
mod test_mod {
|
||||||
|
pub trait TestTrait {
|
||||||
|
const TEST_CONST: u8;
|
||||||
|
}
|
||||||
|
pub struct TestStruct {}
|
||||||
|
impl TestTrait for TestStruct {
|
||||||
|
const TEST_CONST: u8 = 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
test_mod::TestStruct::TEST_CONST$0
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
use test_mod::TestTrait;
|
||||||
|
|
||||||
|
mod test_mod {
|
||||||
|
pub trait TestTrait {
|
||||||
|
const TEST_CONST: u8;
|
||||||
|
}
|
||||||
|
pub struct TestStruct {}
|
||||||
|
impl TestTrait for TestStruct {
|
||||||
|
const TEST_CONST: u8 = 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
test_mod::TestStruct::TEST_CONST
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Import `test_mod::TestTrait`",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -881,7 +958,7 @@ fn main() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn trait_method() {
|
fn trait_method() {
|
||||||
check_assist(
|
check_assist_by_label(
|
||||||
auto_import,
|
auto_import,
|
||||||
r"
|
r"
|
||||||
mod test_mod {
|
mod test_mod {
|
||||||
|
@ -917,12 +994,52 @@ fn main() {
|
||||||
test_struct.test_method()
|
test_struct.test_method()
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
|
"Import `test_mod::TestTrait as _`",
|
||||||
|
);
|
||||||
|
|
||||||
|
check_assist_by_label(
|
||||||
|
auto_import,
|
||||||
|
r"
|
||||||
|
mod test_mod {
|
||||||
|
pub trait TestTrait {
|
||||||
|
fn test_method(&self);
|
||||||
|
}
|
||||||
|
pub struct TestStruct {}
|
||||||
|
impl TestTrait for TestStruct {
|
||||||
|
fn test_method(&self) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let test_struct = test_mod::TestStruct {};
|
||||||
|
test_struct.test_meth$0od()
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
use test_mod::TestTrait;
|
||||||
|
|
||||||
|
mod test_mod {
|
||||||
|
pub trait TestTrait {
|
||||||
|
fn test_method(&self);
|
||||||
|
}
|
||||||
|
pub struct TestStruct {}
|
||||||
|
impl TestTrait for TestStruct {
|
||||||
|
fn test_method(&self) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let test_struct = test_mod::TestStruct {};
|
||||||
|
test_struct.test_method()
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Import `test_mod::TestTrait`",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn trait_method_cross_crate() {
|
fn trait_method_cross_crate() {
|
||||||
check_assist(
|
check_assist_by_label(
|
||||||
auto_import,
|
auto_import,
|
||||||
r"
|
r"
|
||||||
//- /main.rs crate:main deps:dep
|
//- /main.rs crate:main deps:dep
|
||||||
|
@ -949,12 +1066,43 @@ fn main() {
|
||||||
test_struct.test_method()
|
test_struct.test_method()
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
|
"Import `dep::test_mod::TestTrait as _`",
|
||||||
|
);
|
||||||
|
|
||||||
|
check_assist_by_label(
|
||||||
|
auto_import,
|
||||||
|
r"
|
||||||
|
//- /main.rs crate:main deps:dep
|
||||||
|
fn main() {
|
||||||
|
let test_struct = dep::test_mod::TestStruct {};
|
||||||
|
test_struct.test_meth$0od()
|
||||||
|
}
|
||||||
|
//- /dep.rs crate:dep
|
||||||
|
pub mod test_mod {
|
||||||
|
pub trait TestTrait {
|
||||||
|
fn test_method(&self);
|
||||||
|
}
|
||||||
|
pub struct TestStruct {}
|
||||||
|
impl TestTrait for TestStruct {
|
||||||
|
fn test_method(&self) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
use dep::test_mod::TestTrait;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let test_struct = dep::test_mod::TestStruct {};
|
||||||
|
test_struct.test_method()
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Import `dep::test_mod::TestTrait`",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn assoc_fn_cross_crate() {
|
fn assoc_fn_cross_crate() {
|
||||||
check_assist(
|
check_assist_by_label(
|
||||||
auto_import,
|
auto_import,
|
||||||
r"
|
r"
|
||||||
//- /main.rs crate:main deps:dep
|
//- /main.rs crate:main deps:dep
|
||||||
|
@ -979,12 +1127,41 @@ fn main() {
|
||||||
dep::test_mod::TestStruct::test_function
|
dep::test_mod::TestStruct::test_function
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
|
"Import `dep::test_mod::TestTrait as _`",
|
||||||
|
);
|
||||||
|
|
||||||
|
check_assist_by_label(
|
||||||
|
auto_import,
|
||||||
|
r"
|
||||||
|
//- /main.rs crate:main deps:dep
|
||||||
|
fn main() {
|
||||||
|
dep::test_mod::TestStruct::test_func$0tion
|
||||||
|
}
|
||||||
|
//- /dep.rs crate:dep
|
||||||
|
pub mod test_mod {
|
||||||
|
pub trait TestTrait {
|
||||||
|
fn test_function();
|
||||||
|
}
|
||||||
|
pub struct TestStruct {}
|
||||||
|
impl TestTrait for TestStruct {
|
||||||
|
fn test_function() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
use dep::test_mod::TestTrait;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
dep::test_mod::TestStruct::test_function
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Import `dep::test_mod::TestTrait`",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn assoc_const_cross_crate() {
|
fn assoc_const_cross_crate() {
|
||||||
check_assist(
|
check_assist_by_label(
|
||||||
auto_import,
|
auto_import,
|
||||||
r"
|
r"
|
||||||
//- /main.rs crate:main deps:dep
|
//- /main.rs crate:main deps:dep
|
||||||
|
@ -1009,6 +1186,35 @@ fn main() {
|
||||||
dep::test_mod::TestStruct::CONST
|
dep::test_mod::TestStruct::CONST
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
|
"Import `dep::test_mod::TestTrait as _`",
|
||||||
|
);
|
||||||
|
|
||||||
|
check_assist_by_label(
|
||||||
|
auto_import,
|
||||||
|
r"
|
||||||
|
//- /main.rs crate:main deps:dep
|
||||||
|
fn main() {
|
||||||
|
dep::test_mod::TestStruct::CONST$0
|
||||||
|
}
|
||||||
|
//- /dep.rs crate:dep
|
||||||
|
pub mod test_mod {
|
||||||
|
pub trait TestTrait {
|
||||||
|
const CONST: bool;
|
||||||
|
}
|
||||||
|
pub struct TestStruct {}
|
||||||
|
impl TestTrait for TestStruct {
|
||||||
|
const CONST: bool = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
use dep::test_mod::TestTrait;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
dep::test_mod::TestStruct::CONST
|
||||||
|
}
|
||||||
|
",
|
||||||
|
"Import `dep::test_mod::TestTrait`",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue