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!(ignore_short_input_for_path);
103 //- /lib.rs crate:dep
104 pub struct FirstStruct;
105 pub mod some_module {
106 pub struct SecondStruct;
107 pub struct ThirdStruct;
110 //- /main.rs crate:main deps:dep
111 use dep::{FirstStruct, some_module::SecondStruct};
122 fn fuzzy_completions_come_in_specific_order() {
123 cov_mark::check!(certain_fuzzy_order_test);
126 //- /lib.rs crate:dep
127 pub struct FirstStruct;
128 pub mod some_module {
129 // already imported, omitted
130 pub struct SecondStruct;
131 // does not contain all letters from the query, omitted
132 pub struct UnrelatedOne;
133 // contains all letters from the query, but not in sequence, displayed last
134 pub struct ThiiiiiirdStruct;
135 // contains all letters from the query, but not in the beginning, displayed second
136 pub struct AfterThirdStruct;
137 // contains all letters from the query in the begginning, displayed first
138 pub struct ThirdStruct;
141 //- /main.rs crate:main deps:dep
142 use dep::{FirstStruct, some_module::SecondStruct};
149 st ThirdStruct (use dep::some_module::ThirdStruct)
150 st AfterThirdStruct (use dep::some_module::AfterThirdStruct)
151 st ThiiiiiirdStruct (use dep::some_module::ThiiiiiirdStruct)
157 fn trait_function_fuzzy_completion() {
159 //- /lib.rs crate:dep
161 pub trait TestTrait {
162 const SPECIAL_CONST: u8;
165 fn random_method(&self);
167 pub struct TestStruct {}
168 impl TestTrait for TestStruct {
169 const SPECIAL_CONST: u8 = 42;
170 type HumbleType = ();
171 fn weird_function() {}
172 fn random_method(&self) {}
176 //- /main.rs crate:main deps:dep
178 dep::test_mod::TestStruct::wei$0
185 fn weird_function() (use dep::test_mod::TestTrait) fn()
193 use dep::test_mod::TestTrait;
196 dep::test_mod::TestStruct::weird_function()$0
203 fn trait_const_fuzzy_completion() {
205 //- /lib.rs crate:dep
207 pub trait TestTrait {
208 const SPECIAL_CONST: u8;
211 fn random_method(&self);
213 pub struct TestStruct {}
214 impl TestTrait for TestStruct {
215 const SPECIAL_CONST: u8 = 42;
216 type HumbleType = ();
217 fn weird_function() {}
218 fn random_method(&self) {}
222 //- /main.rs crate:main deps:dep
224 dep::test_mod::TestStruct::spe$0
231 ct SPECIAL_CONST (use dep::test_mod::TestTrait)
239 use dep::test_mod::TestTrait;
242 dep::test_mod::TestStruct::SPECIAL_CONST
249 fn trait_method_fuzzy_completion() {
251 //- /lib.rs crate:dep
253 pub trait TestTrait {
254 const SPECIAL_CONST: u8;
257 fn random_method(&self);
259 pub struct TestStruct {}
260 impl TestTrait for TestStruct {
261 const SPECIAL_CONST: u8 = 42;
262 type HumbleType = ();
263 fn weird_function() {}
264 fn random_method(&self) {}
268 //- /main.rs crate:main deps:dep
270 let test_struct = dep::test_mod::TestStruct {};
278 me random_method() (use dep::test_mod::TestTrait) fn(&self)
286 use dep::test_mod::TestTrait;
289 let test_struct = dep::test_mod::TestStruct {};
290 test_struct.random_method()$0
297 fn no_trait_type_fuzzy_completion() {
300 //- /lib.rs crate:dep
302 pub trait TestTrait {
303 const SPECIAL_CONST: u8;
306 fn random_method(&self);
308 pub struct TestStruct {}
309 impl TestTrait for TestStruct {
310 const SPECIAL_CONST: u8 = 42;
311 type HumbleType = ();
312 fn weird_function() {}
313 fn random_method(&self) {}
317 //- /main.rs crate:main deps:dep
319 dep::test_mod::TestStruct::hum$0
327 fn does_not_propose_names_in_scope() {
330 //- /lib.rs crate:dep
332 pub trait TestTrait {
333 const SPECIAL_CONST: u8;
336 fn random_method(&self);
338 pub struct TestStruct {}
339 impl TestTrait for TestStruct {
340 const SPECIAL_CONST: u8 = 42;
341 type HumbleType = ();
342 fn weird_function() {}
343 fn random_method(&self) {}
347 //- /main.rs crate:main deps:dep
348 use dep::test_mod::TestStruct;
358 fn does_not_propose_traits_in_scope() {
361 //- /lib.rs crate:dep
363 pub trait TestTrait {
364 const SPECIAL_CONST: u8;
367 fn random_method(&self);
369 pub struct TestStruct {}
370 impl TestTrait for TestStruct {
371 const SPECIAL_CONST: u8 = 42;
372 type HumbleType = ();
373 fn weird_function() {}
374 fn random_method(&self) {}
378 //- /main.rs crate:main deps:dep
379 use dep::test_mod::{TestStruct, TestTrait};
381 dep::test_mod::TestStruct::hum$0
389 fn blanket_trait_impl_import() {
393 //- /lib.rs crate:dep
395 pub struct TestStruct {}
396 pub trait TestTrait {
397 fn another_function();
399 impl<T> TestTrait for T {
400 fn another_function() {}
404 //- /main.rs crate:main deps:dep
406 dep::test_mod::TestStruct::ano$0
410 use dep::test_mod::TestTrait;
413 dep::test_mod::TestStruct::another_function()$0
420 fn zero_input_deprecated_assoc_item_completion() {
423 //- /lib.rs crate:dep
426 pub trait TestTrait {
427 const SPECIAL_CONST: u8;
430 fn random_method(&self);
432 pub struct TestStruct {}
433 impl TestTrait for TestStruct {
434 const SPECIAL_CONST: u8 = 42;
435 type HumbleType = ();
436 fn weird_function() {}
437 fn random_method(&self) {}
441 //- /main.rs crate:main deps:dep
443 let test_struct = dep::test_mod::TestStruct {};
448 me random_method() (use dep::test_mod::TestTrait) fn(&self) DEPRECATED
454 //- /lib.rs crate:dep
457 pub trait TestTrait {
458 const SPECIAL_CONST: u8;
461 fn random_method(&self);
463 pub struct TestStruct {}
464 impl TestTrait for TestStruct {
465 const SPECIAL_CONST: u8 = 42;
466 type HumbleType = ();
467 fn weird_function() {}
468 fn random_method(&self) {}
472 //- /main.rs crate:main deps:dep
474 dep::test_mod::TestStruct::$0
478 fn weird_function() (use dep::test_mod::TestTrait) fn() DEPRECATED
479 ct SPECIAL_CONST (use dep::test_mod::TestTrait) DEPRECATED
485 fn no_completions_in_use_statements() {
488 //- /lib.rs crate:dep
493 //- /main.rs crate:main deps:dep
503 fn prefix_config_usage() {
516 let mut config = TEST_CONFIG;
518 config.insert_use.prefix_kind = hir::PrefixKind::ByCrate;
519 check_edit_with_config(
530 use crate::foo::bar::{self, Item};
537 config.insert_use.prefix_kind = hir::PrefixKind::BySelf;
538 check_edit_with_config(
551 use self::foo::bar::Item;
558 config.insert_use.prefix_kind = hir::PrefixKind::Plain;
559 check_edit_with_config(
581 fn unresolved_qualifier() {
598 st Item (use foo::bar::baz::Item)
623 fn unresolved_assoc_item_container() {
629 pub const TEST_ASSOC: usize = 3;
640 ct TEST_ASSOC (use foo::Item)
654 pub const TEST_ASSOC: usize = 3;
665 fn unresolved_assoc_item_container_with_path() {
672 pub const TEST_ASSOC: usize = 3;
684 ct TEST_ASSOC (use foo::bar::Item)
699 pub const TEST_ASSOC: usize = 3;
705 bar::Item::TEST_ASSOC
711 fn fuzzy_unresolved_path() {
719 pub const TEST_ASSOC: usize = 3;
732 fn unqualified_assoc_items_are_omitted() {
736 pub trait BaseTrait {
737 fn test_function() -> i32;
743 impl BaseTrait for Item1 {
744 fn test_function() -> i32 {
749 impl BaseTrait for Item2 {
750 fn test_function() -> i32 {
768 pub const TEST_CONST: usize = 3;
769 pub fn test_function() -> i32 {
778 ct TEST_CONST (use foo::TEST_CONST)
785 pub const TEST_CONST: usize = 3;
786 pub fn test_function() -> i32 {
795 ct TEST_CONST (use foo::TEST_CONST)
796 fn test_function() (use foo::test_function) fn() -> i32
803 pub const TEST_CONST: usize = 3;
804 pub fn test_function() -> i32 {
817 fn no_fuzzy_during_fields_of_record_lit_syntax() {
821 pub fn some_fn() -> i32 {
829 let _ = Foo { so$0 };
837 fn fuzzy_after_fields_of_record_lit_syntax() {
841 pub fn some_fn() -> i32 {
849 let _ = Foo { some_field: so$0 };
853 fn some_fn() (use m::some_fn) fn() -> i32
859 fn no_flyimports_in_traits_and_impl_declarations() {
863 pub fn some_fn() -> i32 {
877 pub fn some_fn() -> i32 {
892 pub fn some_fn() -> i32 {
907 fn no_inherent_candidates_proposed() {
911 pub trait DefDatabase {
914 pub trait HirDatabase: DefDatabase {
920 fn test(db: &dyn crate::baz::HirDatabase) {
930 fn respects_doc_hidden() {
933 //- /lib.rs crate:lib deps:dep
938 //- /dep.rs crate:dep
944 impl<T> Private for T {}
950 //- /lib.rs crate:lib deps:dep
955 //- /dep.rs crate:dep
961 impl<T> Private for T {}
968 fn regression_9760() {
976 let struct_instance = Stru$0
981 st Struct (use crate::Struct)
987 fn flyimport_pattern() {
998 st Struct (use module::Struct)
1004 fn flyimport_item_name() {
1017 fn flyimport_rename() {
1030 fn flyimport_enum_variant() {
1055 st Barbara (use foo::Barbara)
1061 fn flyimport_attribute() {
1064 //- proc_macros:identity
1069 at identity (use proc_macros::identity) pub macro identity
1075 //- proc_macros:identity
1080 use proc_macros::identity;