From 78c3e4a23cb300cb415b4cb41851adb1a9fe5fb4 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 22 Oct 2020 19:42:39 +0200 Subject: Hide paramater inlay hints for cloned vars if applicable --- crates/ide/src/inlay_hints.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'crates/ide') diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index cccea129a..49d8e4ae1 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -378,7 +378,11 @@ fn is_enum_name_similar_to_param_name( fn get_string_representation(expr: &ast::Expr) -> Option { match expr { ast::Expr::MethodCallExpr(method_call_expr) => { - Some(method_call_expr.name_ref()?.to_string()) + let name_ref = method_call_expr.name_ref()?; + match name_ref.text().as_str() { + "clone" => method_call_expr.receiver().map(|rec| rec.to_string()), + name_ref => Some(name_ref.to_owned()), + } } ast::Expr::RefExpr(ref_expr) => get_string_representation(&ref_expr.expr()?), _ => Some(expr.to_string()), @@ -1205,6 +1209,29 @@ fn main() { let iter_of_iters = some_iter.take(2); //^^^^^^^^^^^^^ impl Iterator> } +"#, + ); + } + + #[test] + fn hide_param_hints_for_clones() { + check_with_config( + InlayHintsConfig { + parameter_hints: true, + type_hints: false, + chaining_hints: false, + max_length: None, + }, + r#" +fn foo(bar: i32, baz: String, qux: f32) {} + +fn main() { + let bar = 3; + let baz = &"baz"; + let fez = 1.0; + foo(bar.clone(), baz.clone(), fez.clone()); + //^^^^^^^^^^^ qux +} "#, ); } -- cgit v1.2.3