|
1 | 1 | //! FIXME: write short doc here |
2 | | -
|
3 | 2 | use hir::db::AstDatabase; |
4 | 3 | use ra_syntax::{ |
5 | 4 | ast::{self, ArgListOwner}, |
6 | 5 | match_ast, AstNode, SyntaxNode, |
7 | 6 | }; |
| 7 | + |
8 | 8 | use test_utils::tested_by; |
9 | 9 |
|
10 | 10 | use crate::{ |
@@ -51,36 +51,39 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal |
51 | 51 | // If we have a calling expression let's find which argument we are on |
52 | 52 | let num_params = call_info.parameters().len(); |
53 | 53 |
|
54 | | - if num_params == 1 { |
55 | | - if !has_self { |
56 | | - call_info.active_parameter = Some(0); |
57 | | - } |
58 | | - } else if num_params > 1 { |
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; |
| 54 | + match num_params { |
| 55 | + 0 => (), |
| 56 | + 1 => { |
| 57 | + if !has_self { |
| 58 | + call_info.active_parameter = Some(0); |
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( |
71 | | - num_args_at_callsite, |
72 | | - arg_list |
73 | | - .args() |
74 | | - .take_while(|arg| arg.syntax().text_range().end() < position.offset) |
75 | | - .count(), |
76 | | - ); |
77 | | - |
78 | | - // If we are in a method account for `self` |
79 | | - if has_self { |
80 | | - param += 1; |
81 | | - } |
| 72 | + let mut param = std::cmp::min( |
| 73 | + num_args_at_callsite, |
| 74 | + arg_list |
| 75 | + .args() |
| 76 | + .take_while(|arg| arg.syntax().text_range().end() < position.offset) |
| 77 | + .count(), |
| 78 | + ); |
| 79 | + |
| 80 | + // If we are in a method account for `self` |
| 81 | + if has_self { |
| 82 | + param += 1; |
| 83 | + } |
82 | 84 |
|
83 | | - call_info.active_parameter = Some(param); |
| 85 | + call_info.active_parameter = Some(param); |
| 86 | + } |
84 | 87 | } |
85 | 88 | } |
86 | 89 |
|
|
0 commit comments