From 7b34c4c002a96d928794f6d870edc0d01398df99 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 27 Mar 2019 10:00:51 -0400 Subject: Take number of arguments at the call-site into account for signature help Fixes #1065 --- crates/ra_ide_api/src/call_info.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide_api/src/call_info.rs') diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index c5e8d5843..831c4ad12 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -28,6 +28,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option Option 1 { // Count how many parameters into the call we are. - if let Some(ref arg_list) = calling_node.arg_list() { + if let Some(arg_list) = calling_node.arg_list() { + // Number of arguments specified at the caller site + let mut num_args_of_call = arg_list.args().count(); + + // If we are calling a method account for the `self` argument. + if has_self { + num_args_of_call = num_args_of_call + 1; + } + let arg_list_range = arg_list.syntax().range(); if !arg_list_range.contains_inclusive(position.offset) { tested_by!(call_info_bad_offset); @@ -49,6 +58,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option); }"#, assert_eq!(info.active_parameter, Some(1)); } + #[test] + fn test_fn_signature_two_args_empty() { + let info = call_info( + r#"fn foo(x: u32, y: u32) -> u32 {x + y} +fn bar() { foo(<|>); }"#, + ); + + assert_eq!(info.parameters, vec!("x".to_string(), "y".to_string())); + assert_eq!(info.active_parameter, Some(0)); + } + #[test] fn test_fn_signature_for_impl() { let info = call_info( -- cgit v1.2.3 From 80113876e26b5810741b4c18f02177b70f942652 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 27 Mar 2019 11:02:06 -0400 Subject: Simplify --- crates/ra_ide_api/src/call_info.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'crates/ra_ide_api/src/call_info.rs') diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 831c4ad12..29fa7d30b 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -40,13 +40,8 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option 1 { // Count how many parameters into the call we are. if let Some(arg_list) = calling_node.arg_list() { - // Number of arguments specified at the caller site - let mut num_args_of_call = arg_list.args().count(); - - // If we are calling a method account for the `self` argument. - if has_self { - num_args_of_call = num_args_of_call + 1; - } + // Number of arguments specified at the call site + let num_args_at_callsite = arg_list.args().count(); let arg_list_range = arg_list.syntax().range(); if !arg_list_range.contains_inclusive(position.offset) { @@ -54,12 +49,18 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option