From 8a51a74556c77d7f228867dd64cd6244bed82be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sat, 18 Apr 2020 10:53:48 +0300 Subject: Omit more parameter hints in the presence of underscores --- crates/ra_ide/src/inlay_hints.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src/inlay_hints.rs') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 45b9f7802..0774fa0a1 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -237,7 +237,8 @@ fn should_show_param_hint( ) -> bool { if param_name.is_empty() || is_argument_similar_to_param(argument, param_name) - || Some(param_name) == fn_signature.name.as_ref().map(String::as_str) + || Some(param_name.trim_start_matches('_')) + == fn_signature.name.as_ref().map(|s| s.trim_start_matches('_')) { return false; } @@ -255,6 +256,8 @@ fn should_show_param_hint( fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool { let argument_string = remove_ref(argument.clone()).syntax().to_string(); + let param_name = param_name.trim_start_matches('_'); + let argument_string = argument_string.trim_start_matches('_'); argument_string.starts_with(¶m_name) || argument_string.ends_with(¶m_name) } @@ -1094,8 +1097,10 @@ struct Param {} fn different_order(param: &Param) {} fn different_order_mut(param: &mut Param) {} +fn has_underscore(_param: bool) {} fn twiddle(twiddle: bool) {} +fn doo(_doo: bool) {} fn main() { let container: TestVarContainer = TestVarContainer { test_var: 42 }; @@ -1112,11 +1117,15 @@ fn main() { test_processed.frob(false); twiddle(true); + doo(true); let param_begin: Param = Param {}; different_order(¶m_begin); different_order(&mut param_begin); + let param: bool = true; + has_underscore(param); + let a: f64 = 7.0; let b: f64 = 4.0; let _: f64 = a.div_euclid(b); -- cgit v1.2.3