aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-05-03 19:35:21 +0100
committerKirill Bulatov <[email protected]>2020-05-03 19:35:21 +0100
commit66882f1a249983a1b262a219dbcd47a0e2835418 (patch)
tree57e672bb5bc4a0aba430740650ce29fdc1982db1 /crates/ra_ide
parentba8ffab6444e0a6f4b9e5254adbef2adc6169cf9 (diff)
Move snake case method to heck
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/inlay_hints.rs17
1 files changed, 2 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
11use crate::{FileId, FunctionSignature}; 11use crate::{FileId, FunctionSignature};
12use stdx::to_lower_snake_case;
12 13
13#[derive(Clone, Debug, PartialEq, Eq)] 14#[derive(Clone, Debug, PartialEq, Eq)]
14pub struct InlayHintsConfig { 15pub 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
287fn 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
301fn get_string_representation(expr: &ast::Expr) -> Option<String> { 288fn 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) => {