File tree Expand file tree Collapse file tree 2 files changed +16
-15
lines changed Expand file tree Collapse file tree 2 files changed +16
-15
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ use ra_syntax::{
9
9
} ;
10
10
11
11
use crate :: { FileId , FunctionSignature } ;
12
+ use stdx:: to_lower_snake_case;
12
13
13
14
#[ derive( Clone , Debug , PartialEq , Eq ) ]
14
15
pub struct InlayHintsConfig {
@@ -279,25 +280,11 @@ fn is_enum_name_similar_to_param_name(
279
280
param_name : & str ,
280
281
) -> bool {
281
282
match sema. type_of_expr ( argument) . and_then ( |t| t. as_adt ( ) ) {
282
- Some ( Adt :: Enum ( e) ) => & camel_case_to_snake_case ( e. name ( sema. db ) . to_string ( ) ) == param_name,
283
+ Some ( Adt :: Enum ( e) ) => to_lower_snake_case ( & e. name ( sema. db ) . to_string ( ) ) == param_name,
283
284
_ => false ,
284
285
}
285
286
}
286
287
287
- fn camel_case_to_snake_case ( s : String ) -> String {
288
- let mut buf = String :: with_capacity ( s. len ( ) ) ;
289
- let mut prev = false ;
290
- for c in s. chars ( ) {
291
- if c. is_ascii_uppercase ( ) && prev {
292
- buf. push ( '_' )
293
- }
294
- prev = true ;
295
-
296
- buf. push ( c. to_ascii_lowercase ( ) ) ;
297
- }
298
- buf
299
- }
300
-
301
288
fn get_string_representation ( expr : & ast:: Expr ) -> Option < String > {
302
289
match expr {
303
290
ast:: Expr :: MethodCallExpr ( method_call_expr) => {
Original file line number Diff line number Diff line change @@ -102,3 +102,17 @@ pub fn timeit(label: &'static str) -> impl Drop {
102
102
103
103
Guard { label, start : Instant :: now ( ) }
104
104
}
105
+
106
+ pub fn to_lower_snake_case ( s : & str ) -> String {
107
+ let mut buf = String :: with_capacity ( s. len ( ) ) ;
108
+ let mut prev = false ;
109
+ for c in s. chars ( ) {
110
+ if c. is_ascii_uppercase ( ) && prev {
111
+ buf. push ( '_' )
112
+ }
113
+ prev = true ;
114
+
115
+ buf. push ( c. to_ascii_lowercase ( ) ) ;
116
+ }
117
+ buf
118
+ }
You can’t perform that action at this time.
0 commit comments