aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/call_info.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-08 15:43:29 +0000
committerAleksey Kladov <[email protected]>2019-01-08 15:43:29 +0000
commit6f02f176c87ef2d9f22b27800ae56289c6423db4 (patch)
tree88f056407bdffc6c34ee522eb12fb096b4fe5c3e /crates/ra_analysis/src/call_info.rs
parentdb794abe666f9f895ef0577d49eb4db12479ad46 (diff)
simplify
Diffstat (limited to 'crates/ra_analysis/src/call_info.rs')
-rw-r--r--crates/ra_analysis/src/call_info.rs80
1 files changed, 37 insertions, 43 deletions
diff --git a/crates/ra_analysis/src/call_info.rs b/crates/ra_analysis/src/call_info.rs
index 9111fdc69..edb87be11 100644
--- a/crates/ra_analysis/src/call_info.rs
+++ b/crates/ra_analysis/src/call_info.rs
@@ -21,53 +21,47 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable
21 21
22 // Resolve the function's NameRef (NOTE: this isn't entirely accurate). 22 // Resolve the function's NameRef (NOTE: this isn't entirely accurate).
23 let file_symbols = db.index_resolve(name_ref)?; 23 let file_symbols = db.index_resolve(name_ref)?;
24 for symbol in file_symbols { 24 let symbol = ctry!(file_symbols.into_iter().find(|it| it.ptr.kind() == FN_DEF));
25 if symbol.ptr.kind() == FN_DEF { 25 let fn_file = db.source_file(symbol.file_id);
26 let fn_file = db.source_file(symbol.file_id); 26 let fn_def = symbol.ptr.resolve(&fn_file);
27 let fn_def = symbol.ptr.resolve(&fn_file); 27 let fn_def = ast::FnDef::cast(&fn_def).unwrap();
28 let fn_def = ast::FnDef::cast(&fn_def).unwrap(); 28 let mut call_info = ctry!(CallInfo::new(fn_def));
29 if let Some(mut call_info) = CallInfo::new(fn_def) { 29 // If we have a calling expression let's find which argument we are on
30 // If we have a calling expression let's find which argument we are on 30 let num_params = call_info.parameters.len();
31 let num_params = call_info.parameters.len(); 31 let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some();
32 let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some(); 32
33 33 if num_params == 1 {
34 if num_params == 1 { 34 if !has_self {
35 if !has_self { 35 call_info.active_parameter = Some(0);
36 call_info.active_parameter = Some(0); 36 }
37 } 37 } else if num_params > 1 {
38 } else if num_params > 1 { 38 // Count how many parameters into the call we are.
39 // 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 // 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 // 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 // where offset is in that list (or beyond). 42 // Revisit this after we get documentation comments in.
43 // Revisit this after we get documentation comments in. 43 if let Some(ref arg_list) = calling_node.arg_list() {
44 if let Some(ref arg_list) = calling_node.arg_list() { 44 let start = arg_list.syntax().range().start();
45 let start = arg_list.syntax().range().start(); 45
46 46 let range_search = TextRange::from_to(start, position.offset);
47 let range_search = TextRange::from_to(start, position.offset); 47 let mut commas: usize = arg_list
48 let mut commas: usize = arg_list 48 .syntax()
49 .syntax() 49 .text()
50 .text() 50 .slice(range_search)
51 .slice(range_search) 51 .to_string()
52 .to_string() 52 .matches(',')
53 .matches(',') 53 .count();
54 .count(); 54
55 55 // If we have a method call eat the first param since it's just self.
56 // If we have a method call eat the first param since it's just self. 56 if has_self {
57 if has_self { 57 commas += 1;
58 commas += 1;
59 }
60
61 call_info.active_parameter = Some(commas);
62 }
63 }
64
65 return Ok(Some(call_info));
66 } 58 }
59
60 call_info.active_parameter = Some(commas);
67 } 61 }
68 } 62 }
69 63
70 Ok(None) 64 Ok(Some(call_info))
71} 65}
72 66
73enum FnCallNode<'a> { 67enum FnCallNode<'a> {