From ae416f3c6e90a8d2b2f9d1713d2db4ddce12df65 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Thu, 9 Apr 2020 10:35:07 -0400 Subject: clean up param hint checking --- crates/ra_ide/src/inlay_hints.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 1da61e4c4..b1661d238 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -235,19 +235,7 @@ fn should_show_param_hint( param_name: &str, argument: &ast::Expr, ) -> bool { - let argument_string = { - let mut arg_string = argument.syntax().to_string(); - if arg_string.get(0..5) == Some("&mut ") { - arg_string = arg_string[5..].to_string(); - } else if arg_string.get(0..1) == Some("&") { - arg_string = arg_string[1..].to_string(); - } - arg_string - }; - if param_name.is_empty() - || argument_string.ends_with(¶m_name) - || argument_string.starts_with(¶m_name) - { + if param_name.is_empty() || is_argument_similar_to_param(argument, param_name) { return false; } @@ -259,15 +247,27 @@ fn should_show_param_hint( // avoid displaying hints for common functions like map, filter, etc. // or other obvious words used in std + if parameters_len == 1 && is_obvious_param(param_name) { + return false; + } + true +} + +fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool { + let argument_string = if let ast::Expr::RefExpr(ref_expr) = argument { + ref_expr.syntax().last_token().expect("RefExpr should have a last_token").to_string() + } else { + argument.syntax().to_string() + }; + argument_string.starts_with(¶m_name) || argument_string.ends_with(¶m_name) +} + +fn is_obvious_param(param_name: &str) -> bool { let is_obvious_param_name = match param_name { "predicate" | "value" | "pat" | "rhs" | "other" => true, _ => false, }; - if parameters_len == 1 && (param_name.len() == 1 || is_obvious_param_name) { - return false; - } - - true + param_name.len() == 1 || is_obvious_param_name } fn get_fn_signature(sema: &Semantics, expr: &ast::Expr) -> Option { -- cgit v1.2.3