aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/handlers/auto_import.rs140
1 files changed, 140 insertions, 0 deletions
diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs
index 7b6499a08..4cd77adbf 100644
--- a/crates/ra_assists/src/handlers/auto_import.rs
+++ b/crates/ra_assists/src/handlers/auto_import.rs
@@ -811,6 +811,146 @@ fn main() {
811 } 811 }
812 812
813 #[test] 813 #[test]
814 fn trait_method_cross_crate() {
815 check_assist(
816 auto_import,
817 r"
818 //- /main.rs crate:main deps:dep
819 fn main() {
820 let test_struct = dep::test_mod::TestStruct {};
821 test_struct.test_meth<|>od()
822 }
823 //- /dep.rs crate:dep
824 pub mod test_mod {
825 pub trait TestTrait {
826 fn test_method(&self);
827 }
828 pub struct TestStruct {}
829 impl TestTrait for TestStruct {
830 fn test_method(&self) {}
831 }
832 }
833 ",
834 r"
835 use dep::test_mod::TestTrait;
836
837 fn main() {
838 let test_struct = dep::test_mod::TestStruct {};
839 test_struct.test_method()
840 }
841 ",
842 );
843 }
844
845 #[test]
846 fn assoc_fn_cross_crate() {
847 check_assist(
848 auto_import,
849 r"
850 //- /main.rs crate:main deps:dep
851 fn main() {
852 dep::test_mod::TestStruct::test_func<|>tion
853 }
854 //- /dep.rs crate:dep
855 pub mod test_mod {
856 pub trait TestTrait {
857 fn test_function();
858 }
859 pub struct TestStruct {}
860 impl TestTrait for TestStruct {
861 fn test_function() {}
862 }
863 }
864 ",
865 r"
866 use dep::test_mod::TestTrait;
867
868 fn main() {
869 dep::test_mod::TestStruct::test_function
870 }
871 ",
872 );
873 }
874
875 #[test]
876 fn assoc_const_cross_crate() {
877 check_assist(
878 auto_import,
879 r"
880 //- /main.rs crate:main deps:dep
881 fn main() {
882 dep::test_mod::TestStruct::CONST<|>
883 }
884 //- /dep.rs crate:dep
885 pub mod test_mod {
886 pub trait TestTrait {
887 const CONST: bool;
888 }
889 pub struct TestStruct {}
890 impl TestTrait for TestStruct {
891 const CONST: bool = true;
892 }
893 }
894 ",
895 r"
896 use dep::test_mod::TestTrait;
897
898 fn main() {
899 dep::test_mod::TestStruct::CONST
900 }
901 ",
902 );
903 }
904
905 #[test]
906 fn assoc_fn_as_method_cross_crate() {
907 check_assist_not_applicable(
908 auto_import,
909 r"
910 //- /main.rs crate:main deps:dep
911 fn main() {
912 let test_struct = dep::test_mod::TestStruct {};
913 test_struct.test_func<|>tion()
914 }
915 //- /dep.rs crate:dep
916 pub mod test_mod {
917 pub trait TestTrait {
918 fn test_function();
919 }
920 pub struct TestStruct {}
921 impl TestTrait for TestStruct {
922 fn test_function() {}
923 }
924 }
925 ",
926 );
927 }
928
929 #[test]
930 fn private_trait_cross_crate() {
931 check_assist_not_applicable(
932 auto_import,
933 r"
934 //- /main.rs crate:main deps:dep
935 fn main() {
936 let test_struct = dep::test_mod::TestStruct {};
937 test_struct.test_meth<|>od()
938 }
939 //- /dep.rs crate:dep
940 pub mod test_mod {
941 trait TestTrait {
942 fn test_method(&self);
943 }
944 pub struct TestStruct {}
945 impl TestTrait for TestStruct {
946 fn test_method(&self) {}
947 }
948 }
949 ",
950 );
951 }
952
953 #[test]
814 fn not_applicable_for_imported_trait_for_method() { 954 fn not_applicable_for_imported_trait_for_method() {
815 check_assist_not_applicable( 955 check_assist_not_applicable(
816 auto_import, 956 auto_import,