From 6c676909dd94f48ab1e85427071b508f104f360f Mon Sep 17 00:00:00 2001 From: Yuki Kodama Date: Sun, 24 May 2020 18:09:42 +0900 Subject: Strip leading underscore --- crates/ra_ide/src/display/function_signature.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index 9572debd8..4f054398a 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -187,6 +187,14 @@ impl FunctionSignature { impl From<&'_ ast::FnDef> for FunctionSignature { fn from(node: &ast::FnDef) -> FunctionSignature { + fn strip_leading_underscore(name: String) -> String { + if name.starts_with("_") { + name.get(1..).unwrap_or_default().to_string() + } else { + name + } + } + fn param_list(node: &ast::FnDef) -> (bool, Vec, Vec) { let mut res = vec![]; let mut res_types = vec![]; @@ -230,7 +238,7 @@ impl From<&'_ ast::FnDef> for FunctionSignature { param_list .params() .map(|param| { - Some( + Some(strip_leading_underscore( param .pat()? .syntax() @@ -238,7 +246,7 @@ impl From<&'_ ast::FnDef> for FunctionSignature { .find_map(ast::Name::cast)? .text() .to_string(), - ) + )) }) .map(|param| param.unwrap_or_default()), ); -- cgit v1.2.3