File tree Expand file tree Collapse file tree 3 files changed +80
-6
lines changed
ide_completion/src/completions Expand file tree Collapse file tree 3 files changed +80
-6
lines changed Original file line number Diff line number Diff line change 11//! Feature: completion with imports-on-the-fly
22//!
33//! 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
5- //! (case-insensitive, in any order or places).
4+ //! if they can be qualified in the scope and their name contains all symbols from the completion input.
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.
68//!
79//! ```
810//! fn main() {
@@ -942,7 +944,7 @@ mod foo {
942944}
943945
944946fn main() {
945- bar::Ass $0
947+ bar::ASS $0
946948}"# ,
947949 expect ! [ [ ] ] ,
948950 )
@@ -979,4 +981,57 @@ fn main() {
979981 expect ! [ [ ] ] ,
980982 )
981983 }
984+
985+ #[ test]
986+ fn case_matters ( ) {
987+ check (
988+ r#"
989+ mod foo {
990+ pub const TEST_CONST: usize = 3;
991+ pub fn test_function() -> i32 {
992+ 4
993+ }
994+ }
995+
996+ fn main() {
997+ TE$0
998+ }"# ,
999+ expect ! [ [ r#"
1000+ ct foo::TEST_CONST
1001+ "# ] ] ,
1002+ ) ;
1003+
1004+ check (
1005+ r#"
1006+ mod foo {
1007+ pub const TEST_CONST: usize = 3;
1008+ pub fn test_function() -> i32 {
1009+ 4
1010+ }
1011+ }
1012+
1013+ fn 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#"
1024+ mod foo {
1025+ pub const TEST_CONST: usize = 3;
1026+ pub fn test_function() -> i32 {
1027+ 4
1028+ }
1029+ }
1030+
1031+ fn main() {
1032+ Te$0
1033+ }"# ,
1034+ expect ! [ [ ] ] ,
1035+ ) ;
1036+ }
9821037}
Original file line number Diff line number Diff line change @@ -62,6 +62,8 @@ pub fn items_with_name(
6262 ( local_query, external_query)
6363 }
6464 NameToImport :: Fuzzy ( fuzzy_search_string) => {
65+ let mut local_query = symbol_index:: Query :: new ( fuzzy_search_string. clone ( ) ) ;
66+
6567 let mut external_query = import_map:: Query :: new ( fuzzy_search_string. clone ( ) )
6668 . search_mode ( import_map:: SearchMode :: Fuzzy )
6769 . name_only ( ) ;
@@ -75,7 +77,12 @@ pub fn items_with_name(
7577 }
7678 }
7779
78- ( symbol_index:: Query :: new ( fuzzy_search_string) , external_query)
80+ if fuzzy_search_string. to_lowercase ( ) != fuzzy_search_string {
81+ local_query. case_sensitive ( ) ;
82+ external_query = external_query. case_sensitive ( ) ;
83+ }
84+
85+ ( local_query, external_query)
7986 }
8087 } ;
8188
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ pub struct Query {
5252 only_types : bool ,
5353 libs : bool ,
5454 exact : bool ,
55+ case_sensitive : bool ,
5556 limit : usize ,
5657}
5758
@@ -64,6 +65,7 @@ impl Query {
6465 only_types : false ,
6566 libs : false ,
6667 exact : false ,
68+ case_sensitive : false ,
6769 limit : usize:: max_value ( ) ,
6870 }
6971 }
@@ -80,6 +82,10 @@ impl Query {
8082 self . exact = true ;
8183 }
8284
85+ pub fn case_sensitive ( & mut self ) {
86+ self . case_sensitive = true ;
87+ }
88+
8389 pub fn limit ( & mut self , limit : usize ) {
8490 self . limit = limit
8591 }
@@ -326,8 +332,14 @@ impl Query {
326332 if self . only_types && !symbol. kind . is_type ( ) {
327333 continue ;
328334 }
329- if self . exact && symbol. name != self . query {
330- continue ;
335+ if self . exact {
336+ if symbol. name != self . query {
337+ continue ;
338+ }
339+ } else if self . case_sensitive {
340+ if self . query . chars ( ) . any ( |c| !symbol. name . contains ( c) ) {
341+ continue ;
342+ }
331343 }
332344
333345 res. push ( symbol. clone ( ) ) ;
You can’t perform that action at this time.
0 commit comments