From 18ec4e3403854995d44841a066ff3b190d8115e6 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 18 Jan 2020 13:40:32 +0100 Subject: Improve parameter hints a bit & add emacs support - just include the name, not e.g. `mut` - don't return empty hints (or `_`) --- crates/ra_ide/src/display/function_signature.rs | 19 ++++++++++++++++--- crates/ra_ide/src/inlay_hints.rs | 23 +++++++++-------------- 2 files changed, 25 insertions(+), 17 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index ddc53a52b..1e4a472b4 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs @@ -169,9 +169,22 @@ impl From<&'_ ast::FnDef> for FunctionSignature { res.push(self_param.syntax().text().to_string()) } - res.extend(param_list.params().map(|param| { - param.pat().map(|pat| pat.syntax().text().to_string()).unwrap_or_default() - })); + res.extend( + param_list + .params() + .map(|param| { + Some( + param + .pat()? + .syntax() + .descendants() + .find_map(ast::Name::cast)? + .text() + .to_string(), + ) + }) + .map(|param| param.unwrap_or_default()), + ); } res } diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 1b631c7cd..236557541 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -116,7 +116,7 @@ fn get_param_name_hints( let hints = parameters .zip(args) .filter_map(|(param, arg)| { - if arg.syntax().kind() == SyntaxKind::LITERAL { + if arg.syntax().kind() == SyntaxKind::LITERAL && !param.is_empty() { Some((arg.syntax().text_range(), param)) } else { None @@ -683,12 +683,12 @@ fn main() { struct Test {} impl Test { - fn method(&self, param: i32) -> i32 { + fn method(&self, mut param: i32) -> i32 { param * 2 } } -fn test_func(foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 { +fn test_func(mut foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 { foo + bar } @@ -704,37 +704,32 @@ fn main() { assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" [ InlayHint { - range: [207; 218), + range: [215; 226), kind: TypeHint, label: "i32", }, InlayHint { - range: [251; 252), + range: [259; 260), kind: ParameterHint, label: "foo", }, InlayHint { - range: [254; 255), + range: [262; 263), kind: ParameterHint, label: "bar", }, InlayHint { - range: [257; 264), + range: [265; 272), kind: ParameterHint, label: "msg", }, InlayHint { - range: [266; 267), - kind: ParameterHint, - label: "_", - }, - InlayHint { - range: [323; 326), + range: [331; 334), kind: ParameterHint, label: "param", }, InlayHint { - range: [350; 354), + range: [358; 362), kind: ParameterHint, label: "param", }, -- cgit v1.2.3