Skip to content

Commit 9d22704

Browse files
bors[bot]kjeremy
andcommitted
Merge #829
829: Be precise about the argument list r=matklad a=kjeremy Fixes #812 Co-authored-by: Jeremy Kolb <[email protected]>
2 parents b85c189 + 1cd5966 commit 9d22704

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

crates/ra_ide_api/src/call_info.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use test_utils::tested_by;
22
use ra_db::SourceDatabase;
33
use ra_syntax::{
4-
AstNode, SyntaxNode, TextUnit, TextRange,
4+
AstNode, SyntaxNode, TextUnit,
55
SyntaxKind::FN_DEF,
66
ast::{self, ArgListOwner},
77
algo::find_node_at_offset,
@@ -38,28 +38,20 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
3838
}
3939
} else if num_params > 1 {
4040
// 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.
4541
if let Some(ref arg_list) = calling_node.arg_list() {
4642
let arg_list_range = arg_list.syntax().range();
4743
if !arg_list_range.contains_inclusive(position.offset) {
4844
tested_by!(call_info_bad_offset);
4945
return None;
5046
}
51-
let start = arg_list_range.start();
5247

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();
5653

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);
6355
}
6456
}
6557

0 commit comments

Comments
 (0)