Skip to content

Commit db794ab

Browse files
committed
kill FnSignatureInfo
1 parent ed4f13e commit db794ab

File tree

1 file changed

+11
-35
lines changed

1 file changed

+11
-35
lines changed

crates/ra_analysis/src/call_info.rs

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,8 @@ use ra_editor::find_node_at_offset;
1010

1111
use crate::{FilePosition, CallInfo, db::RootDatabase};
1212

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-
2413
/// Computes parameter information for the given call expression.
25-
fn signature_and_active_param(
26-
db: &RootDatabase,
27-
position: FilePosition,
28-
) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
14+
pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable<Option<CallInfo>> {
2915
let file = db.source_file(position.file_id);
3016
let syntax = file.syntax();
3117

@@ -40,16 +26,14 @@ fn signature_and_active_param(
4026
let fn_file = db.source_file(symbol.file_id);
4127
let fn_def = symbol.ptr.resolve(&fn_file);
4228
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) {
4430
// If we have a calling expression let's find which argument we are on
45-
let mut current_parameter = None;
46-
47-
let num_params = descriptor.params.len();
31+
let num_params = call_info.parameters.len();
4832
let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some();
4933

5034
if num_params == 1 {
5135
if !has_self {
52-
current_parameter = Some(0);
36+
call_info.active_parameter = Some(0);
5337
}
5438
} else if num_params > 1 {
5539
// Count how many parameters into the call we are.
@@ -74,11 +58,11 @@ fn signature_and_active_param(
7458
commas += 1;
7559
}
7660

77-
current_parameter = Some(commas);
61+
call_info.active_parameter = Some(commas);
7862
}
7963
}
8064

81-
return Ok(Some((descriptor, current_parameter)));
65+
return Ok(Some(call_info));
8266
}
8367
}
8468
}
@@ -125,14 +109,7 @@ impl<'a> FnCallNode<'a> {
125109
}
126110
}
127111

128-
#[derive(Debug, Clone)]
129-
struct FnSignatureInfo {
130-
label: String,
131-
params: Vec<String>,
132-
doc: Option<String>,
133-
}
134-
135-
impl FnSignatureInfo {
112+
impl CallInfo {
136113
fn new(node: &ast::FnDef) -> Option<Self> {
137114
let mut doc = None;
138115

@@ -150,7 +127,7 @@ impl FnSignatureInfo {
150127
node.syntax().text().to_string()
151128
};
152129

153-
if let Some((comment_range, docs)) = FnSignatureInfo::extract_doc_comments(node) {
130+
if let Some((comment_range, docs)) = CallInfo::extract_doc_comments(node) {
154131
let comment_range = comment_range
155132
.checked_sub(node.syntax().range().start())
156133
.unwrap();
@@ -182,12 +159,11 @@ impl FnSignatureInfo {
182159
}
183160
}
184161

185-
let params = FnSignatureInfo::param_list(node);
186-
187-
Some(FnSignatureInfo {
188-
params,
162+
Some(CallInfo {
163+
parameters: CallInfo::param_list(node),
189164
label: label.trim().to_owned(),
190165
doc,
166+
active_parameter: None,
191167
})
192168
}
193169

0 commit comments

Comments
 (0)