diff options
author | Jeremy Kolb <[email protected]> | 2019-02-14 14:15:58 +0000 |
---|---|---|
committer | kjeremy <[email protected]> | 2019-02-14 15:28:48 +0000 |
commit | 1cd59664621def9d0a694505cf095714e49a6761 (patch) | |
tree | a75f2a88894f276e6034e15d33cd27be47bbb130 | |
parent | b85c189500a47f3c5f7690250611b06e08616c9a (diff) |
Be precise about the argument list
Fixes #812
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 1b279615c..c5e8d5843 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use test_utils::tested_by; | 1 | use test_utils::tested_by; |
2 | use ra_db::SourceDatabase; | 2 | use ra_db::SourceDatabase; |
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | AstNode, SyntaxNode, TextUnit, TextRange, | 4 | AstNode, SyntaxNode, TextUnit, |
5 | SyntaxKind::FN_DEF, | 5 | SyntaxKind::FN_DEF, |
6 | ast::{self, ArgListOwner}, | 6 | ast::{self, ArgListOwner}, |
7 | algo::find_node_at_offset, | 7 | algo::find_node_at_offset, |
@@ -38,28 +38,20 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal | |||
38 | } | 38 | } |
39 | } else if num_params > 1 { | 39 | } else if num_params > 1 { |
40 | // Count how many parameters into the call we are. | 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 | if let Some(ref arg_list) = calling_node.arg_list() { | 41 | if let Some(ref arg_list) = calling_node.arg_list() { |
46 | let arg_list_range = arg_list.syntax().range(); | 42 | let arg_list_range = arg_list.syntax().range(); |
47 | if !arg_list_range.contains_inclusive(position.offset) { | 43 | if !arg_list_range.contains_inclusive(position.offset) { |
48 | tested_by!(call_info_bad_offset); | 44 | tested_by!(call_info_bad_offset); |
49 | return None; | 45 | return None; |
50 | } | 46 | } |
51 | let start = arg_list_range.start(); | ||
52 | 47 | ||
53 | let range_search = TextRange::from_to(start, position.offset); | 48 | let param = arg_list |
54 | let mut commas: usize = | 49 | .args() |
55 | arg_list.syntax().text().slice(range_search).to_string().matches(',').count(); | 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. | 54 | call_info.active_parameter = Some(param); |
58 | if has_self { | ||
59 | commas += 1; | ||
60 | } | ||
61 | |||
62 | call_info.active_parameter = Some(commas); | ||
63 | } | 55 | } |
64 | } | 56 | } |
65 | 57 | ||