Skip to content

Commit 6f02f17

Browse files
committed
simplify
1 parent db794ab commit 6f02f17

File tree

1 file changed

+37
-43
lines changed

1 file changed

+37
-43
lines changed

crates/ra_analysis/src/call_info.rs

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,47 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable
2121

2222
// Resolve the function's NameRef (NOTE: this isn't entirely accurate).
2323
let file_symbols = db.index_resolve(name_ref)?;
24-
for symbol in file_symbols {
25-
if symbol.ptr.kind() == FN_DEF {
26-
let fn_file = db.source_file(symbol.file_id);
27-
let fn_def = symbol.ptr.resolve(&fn_file);
28-
let fn_def = ast::FnDef::cast(&fn_def).unwrap();
29-
if let Some(mut call_info) = CallInfo::new(fn_def) {
30-
// If we have a calling expression let's find which argument we are on
31-
let num_params = call_info.parameters.len();
32-
let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some();
33-
34-
if num_params == 1 {
35-
if !has_self {
36-
call_info.active_parameter = Some(0);
37-
}
38-
} else if num_params > 1 {
39-
// Count how many parameters into the call we are.
40-
// TODO: This is best effort for now and should be fixed at some point.
41-
// It may be better to see where we are in the arg_list and then check
42-
// where offset is in that list (or beyond).
43-
// Revisit this after we get documentation comments in.
44-
if let Some(ref arg_list) = calling_node.arg_list() {
45-
let start = arg_list.syntax().range().start();
46-
47-
let range_search = TextRange::from_to(start, position.offset);
48-
let mut commas: usize = arg_list
49-
.syntax()
50-
.text()
51-
.slice(range_search)
52-
.to_string()
53-
.matches(',')
54-
.count();
55-
56-
// If we have a method call eat the first param since it's just self.
57-
if has_self {
58-
commas += 1;
59-
}
60-
61-
call_info.active_parameter = Some(commas);
62-
}
63-
}
64-
65-
return Ok(Some(call_info));
24+
let symbol = ctry!(file_symbols.into_iter().find(|it| it.ptr.kind() == FN_DEF));
25+
let fn_file = db.source_file(symbol.file_id);
26+
let fn_def = symbol.ptr.resolve(&fn_file);
27+
let fn_def = ast::FnDef::cast(&fn_def).unwrap();
28+
let mut call_info = ctry!(CallInfo::new(fn_def));
29+
// If we have a calling expression let's find which argument we are on
30+
let num_params = call_info.parameters.len();
31+
let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some();
32+
33+
if num_params == 1 {
34+
if !has_self {
35+
call_info.active_parameter = Some(0);
36+
}
37+
} else if num_params > 1 {
38+
// Count how many parameters into the call we are.
39+
// TODO: This is best effort for now and should be fixed at some point.
40+
// It may be better to see where we are in the arg_list and then check
41+
// where offset is in that list (or beyond).
42+
// Revisit this after we get documentation comments in.
43+
if let Some(ref arg_list) = calling_node.arg_list() {
44+
let start = arg_list.syntax().range().start();
45+
46+
let range_search = TextRange::from_to(start, position.offset);
47+
let mut commas: usize = arg_list
48+
.syntax()
49+
.text()
50+
.slice(range_search)
51+
.to_string()
52+
.matches(',')
53+
.count();
54+
55+
// If we have a method call eat the first param since it's just self.
56+
if has_self {
57+
commas += 1;
6658
}
59+
60+
call_info.active_parameter = Some(commas);
6761
}
6862
}
6963

70-
Ok(None)
64+
Ok(Some(call_info))
7165
}
7266

7367
enum FnCallNode<'a> {

0 commit comments

Comments
 (0)