aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/call_info.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/call_info.rs')
-rw-r--r--crates/ra_ide/src/call_info.rs59
1 files changed, 31 insertions, 28 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs
index a7023529b..72a68522e 100644
--- a/crates/ra_ide/src/call_info.rs
+++ b/crates/ra_ide/src/call_info.rs
@@ -1,10 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2
3use hir::db::AstDatabase; 2use hir::db::AstDatabase;
4use ra_syntax::{ 3use ra_syntax::{
5 ast::{self, ArgListOwner}, 4 ast::{self, ArgListOwner},
6 match_ast, AstNode, SyntaxNode, 5 match_ast, AstNode, SyntaxNode,
7}; 6};
7
8use test_utils::tested_by; 8use test_utils::tested_by;
9 9
10use crate::{ 10use crate::{
@@ -51,36 +51,39 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
51 // If we have a calling expression let's find which argument we are on 51 // If we have a calling expression let's find which argument we are on
52 let num_params = call_info.parameters().len(); 52 let num_params = call_info.parameters().len();
53 53
54 if num_params == 1 { 54 match num_params {
55 if !has_self { 55 0 => (),
56 call_info.active_parameter = Some(0); 56 1 => {
57 } 57 if !has_self {
58 } else if num_params > 1 { 58 call_info.active_parameter = Some(0);
59 // Count how many parameters into the call we are.
60 if let Some(arg_list) = calling_node.arg_list() {
61 // Number of arguments specified at the call site
62 let num_args_at_callsite = arg_list.args().count();
63
64 let arg_list_range = arg_list.syntax().text_range();
65 if !arg_list_range.contains_inclusive(position.offset) {
66 tested_by!(call_info_bad_offset);
67 return None;
68 } 59 }
60 }
61 _ => {
62 if let Some(arg_list) = calling_node.arg_list() {
63 // Number of arguments specified at the call site
64 let num_args_at_callsite = arg_list.args().count();
65
66 let arg_list_range = arg_list.syntax().text_range();
67 if !arg_list_range.contains_inclusive(position.offset) {
68 tested_by!(call_info_bad_offset);
69 return None;
70 }
69 71
70 let mut param = std::cmp::min( 72 let mut param = std::cmp::min(
71 num_args_at_callsite, 73 num_args_at_callsite,
72 arg_list 74 arg_list
73 .args() 75 .args()
74 .take_while(|arg| arg.syntax().text_range().end() < position.offset) 76 .take_while(|arg| arg.syntax().text_range().end() < position.offset)
75 .count(), 77 .count(),
76 ); 78 );
77 79
78 // If we are in a method account for `self` 80 // If we are in a method account for `self`
79 if has_self { 81 if has_self {
80 param += 1; 82 param += 1;
81 } 83 }
82 84
83 call_info.active_parameter = Some(param); 85 call_info.active_parameter = Some(param);
86 }
84 } 87 }
85 } 88 }
86 89