diff options
author | IceSentry <[email protected]> | 2020-04-09 15:35:07 +0100 |
---|---|---|
committer | IceSentry <[email protected]> | 2020-04-09 15:35:07 +0100 |
commit | ae416f3c6e90a8d2b2f9d1713d2db4ddce12df65 (patch) | |
tree | 257a014a6f062f680156e448543b01ee6f400e05 /crates/ra_ide/src | |
parent | cba694c60276f7543ee9ed1dddf3fe93209f527f (diff) |
clean up param hint checking
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 36 |
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(¶m_name) | ||
249 | || argument_string.starts_with(¶m_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 | |||
256 | fn 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(¶m_name) || argument_string.ends_with(¶m_name) | ||
263 | } | ||
264 | |||
265 | fn 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 | ||
273 | fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<FunctionSignature> { | 273 | fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<FunctionSignature> { |