aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/inlay_hints.rs36
1 files changed, 18 insertions, 18 deletions
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(
235 param_name: &str, 235 param_name: &str,
236 argument: &ast::Expr, 236 argument: &ast::Expr,
237) -> bool { 237) -> bool {
238 let argument_string = { 238 if param_name.is_empty() || is_argument_similar_to_param(argument, param_name) {
239 let mut arg_string = argument.syntax().to_string();
240 if arg_string.get(0..5) == Some("&mut ") {
241 arg_string = arg_string[5..].to_string();
242 } else if arg_string.get(0..1) == Some("&") {
243 arg_string = arg_string[1..].to_string();
244 }
245 arg_string
246 };
247 if param_name.is_empty()
248 || argument_string.ends_with(&param_name)
249 || argument_string.starts_with(&param_name)
250 {
251 return false; 239 return false;
252 } 240 }
253 241
@@ -259,15 +247,27 @@ fn should_show_param_hint(
259 247
260 // avoid displaying hints for common functions like map, filter, etc. 248 // avoid displaying hints for common functions like map, filter, etc.
261 // or other obvious words used in std 249 // or other obvious words used in std
250 if parameters_len == 1 && is_obvious_param(param_name) {
251 return false;
252 }
253 true
254}
255
256fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool {
257 let argument_string = if let ast::Expr::RefExpr(ref_expr) = argument {
258 ref_expr.syntax().last_token().expect("RefExpr should have a last_token").to_string()
259 } else {
260 argument.syntax().to_string()
261 };
262 argument_string.starts_with(&param_name) || argument_string.ends_with(&param_name)
263}
264
265fn is_obvious_param(param_name: &str) -> bool {
262 let is_obvious_param_name = match param_name { 266 let is_obvious_param_name = match param_name {
263 "predicate" | "value" | "pat" | "rhs" | "other" => true, 267 "predicate" | "value" | "pat" | "rhs" | "other" => true,
264 _ => false, 268 _ => false,
265 }; 269 };
266 if parameters_len == 1 && (param_name.len() == 1 || is_obvious_param_name) { 270 param_name.len() == 1 || is_obvious_param_name
267 return false;
268 }
269
270 true
271} 271}
272 272
273fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<FunctionSignature> { 273fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<FunctionSignature> {