From 66882f1a249983a1b262a219dbcd47a0e2835418 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 3 May 2020 21:35:21 +0300 Subject: Move snake case method to heck --- crates/ra_ide/src/inlay_hints.rs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'crates/ra_ide/src') 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::{ }; use crate::{FileId, FunctionSignature}; +use stdx::to_lower_snake_case; #[derive(Clone, Debug, PartialEq, Eq)] pub struct InlayHintsConfig { @@ -279,25 +280,11 @@ fn is_enum_name_similar_to_param_name( param_name: &str, ) -> bool { match sema.type_of_expr(argument).and_then(|t| t.as_adt()) { - Some(Adt::Enum(e)) => &camel_case_to_snake_case(e.name(sema.db).to_string()) == param_name, + Some(Adt::Enum(e)) => to_lower_snake_case(&e.name(sema.db).to_string()) == param_name, _ => false, } } -fn camel_case_to_snake_case(s: String) -> String { - let mut buf = String::with_capacity(s.len()); - let mut prev = false; - for c in s.chars() { - if c.is_ascii_uppercase() && prev { - buf.push('_') - } - prev = true; - - buf.push(c.to_ascii_lowercase()); - } - buf -} - fn get_string_representation(expr: &ast::Expr) -> Option { match expr { ast::Expr::MethodCallExpr(method_call_expr) => { -- cgit v1.2.3