|
1 | 1 | use test_utils::tested_by;
|
2 | 2 | use ra_db::SourceDatabase;
|
3 | 3 | use ra_syntax::{
|
4 |
| - AstNode, SyntaxNode, TextUnit, TextRange, |
| 4 | + AstNode, SyntaxNode, TextUnit, |
5 | 5 | SyntaxKind::FN_DEF,
|
6 | 6 | ast::{self, ArgListOwner},
|
7 | 7 | algo::find_node_at_offset,
|
@@ -38,28 +38,20 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
|
38 | 38 | }
|
39 | 39 | } else if num_params > 1 {
|
40 | 40 | // Count how many parameters into the call we are.
|
41 |
| - // TODO: This is best effort for now and should be fixed at some point. |
42 |
| - // It may be better to see where we are in the arg_list and then check |
43 |
| - // where offset is in that list (or beyond). |
44 |
| - // Revisit this after we get documentation comments in. |
45 | 41 | if let Some(ref arg_list) = calling_node.arg_list() {
|
46 | 42 | let arg_list_range = arg_list.syntax().range();
|
47 | 43 | if !arg_list_range.contains_inclusive(position.offset) {
|
48 | 44 | tested_by!(call_info_bad_offset);
|
49 | 45 | return None;
|
50 | 46 | }
|
51 |
| - let start = arg_list_range.start(); |
52 | 47 |
|
53 |
| - let range_search = TextRange::from_to(start, position.offset); |
54 |
| - let mut commas: usize = |
55 |
| - arg_list.syntax().text().slice(range_search).to_string().matches(',').count(); |
| 48 | + let param = arg_list |
| 49 | + .args() |
| 50 | + .position(|arg| arg.syntax().range().contains(position.offset)) |
| 51 | + .or(Some(num_params - 1)) |
| 52 | + .unwrap(); |
56 | 53 |
|
57 |
| - // If we have a method call eat the first param since it's just self. |
58 |
| - if has_self { |
59 |
| - commas += 1; |
60 |
| - } |
61 |
| - |
62 |
| - call_info.active_parameter = Some(commas); |
| 54 | + call_info.active_parameter = Some(param); |
63 | 55 | }
|
64 | 56 | }
|
65 | 57 |
|
|
0 commit comments