aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-21 09:51:06 +0000
committerGitHub <[email protected]>2021-03-21 09:51:06 +0000
commit0d40ff5e623b3670ce3e0e324ecbab3e5197aaeb (patch)
treeb376f04aa3bd91eb13007e1a334327a45e45753c /crates/ide_completion
parent09412d85fc3137d6ada3b27170e14c287f1a1191 (diff)
parentb17d99c0706674c7549aca4670f915aa0b0e2f4e (diff)
Merge #8131
8131: Do smart case fuzzy search during flyimports r=SomeoneToIgnore a=SomeoneToIgnore For now, last actionable part of https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/autoimport.20weirdness Should help https://github.com/rust-analyzer/rust-analyzer/issues/7902 Now during the flyimport completion, if the input is searched case-sensitively, if the input contains any non-lowercase letters; otherwise the lookup done as before, case-insensitively. Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ide_completion')
-rw-r--r--crates/ide_completion/src/completions/flyimport.rs61
-rw-r--r--crates/ide_completion/src/lib.rs1
2 files changed, 58 insertions, 4 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index eb2cba631..1ad017198 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -1,8 +1,10 @@
1//! Feature: completion with imports-on-the-fly 1//! Feature: completion with imports-on-the-fly
2//! 2//!
3//! When completing names in the current scope, proposes additional imports from other modules or crates, 3//! When completing names in the current scope, proposes additional imports from other modules or crates,
4//! if they can be qualified in the scope and their name contains all symbols from the completion input 4//! if they can be qualified in the scope and their name contains all symbols from the completion input.
5//! (case-insensitive, in any order or places). 5//!
6//! To be considered applicable, the name must contain all input symbols in the given order, not necessarily adjacent.
7//! If any input symbol is not lowercased, the name must contain all symbols in exact case; otherwise the contaning is checked case-insensitively.
6//! 8//!
7//! ``` 9//! ```
8//! fn main() { 10//! fn main() {
@@ -942,7 +944,7 @@ mod foo {
942} 944}
943 945
944fn main() { 946fn main() {
945 bar::Ass$0 947 bar::ASS$0
946}"#, 948}"#,
947 expect![[]], 949 expect![[]],
948 ) 950 )
@@ -979,4 +981,57 @@ fn main() {
979 expect![[]], 981 expect![[]],
980 ) 982 )
981 } 983 }
984
985 #[test]
986 fn case_matters() {
987 check(
988 r#"
989mod foo {
990 pub const TEST_CONST: usize = 3;
991 pub fn test_function() -> i32 {
992 4
993 }
994}
995
996fn main() {
997 TE$0
998}"#,
999 expect![[r#"
1000 ct foo::TEST_CONST
1001 "#]],
1002 );
1003
1004 check(
1005 r#"
1006mod foo {
1007 pub const TEST_CONST: usize = 3;
1008 pub fn test_function() -> i32 {
1009 4
1010 }
1011}
1012
1013fn main() {
1014 te$0
1015}"#,
1016 expect![[r#"
1017 ct foo::TEST_CONST
1018 fn test_function() (foo::test_function) fn() -> i32
1019 "#]],
1020 );
1021
1022 check(
1023 r#"
1024mod foo {
1025 pub const TEST_CONST: usize = 3;
1026 pub fn test_function() -> i32 {
1027 4
1028 }
1029}
1030
1031fn main() {
1032 Te$0
1033}"#,
1034 expect![[]],
1035 );
1036 }
982} 1037}
diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs
index 87cddb98e..5ac1cb48d 100644
--- a/crates/ide_completion/src/lib.rs
+++ b/crates/ide_completion/src/lib.rs
@@ -161,7 +161,6 @@ pub fn resolve_completion_edits(
161 items_locator::AssocItemSearch::Include, 161 items_locator::AssocItemSearch::Include,
162 Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT), 162 Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
163 ) 163 )
164 .into_iter()
165 .filter_map(|candidate| { 164 .filter_map(|candidate| {
166 current_module 165 current_module
167 .find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind) 166 .find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind)