aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/call_info.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/call_info.rs')
-rw-r--r--crates/ra_ide_api/src/call_info.rs38
1 files changed, 9 insertions, 29 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs
index a59ab7853..1b279615c 100644
--- a/crates/ra_ide_api/src/call_info.rs
+++ b/crates/ra_ide_api/src/call_info.rs
@@ -21,9 +21,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
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 = crate::symbol_index::index_resolve(db, name_ref); 23 let file_symbols = crate::symbol_index::index_resolve(db, name_ref);
24 let symbol = file_symbols 24 let symbol = file_symbols.into_iter().find(|it| it.ptr.kind() == FN_DEF)?;
25 .into_iter()
26 .find(|it| it.ptr.kind() == FN_DEF)?;
27 let fn_file = db.parse(symbol.file_id); 25 let fn_file = db.parse(symbol.file_id);
28 let fn_def = symbol.ptr.to_node(&fn_file); 26 let fn_def = symbol.ptr.to_node(&fn_file);
29 let fn_def = ast::FnDef::cast(fn_def).unwrap(); 27 let fn_def = ast::FnDef::cast(fn_def).unwrap();
@@ -53,13 +51,8 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
53 let start = arg_list_range.start(); 51 let start = arg_list_range.start();
54 52
55 let range_search = TextRange::from_to(start, position.offset); 53 let range_search = TextRange::from_to(start, position.offset);
56 let mut commas: usize = arg_list 54 let mut commas: usize =
57 .syntax() 55 arg_list.syntax().text().slice(range_search).to_string().matches(',').count();
58 .text()
59 .slice(range_search)
60 .to_string()
61 .matches(',')
62 .count();
63 56
64 // If we have a method call eat the first param since it's just self. 57 // If we have a method call eat the first param since it's just self.
65 if has_self { 58 if has_self {
@@ -96,11 +89,9 @@ impl<'a> FnCallNode<'a> {
96 _ => return None, 89 _ => return None,
97 }), 90 }),
98 91
99 FnCallNode::MethodCallExpr(call_expr) => call_expr 92 FnCallNode::MethodCallExpr(call_expr) => {
100 .syntax() 93 call_expr.syntax().children().filter_map(ast::NameRef::cast).nth(0)
101 .children() 94 }
102 .filter_map(ast::NameRef::cast)
103 .nth(0),
104 } 95 }
105 } 96 }
106 97
@@ -117,12 +108,7 @@ impl CallInfo {
117 let label = crate::completion::function_label(node)?; 108 let label = crate::completion::function_label(node)?;
118 let doc = function.docs(db); 109 let doc = function.docs(db);
119 110
120 Some(CallInfo { 111 Some(CallInfo { parameters: param_list(node), label, doc, active_parameter: None })
121 parameters: param_list(node),
122 label,
123 doc,
124 active_parameter: None,
125 })
126 } 112 }
127} 113}
128 114
@@ -136,10 +122,7 @@ fn param_list(node: &ast::FnDef) -> Vec<String> {
136 // Maybe use param.pat here? See if we can just extract the name? 122 // Maybe use param.pat here? See if we can just extract the name?
137 //res.extend(param_list.params().map(|p| p.syntax().text().to_string())); 123 //res.extend(param_list.params().map(|p| p.syntax().text().to_string()));
138 res.extend( 124 res.extend(
139 param_list 125 param_list.params().filter_map(|p| p.pat()).map(|pat| pat.syntax().text().to_string()),
140 .params()
141 .filter_map(|p| p.pat())
142 .map(|pat| pat.syntax().text().to_string()),
143 ); 126 );
144 } 127 }
145 res 128 res
@@ -378,10 +361,7 @@ pub fn foo() {
378"#, 361"#,
379 ); 362 );
380 363
381 assert_eq!( 364 assert_eq!(info.parameters, vec!["&mut self".to_string(), "ctx".to_string()]);
382 info.parameters,
383 vec!["&mut self".to_string(), "ctx".to_string()]
384 );
385 assert_eq!(info.active_parameter, Some(1)); 365 assert_eq!(info.active_parameter, Some(1));
386 assert_eq!( 366 assert_eq!(
387 info.doc.map(|it| it.into()), 367 info.doc.map(|it| it.into()),