diff options
-rw-r--r-- | crates/ra_analysis/src/call_info.rs | 46 |
1 files changed, 11 insertions, 35 deletions
diff --git a/crates/ra_analysis/src/call_info.rs b/crates/ra_analysis/src/call_info.rs index 911ac3955..9111fdc69 100644 --- a/crates/ra_analysis/src/call_info.rs +++ b/crates/ra_analysis/src/call_info.rs | |||
@@ -10,22 +10,8 @@ use ra_editor::find_node_at_offset; | |||
10 | 10 | ||
11 | use crate::{FilePosition, CallInfo, db::RootDatabase}; | 11 | use crate::{FilePosition, CallInfo, db::RootDatabase}; |
12 | 12 | ||
13 | pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable<Option<CallInfo>> { | ||
14 | let (sig_info, active_parameter) = ctry!(signature_and_active_param(db, position)?); | ||
15 | let res = CallInfo { | ||
16 | label: sig_info.label, | ||
17 | doc: sig_info.doc, | ||
18 | parameters: sig_info.params, | ||
19 | active_parameter, | ||
20 | }; | ||
21 | Ok(Some(res)) | ||
22 | } | ||
23 | |||
24 | /// Computes parameter information for the given call expression. | 13 | /// Computes parameter information for the given call expression. |
25 | fn signature_and_active_param( | 14 | pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable<Option<CallInfo>> { |
26 | db: &RootDatabase, | ||
27 | position: FilePosition, | ||
28 | ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> { | ||
29 | let file = db.source_file(position.file_id); | 15 | let file = db.source_file(position.file_id); |
30 | let syntax = file.syntax(); | 16 | let syntax = file.syntax(); |
31 | 17 | ||
@@ -40,16 +26,14 @@ fn signature_and_active_param( | |||
40 | let fn_file = db.source_file(symbol.file_id); | 26 | let fn_file = db.source_file(symbol.file_id); |
41 | let fn_def = symbol.ptr.resolve(&fn_file); | 27 | let fn_def = symbol.ptr.resolve(&fn_file); |
42 | let fn_def = ast::FnDef::cast(&fn_def).unwrap(); | 28 | let fn_def = ast::FnDef::cast(&fn_def).unwrap(); |
43 | if let Some(descriptor) = FnSignatureInfo::new(fn_def) { | 29 | if let Some(mut call_info) = CallInfo::new(fn_def) { |
44 | // 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 |
45 | let mut current_parameter = None; | 31 | let num_params = call_info.parameters.len(); |
46 | |||
47 | let num_params = descriptor.params.len(); | ||
48 | 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(); |
49 | 33 | ||
50 | if num_params == 1 { | 34 | if num_params == 1 { |
51 | if !has_self { | 35 | if !has_self { |
52 | current_parameter = Some(0); | 36 | call_info.active_parameter = Some(0); |
53 | } | 37 | } |
54 | } else if num_params > 1 { | 38 | } else if num_params > 1 { |
55 | // Count how many parameters into the call we are. | 39 | // Count how many parameters into the call we are. |
@@ -74,11 +58,11 @@ fn signature_and_active_param( | |||
74 | commas += 1; | 58 | commas += 1; |
75 | } | 59 | } |
76 | 60 | ||
77 | current_parameter = Some(commas); | 61 | call_info.active_parameter = Some(commas); |
78 | } | 62 | } |
79 | } | 63 | } |
80 | 64 | ||
81 | return Ok(Some((descriptor, current_parameter))); | 65 | return Ok(Some(call_info)); |
82 | } | 66 | } |
83 | } | 67 | } |
84 | } | 68 | } |
@@ -125,14 +109,7 @@ impl<'a> FnCallNode<'a> { | |||
125 | } | 109 | } |
126 | } | 110 | } |
127 | 111 | ||
128 | #[derive(Debug, Clone)] | 112 | impl CallInfo { |
129 | struct FnSignatureInfo { | ||
130 | label: String, | ||
131 | params: Vec<String>, | ||
132 | doc: Option<String>, | ||
133 | } | ||
134 | |||
135 | impl FnSignatureInfo { | ||
136 | fn new(node: &ast::FnDef) -> Option<Self> { | 113 | fn new(node: &ast::FnDef) -> Option<Self> { |
137 | let mut doc = None; | 114 | let mut doc = None; |
138 | 115 | ||
@@ -150,7 +127,7 @@ impl FnSignatureInfo { | |||
150 | node.syntax().text().to_string() | 127 | node.syntax().text().to_string() |
151 | }; | 128 | }; |
152 | 129 | ||
153 | if let Some((comment_range, docs)) = FnSignatureInfo::extract_doc_comments(node) { | 130 | if let Some((comment_range, docs)) = CallInfo::extract_doc_comments(node) { |
154 | let comment_range = comment_range | 131 | let comment_range = comment_range |
155 | .checked_sub(node.syntax().range().start()) | 132 | .checked_sub(node.syntax().range().start()) |
156 | .unwrap(); | 133 | .unwrap(); |
@@ -182,12 +159,11 @@ impl FnSignatureInfo { | |||
182 | } | 159 | } |
183 | } | 160 | } |
184 | 161 | ||
185 | let params = FnSignatureInfo::param_list(node); | 162 | Some(CallInfo { |
186 | 163 | parameters: CallInfo::param_list(node), | |
187 | Some(FnSignatureInfo { | ||
188 | params, | ||
189 | label: label.trim().to_owned(), | 164 | label: label.trim().to_owned(), |
190 | doc, | 165 | doc, |
166 | active_parameter: None, | ||
191 | }) | 167 | }) |
192 | } | 168 | } |
193 | 169 | ||