1 use expect_test::{expect, Expect};
3 use crate::tests::{check_edit, check_edit_with_config, TEST_CONFIG};
5 fn check(ra_fixture: &str, expect: Expect) {
6 let config = TEST_CONFIG;
7 let (db, position) = crate::tests::position(ra_fixture);
8 let ctx = crate::context::CompletionContext::new(&db, position, &config).unwrap();
10 let mut acc = crate::completions::Completions::default();
11 crate::completions::flyimport::import_on_the_fly(&mut acc, &ctx);
13 expect.assert_eq(&super::render_completion_list(Vec::from(acc)));
17 fn function_fuzzy_completion() {
26 //- /main.rs crate:main deps:dep
42 fn macro_fuzzy_completion() {
44 "macro_with_curlies!",
47 /// Please call me as macro_with_curlies! {}
49 macro_rules! macro_with_curlies {
53 //- /main.rs crate:main deps:dep
59 use dep::macro_with_curlies;
62 macro_with_curlies! {$0}
69 fn struct_fuzzy_completion() {
74 pub struct FirstStruct;
76 pub struct SecondStruct;
77 pub struct ThirdStruct;
80 //- /main.rs crate:main deps:dep
81 use dep::{FirstStruct, some_module::SecondStruct};
88 use dep::{FirstStruct, some_module::{SecondStruct, ThirdStruct}};
98 fn short_paths_are_ignored() {
99 cov_mark::check!(flyimport_exact_on_short_path);
103 //- /lib.rs crate:dep
107 pub mod some_module {
113 //- /main.rs crate:main deps:dep
120 st Rc (use dep::some_module::Rc)
126 fn fuzzy_completions_come_in_specific_order() {
127 cov_mark::check!(certain_fuzzy_order_test);
130 //- /lib.rs crate:dep
131 pub struct FirstStruct;
132 pub mod some_module {
133 // already imported, omitted
134 pub struct SecondStruct;
135 // does not contain all letters from the query, omitted
136 pub struct UnrelatedOne;
137 // contains all letters from the query, but not in sequence, displayed last
138 pub struct ThiiiiiirdStruct;
139 // contains all letters from the query, but not in the beginning, displayed second
140 pub struct AfterThirdStruct;
141 // contains all letters from the query in the begginning, displayed first
142 pub struct ThirdStruct;
145 //- /main.rs crate:main deps:dep
146 use dep::{FirstStruct, some_module::SecondStruct};
153 st ThirdStruct (use dep::some_module::ThirdStruct)
154 st AfterThirdStruct (use dep::some_module::AfterThirdStruct)
155 st ThiiiiiirdStruct (use dep::some_module::ThiiiiiirdStruct)
161 fn trait_function_fuzzy_completion() {
163 //- /lib.rs crate:dep
165 pub trait TestTrait {
166 const SPECIAL_CONST: u8;
169 fn random_method(&self);
171 pub struct TestStruct {}
172 impl TestTrait for TestStruct {
173 const SPECIAL_CONST: u8 = 42;
174 type HumbleType = ();
175 fn weird_function() {}
176 fn random_method(&self) {}
180 //- /main.rs crate:main deps:dep
182 dep::test_mod::TestStruct::wei$0
189 fn weird_function() (use dep::test_mod::TestTrait) fn()
197 use dep::test_mod::TestTrait;
200 dep::test_mod::TestStruct::weird_function()$0
207 fn trait_const_fuzzy_completion() {
209 //- /lib.rs crate:dep
211 pub trait TestTrait {
212 const SPECIAL_CONST: u8;
215 fn random_method(&self);
217 pub struct TestStruct {}
218 impl TestTrait for TestStruct {
219 const SPECIAL_CONST: u8 = 42;
220 type HumbleType = ();
221 fn weird_function() {}
222 fn random_method(&self) {}
226 //- /main.rs crate:main deps:dep
228 dep::test_mod::TestStruct::spe$0
235 ct SPECIAL_CONST (use dep::test_mod::TestTrait)
243 use dep::test_mod::TestTrait;
246 dep::test_mod::TestStruct::SPECIAL_CONST
253 fn trait_method_fuzzy_completion() {
255 //- /lib.rs crate:dep
257 pub trait TestTrait {
258 const SPECIAL_CONST: u8;
261 fn random_method(&self);
263 pub struct TestStruct {}
264 impl TestTrait for TestStruct {
265 const SPECIAL_CONST: u8 = 42;
266 type HumbleType = ();
267 fn weird_function() {}
268 fn random_method(&self) {}
272 //- /main.rs crate:main deps:dep
274 let test_struct = dep::test_mod::TestStruct {};
282 me random_method() (use dep::test_mod::TestTrait) fn(&self)
290 use dep::test_mod::TestTrait;
293 let test_struct = dep::test_mod::TestStruct {};
294 test_struct.random_method()$0
301 fn trait_method_from_alias() {
303 //- /lib.rs crate:dep
305 pub trait TestTrait {
308 pub struct TestStruct {}
309 impl TestTrait for TestStruct {
310 fn random_method() {}
312 pub type TestAlias = TestStruct;
315 //- /main.rs crate:main deps:dep
317 dep::test_mod::TestAlias::ran$0
324 fn random_method() (use dep::test_mod::TestTrait) fn()
332 use dep::test_mod::TestTrait;
335 dep::test_mod::TestAlias::random_method()$0
342 fn no_trait_type_fuzzy_completion() {
345 //- /lib.rs crate:dep
347 pub trait TestTrait {
348 const SPECIAL_CONST: u8;
351 fn random_method(&self);
353 pub struct TestStruct {}
354 impl TestTrait for TestStruct {
355 const SPECIAL_CONST: u8 = 42;
356 type HumbleType = ();
357 fn weird_function() {}
358 fn random_method(&self) {}
362 //- /main.rs crate:main deps:dep
364 dep::test_mod::TestStruct::hum$0
372 fn does_not_propose_names_in_scope() {
375 //- /lib.rs crate:dep
377 pub trait TestTrait {
378 const SPECIAL_CONST: u8;
381 fn random_method(&self);
383 pub struct TestStruct {}
384 impl TestTrait for TestStruct {
385 const SPECIAL_CONST: u8 = 42;
386 type HumbleType = ();
387 fn weird_function() {}
388 fn random_method(&self) {}
392 //- /main.rs crate:main deps:dep
393 use dep::test_mod::TestStruct;
403 fn does_not_propose_traits_in_scope() {
406 //- /lib.rs crate:dep
408 pub trait TestTrait {
409 const SPECIAL_CONST: u8;
412 fn random_method(&self);
414 pub struct TestStruct {}
415 impl TestTrait for TestStruct {
416 const SPECIAL_CONST: u8 = 42;
417 type HumbleType = ();
418 fn weird_function() {}
419 fn random_method(&self) {}
423 //- /main.rs crate:main deps:dep
424 use dep::test_mod::{TestStruct, TestTrait};
426 dep::test_mod::TestStruct::hum$0
434 fn blanket_trait_impl_import() {
438 //- /lib.rs crate:dep
440 pub struct TestStruct {}
441 pub trait TestTrait {
442 fn another_function();
444 impl<T> TestTrait for T {
445 fn another_function() {}
449 //- /main.rs crate:main deps:dep
451 dep::test_mod::TestStruct::ano$0
455 use dep::test_mod::TestTrait;
458 dep::test_mod::TestStruct::another_function()$0
465 fn zero_input_deprecated_assoc_item_completion() {
468 //- /lib.rs crate:dep
471 pub trait TestTrait {
472 const SPECIAL_CONST: u8;
475 fn random_method(&self);
477 pub struct TestStruct {}
478 impl TestTrait for TestStruct {
479 const SPECIAL_CONST: u8 = 42;
480 type HumbleType = ();
481 fn weird_function() {}
482 fn random_method(&self) {}
486 //- /main.rs crate:main deps:dep
488 let test_struct = dep::test_mod::TestStruct {};
493 me random_method() (use dep::test_mod::TestTrait) fn(&self) DEPRECATED
499 //- /lib.rs crate:dep
502 pub trait TestTrait {
503 const SPECIAL_CONST: u8;
506 fn random_method(&self);
508 pub struct TestStruct {}
509 impl TestTrait for TestStruct {
510 const SPECIAL_CONST: u8 = 42;
511 type HumbleType = ();
512 fn weird_function() {}
513 fn random_method(&self) {}
517 //- /main.rs crate:main deps:dep
519 dep::test_mod::TestStruct::$0
523 fn weird_function() (use dep::test_mod::TestTrait) fn() DEPRECATED
524 ct SPECIAL_CONST (use dep::test_mod::TestTrait) DEPRECATED
530 fn no_completions_in_use_statements() {
533 //- /lib.rs crate:dep
538 //- /main.rs crate:main deps:dep
548 fn prefix_config_usage() {
561 let mut config = TEST_CONFIG;
563 config.insert_use.prefix_kind = hir::PrefixKind::ByCrate;
564 check_edit_with_config(
575 use crate::foo::bar::{self, Item};
582 config.insert_use.prefix_kind = hir::PrefixKind::BySelf;
583 check_edit_with_config(
596 use self::foo::bar::Item;
603 config.insert_use.prefix_kind = hir::PrefixKind::Plain;
604 check_edit_with_config(
626 fn unresolved_qualifier() {
643 st Item (use foo::bar::baz::Item)
668 fn unresolved_assoc_item_container() {
674 pub const TEST_ASSOC: usize = 3;
685 ct TEST_ASSOC (use foo::Item)
699 pub const TEST_ASSOC: usize = 3;
710 fn unresolved_assoc_item_container_with_path() {
717 pub const TEST_ASSOC: usize = 3;
729 ct TEST_ASSOC (use foo::bar::Item)
744 pub const TEST_ASSOC: usize = 3;
750 bar::Item::TEST_ASSOC
756 fn fuzzy_unresolved_path() {
764 pub const TEST_ASSOC: usize = 3;
777 fn unqualified_assoc_items_are_omitted() {
781 pub trait BaseTrait {
782 fn test_function() -> i32;
788 impl BaseTrait for Item1 {
789 fn test_function() -> i32 {
794 impl BaseTrait for Item2 {
795 fn test_function() -> i32 {
813 pub const TEST_CONST: usize = 3;
814 pub fn test_function() -> i32 {
823 ct TEST_CONST (use foo::TEST_CONST)
830 pub const TEST_CONST: usize = 3;
831 pub fn test_function() -> i32 {
840 ct TEST_CONST (use foo::TEST_CONST)
841 fn test_function() (use foo::test_function) fn() -> i32
848 pub const TEST_CONST: usize = 3;
849 pub fn test_function() -> i32 {
862 fn no_fuzzy_during_fields_of_record_lit_syntax() {
866 pub fn some_fn() -> i32 {
874 let _ = Foo { so$0 };
882 fn fuzzy_after_fields_of_record_lit_syntax() {
886 pub fn some_fn() -> i32 {
894 let _ = Foo { some_field: som$0 };
898 fn some_fn() (use m::some_fn) fn() -> i32
904 fn no_flyimports_in_traits_and_impl_declarations() {
908 pub fn some_fn() -> i32 {
922 pub fn some_fn() -> i32 {
937 pub fn some_fn() -> i32 {
952 fn no_inherent_candidates_proposed() {
956 pub trait DefDatabase {
959 pub trait HirDatabase: DefDatabase {
965 fn test(db: &dyn crate::baz::HirDatabase) {
975 pub trait DefDatabase {
978 pub trait HirDatabase: DefDatabase {
984 fn test(db: &impl crate::baz::HirDatabase) {
994 pub trait DefDatabase {
997 pub trait HirDatabase: DefDatabase {
1003 fn test<T: crate::baz::HirDatabase>(db: T) {
1013 fn respects_doc_hidden() {
1016 //- /lib.rs crate:lib deps:dep
1021 //- /dep.rs crate:dep
1027 impl<T> Private for T {}
1033 //- /lib.rs crate:lib deps:dep
1038 //- /dep.rs crate:dep
1044 impl<T> Private for T {}
1051 fn regression_9760() {
1059 let struct_instance = Stru$0
1064 st Struct (use crate::Struct)
1070 fn flyimport_pattern() {
1074 pub struct FooStruct {}
1075 pub const FooConst: () = ();
1083 ct FooConst (use module::FooConst)
1084 st FooStruct (use module::FooStruct)
1090 fn flyimport_item_name() {
1103 fn flyimport_rename() {
1116 fn flyimport_enum_variant() {
1141 st Barbara (use foo::Barbara)
1147 fn flyimport_attribute() {
1150 //- proc_macros:identity
1155 at identity (use proc_macros::identity) proc_macro identity
1161 //- proc_macros:identity
1166 use proc_macros::identity;
1175 fn flyimport_in_type_bound_omits_types() {
1179 pub struct CompletemeStruct;
1180 pub type CompletemeType = ();
1181 pub enum CompletemeEnum {}
1182 pub trait CompletemeTrait {}
1185 fn f<T>() where T: Comp$0
1188 tt CompletemeTrait (use module::CompletemeTrait)