@@ -68,22 +68,29 @@ pub struct FirstSegmentUnresolved {
68
68
pub enum NameToImport {
69
69
/// Requires items with names that exactly match the given string, bool indicates case-sensitivity.
70
70
Exact ( String , bool ) ,
71
- /// Requires items with names that case-insensitively contain all letters from the string,
71
+ /// Requires items with names that match the given string by prefix, bool indicates case-sensitivity.
72
+ Prefix ( String , bool ) ,
73
+ /// Requires items with names contain all letters from the string,
72
74
/// in the same order, but not necessary adjacent.
73
- Fuzzy ( String ) ,
75
+ Fuzzy ( String , bool ) ,
74
76
}
75
77
76
78
impl NameToImport {
77
79
pub fn exact_case_sensitive ( s : String ) -> NameToImport {
78
80
NameToImport :: Exact ( s, true )
79
81
}
80
- }
81
82
82
- impl NameToImport {
83
+ pub fn fuzzy ( s : String ) -> NameToImport {
84
+ // unless all chars are lowercase, we do a case sensitive search
85
+ let case_sensitive = s. chars ( ) . any ( |c| c. is_uppercase ( ) ) ;
86
+ NameToImport :: Fuzzy ( s, case_sensitive)
87
+ }
88
+
83
89
pub fn text ( & self ) -> & str {
84
90
match self {
85
- NameToImport :: Exact ( text, _) => text. as_str ( ) ,
86
- NameToImport :: Fuzzy ( text) => text. as_str ( ) ,
91
+ NameToImport :: Prefix ( text, _)
92
+ | NameToImport :: Exact ( text, _)
93
+ | NameToImport :: Fuzzy ( text, _) => text. as_str ( ) ,
87
94
}
88
95
}
89
96
}
@@ -165,7 +172,7 @@ impl ImportAssets {
165
172
Some ( Self {
166
173
import_candidate : ImportCandidate :: TraitMethod ( TraitImportCandidate {
167
174
receiver_ty,
168
- assoc_item_name : NameToImport :: Fuzzy ( fuzzy_method_name) ,
175
+ assoc_item_name : NameToImport :: fuzzy ( fuzzy_method_name) ,
169
176
} ) ,
170
177
module_with_candidate : module_with_method_call,
171
178
candidate_node,
@@ -228,12 +235,30 @@ impl ImportAssets {
228
235
self . search_for ( sema, None , prefer_no_std)
229
236
}
230
237
231
- pub fn path_fuzzy_name_to_exact ( & mut self , case_sensitive : bool ) {
238
+ /// Requires imports to by prefix instead of fuzzily.
239
+ pub fn path_fuzzy_name_to_prefix ( & mut self ) {
240
+ if let ImportCandidate :: Path ( PathImportCandidate { name : to_import, .. } ) =
241
+ & mut self . import_candidate
242
+ {
243
+ let ( name, case_sensitive) = match to_import {
244
+ NameToImport :: Fuzzy ( name, case_sensitive) => {
245
+ ( std:: mem:: take ( name) , * case_sensitive)
246
+ }
247
+ _ => return ,
248
+ } ;
249
+ * to_import = NameToImport :: Prefix ( name, case_sensitive) ;
250
+ }
251
+ }
252
+
253
+ /// Requires imports to match exactly instead of fuzzily.
254
+ pub fn path_fuzzy_name_to_exact ( & mut self ) {
232
255
if let ImportCandidate :: Path ( PathImportCandidate { name : to_import, .. } ) =
233
256
& mut self . import_candidate
234
257
{
235
- let name = match to_import {
236
- NameToImport :: Fuzzy ( name) => std:: mem:: take ( name) ,
258
+ let ( name, case_sensitive) = match to_import {
259
+ NameToImport :: Fuzzy ( name, case_sensitive) => {
260
+ ( std:: mem:: take ( name) , * case_sensitive)
261
+ }
237
262
_ => return ,
238
263
} ;
239
264
* to_import = NameToImport :: Exact ( name, case_sensitive) ;
@@ -623,7 +648,7 @@ impl ImportCandidate {
623
648
fuzzy_name : String ,
624
649
sema : & Semantics < ' _ , RootDatabase > ,
625
650
) -> Option < Self > {
626
- path_import_candidate ( sema, qualifier, NameToImport :: Fuzzy ( fuzzy_name) )
651
+ path_import_candidate ( sema, qualifier, NameToImport :: fuzzy ( fuzzy_name) )
627
652
}
628
653
}
629
654
0 commit comments