aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-01-18 13:00:43 +0000
committerGitHub <[email protected]>2020-01-18 13:00:43 +0000
commit3a7724e44181ccd5c248589538bd82458b5a9407 (patch)
treee7dfad0f3f90e709580040a3a8894658ee926fe4 /crates
parentd1d91dfe4d52856403a17e2644a22c919690010d (diff)
parent18ec4e3403854995d44841a066ff3b190d8115e6 (diff)
Merge #2875
2875: Improve parameter hints a bit & add emacs support r=matklad a=flodiebold - just include the name, not e.g. `mut` - don't return empty hints (or `_`) CC @brotzeit for the Emacs change Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/display/function_signature.rs19
-rw-r--r--crates/ra_ide/src/inlay_hints.rs23
2 files changed, 25 insertions, 17 deletions
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 {
169 res.push(self_param.syntax().text().to_string()) 169 res.push(self_param.syntax().text().to_string())
170 } 170 }
171 171
172 res.extend(param_list.params().map(|param| { 172 res.extend(
173 param.pat().map(|pat| pat.syntax().text().to_string()).unwrap_or_default() 173 param_list
174 })); 174 .params()
175 .map(|param| {
176 Some(
177 param
178 .pat()?
179 .syntax()
180 .descendants()
181 .find_map(ast::Name::cast)?
182 .text()
183 .to_string(),
184 )
185 })
186 .map(|param| param.unwrap_or_default()),
187 );
175 } 188 }
176 res 189 res
177 } 190 }
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(
116 let hints = parameters 116 let hints = parameters
117 .zip(args) 117 .zip(args)
118 .filter_map(|(param, arg)| { 118 .filter_map(|(param, arg)| {
119 if arg.syntax().kind() == SyntaxKind::LITERAL { 119 if arg.syntax().kind() == SyntaxKind::LITERAL && !param.is_empty() {
120 Some((arg.syntax().text_range(), param)) 120 Some((arg.syntax().text_range(), param))
121 } else { 121 } else {
122 None 122 None
@@ -683,12 +683,12 @@ fn main() {
683struct Test {} 683struct Test {}
684 684
685impl Test { 685impl Test {
686 fn method(&self, param: i32) -> i32 { 686 fn method(&self, mut param: i32) -> i32 {
687 param * 2 687 param * 2
688 } 688 }
689} 689}
690 690
691fn test_func(foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 { 691fn test_func(mut foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 {
692 foo + bar 692 foo + bar
693} 693}
694 694
@@ -704,37 +704,32 @@ fn main() {
704 assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###" 704 assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###"
705 [ 705 [
706 InlayHint { 706 InlayHint {
707 range: [207; 218), 707 range: [215; 226),
708 kind: TypeHint, 708 kind: TypeHint,
709 label: "i32", 709 label: "i32",
710 }, 710 },
711 InlayHint { 711 InlayHint {
712 range: [251; 252), 712 range: [259; 260),
713 kind: ParameterHint, 713 kind: ParameterHint,
714 label: "foo", 714 label: "foo",
715 }, 715 },
716 InlayHint { 716 InlayHint {
717 range: [254; 255), 717 range: [262; 263),
718 kind: ParameterHint, 718 kind: ParameterHint,
719 label: "bar", 719 label: "bar",
720 }, 720 },
721 InlayHint { 721 InlayHint {
722 range: [257; 264), 722 range: [265; 272),
723 kind: ParameterHint, 723 kind: ParameterHint,
724 label: "msg", 724 label: "msg",
725 }, 725 },
726 InlayHint { 726 InlayHint {
727 range: [266; 267), 727 range: [331; 334),
728 kind: ParameterHint,
729 label: "_",
730 },
731 InlayHint {
732 range: [323; 326),
733 kind: ParameterHint, 728 kind: ParameterHint,
734 label: "param", 729 label: "param",
735 }, 730 },
736 InlayHint { 731 InlayHint {
737 range: [350; 354), 732 range: [358; 362),
738 kind: ParameterHint, 733 kind: ParameterHint,
739 label: "param", 734 label: "param",
740 }, 735 },