diff options
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 17 | ||||
-rw-r--r-- | crates/stdx/src/lib.rs | 14 |
2 files changed, 16 insertions, 15 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 746306428..79c6ff4e1 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -9,6 +9,7 @@ use ra_syntax::{ | |||
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{FileId, FunctionSignature}; | 11 | use crate::{FileId, FunctionSignature}; |
12 | use stdx::to_lower_snake_case; | ||
12 | 13 | ||
13 | #[derive(Clone, Debug, PartialEq, Eq)] | 14 | #[derive(Clone, Debug, PartialEq, Eq)] |
14 | pub struct InlayHintsConfig { | 15 | pub struct InlayHintsConfig { |
@@ -279,25 +280,11 @@ fn is_enum_name_similar_to_param_name( | |||
279 | param_name: &str, | 280 | param_name: &str, |
280 | ) -> bool { | 281 | ) -> bool { |
281 | match sema.type_of_expr(argument).and_then(|t| t.as_adt()) { | 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 | _ => false, | 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 | fn get_string_representation(expr: &ast::Expr) -> Option<String> { | 288 | fn get_string_representation(expr: &ast::Expr) -> Option<String> { |
302 | match expr { | 289 | match expr { |
303 | ast::Expr::MethodCallExpr(method_call_expr) => { | 290 | ast::Expr::MethodCallExpr(method_call_expr) => { |
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 01cdf452c..0f34ce70e 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs | |||
@@ -102,3 +102,17 @@ pub fn timeit(label: &'static str) -> impl Drop { | |||
102 | 102 | ||
103 | Guard { label, start: Instant::now() } | 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 | } | ||