@@ -288,11 +288,9 @@ fn fst_path(db: &dyn DefDatabase, path: &ImportPath) -> String {
288
288
289
289
/// A way to match import map contents against the search query.
290
290
#[ derive( Debug ) ]
291
- pub enum SearchMode {
291
+ enum SearchMode {
292
292
/// Import map entry should strictly match the query string.
293
- Equals ,
294
- /// Import map entry should contain the query string.
295
- Contains ,
293
+ Exact ,
296
294
/// Import map entry should contain all letters from the query string,
297
295
/// in the same order, but not necessary adjacent.
298
296
Fuzzy ,
@@ -325,16 +323,16 @@ impl Query {
325
323
Self {
326
324
query,
327
325
lowercased,
328
- search_mode : SearchMode :: Contains ,
326
+ search_mode : SearchMode :: Exact ,
329
327
assoc_mode : AssocSearchMode :: Include ,
330
328
case_sensitive : false ,
331
- limit : usize:: max_value ( ) ,
329
+ limit : usize:: MAX ,
332
330
}
333
331
}
334
332
335
- /// Specifies the way to search for the entries using the query .
336
- pub fn search_mode ( self , search_mode : SearchMode ) -> Self {
337
- Self { search_mode, ..self }
333
+ /// Fuzzy finds items instead of exact matching .
334
+ pub fn fuzzy ( self ) -> Self {
335
+ Self { search_mode : SearchMode :: Fuzzy , ..self }
338
336
}
339
337
340
338
/// Specifies whether we want to include associated items in the result.
@@ -374,22 +372,15 @@ impl Query {
374
372
let query_string = if case_insensitive { & self . lowercased } else { & self . query } ;
375
373
376
374
match self . search_mode {
377
- SearchMode :: Equals => & input == query_string,
378
- SearchMode :: Contains => input. contains ( query_string) ,
375
+ SearchMode :: Exact => & input == query_string,
379
376
SearchMode :: Fuzzy => {
380
- let mut unchecked_query_chars = query_string. chars ( ) ;
381
- let mut mismatching_query_char = unchecked_query_chars. next ( ) ;
382
-
383
- for input_char in input. chars ( ) {
384
- match mismatching_query_char {
385
- None => return true ,
386
- Some ( matching_query_char) if matching_query_char == input_char => {
387
- mismatching_query_char = unchecked_query_chars. next ( ) ;
388
- }
389
- _ => ( ) ,
377
+ let mut input_chars = input. chars ( ) ;
378
+ for query_char in query_string. chars ( ) {
379
+ if input_chars. find ( |& it| it == query_char) . is_none ( ) {
380
+ return false ;
390
381
}
391
382
}
392
- mismatching_query_char . is_none ( )
383
+ true
393
384
}
394
385
}
395
386
}
@@ -824,7 +815,7 @@ mod tests {
824
815
check_search (
825
816
ra_fixture,
826
817
"main" ,
827
- Query :: new ( "fmt" . to_string ( ) ) . search_mode ( SearchMode :: Fuzzy ) ,
818
+ Query :: new ( "fmt" . to_string ( ) ) . fuzzy ( ) ,
828
819
expect ! [ [ r#"
829
820
dep::fmt (t)
830
821
dep::fmt::Display::FMT_CONST (a)
@@ -854,7 +845,7 @@ mod tests {
854
845
ra_fixture,
855
846
"main" ,
856
847
Query :: new ( "fmt" . to_string ( ) )
857
- . search_mode ( SearchMode :: Fuzzy )
848
+ . fuzzy ( )
858
849
. assoc_search_mode ( AssocSearchMode :: AssocItemsOnly ) ,
859
850
expect ! [ [ r#"
860
851
dep::fmt::Display::FMT_CONST (a)
@@ -866,9 +857,7 @@ mod tests {
866
857
check_search (
867
858
ra_fixture,
868
859
"main" ,
869
- Query :: new ( "fmt" . to_string ( ) )
870
- . search_mode ( SearchMode :: Fuzzy )
871
- . assoc_search_mode ( AssocSearchMode :: Exclude ) ,
860
+ Query :: new ( "fmt" . to_string ( ) ) . fuzzy ( ) . assoc_search_mode ( AssocSearchMode :: Exclude ) ,
872
861
expect ! [ [ r#"
873
862
dep::fmt (t)
874
863
"# ] ] ,
@@ -904,7 +893,7 @@ mod tests {
904
893
check_search (
905
894
ra_fixture,
906
895
"main" ,
907
- Query :: new ( "fmt" . to_string ( ) ) . search_mode ( SearchMode :: Fuzzy ) ,
896
+ Query :: new ( "fmt" . to_string ( ) ) . fuzzy ( ) ,
908
897
expect ! [ [ r#"
909
898
dep::Fmt (m)
910
899
dep::Fmt (t)
@@ -918,20 +907,7 @@ mod tests {
918
907
check_search (
919
908
ra_fixture,
920
909
"main" ,
921
- Query :: new ( "fmt" . to_string ( ) ) . search_mode ( SearchMode :: Equals ) ,
922
- expect ! [ [ r#"
923
- dep::Fmt (m)
924
- dep::Fmt (t)
925
- dep::Fmt (v)
926
- dep::fmt (t)
927
- dep::fmt::Display::fmt (a)
928
- "# ] ] ,
929
- ) ;
930
-
931
- check_search (
932
- ra_fixture,
933
- "main" ,
934
- Query :: new ( "fmt" . to_string ( ) ) . search_mode ( SearchMode :: Contains ) ,
910
+ Query :: new ( "fmt" . to_string ( ) ) ,
935
911
expect ! [ [ r#"
936
912
dep::Fmt (m)
937
913
dep::Fmt (t)
@@ -1049,7 +1025,7 @@ mod tests {
1049
1025
pub fn no() {}
1050
1026
"# ,
1051
1027
"main" ,
1052
- Query :: new ( "" . to_string ( ) ) . limit ( 2 ) ,
1028
+ Query :: new ( "" . to_string ( ) ) . fuzzy ( ) . limit ( 2 ) ,
1053
1029
expect ! [ [ r#"
1054
1030
dep::Fmt (m)
1055
1031
dep::Fmt (t)
0 commit comments