mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Move snake case method to heck
This commit is contained in:
parent
ba8ffab644
commit
66882f1a24
2 changed files with 16 additions and 15 deletions
|
@ -9,6 +9,7 @@ use ra_syntax::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{FileId, FunctionSignature};
|
use crate::{FileId, FunctionSignature};
|
||||||
|
use stdx::to_lower_snake_case;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct InlayHintsConfig {
|
pub struct InlayHintsConfig {
|
||||||
|
@ -279,25 +280,11 @@ fn is_enum_name_similar_to_param_name(
|
||||||
param_name: &str,
|
param_name: &str,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
match sema.type_of_expr(argument).and_then(|t| t.as_adt()) {
|
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,
|
_ => 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<String> {
|
fn get_string_representation(expr: &ast::Expr) -> Option<String> {
|
||||||
match expr {
|
match expr {
|
||||||
ast::Expr::MethodCallExpr(method_call_expr) => {
|
ast::Expr::MethodCallExpr(method_call_expr) => {
|
||||||
|
|
|
@ -102,3 +102,17 @@ pub fn timeit(label: &'static str) -> impl Drop {
|
||||||
|
|
||||||
Guard { label, start: Instant::now() }
|
Guard { label, start: Instant::now() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_lower_snake_case(s: &str) -> 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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue