@@ -10,22 +10,8 @@ use ra_editor::find_node_at_offset;
10
10
11
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
13
/// 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 > > {
29
15
let file = db. source_file ( position. file_id ) ;
30
16
let syntax = file. syntax ( ) ;
31
17
@@ -40,16 +26,14 @@ fn signature_and_active_param(
40
26
let fn_file = db. source_file ( symbol. file_id ) ;
41
27
let fn_def = symbol. ptr . resolve ( & fn_file) ;
42
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
30
// 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 ( ) ;
48
32
let has_self = fn_def. param_list ( ) . and_then ( |l| l. self_param ( ) ) . is_some ( ) ;
49
33
50
34
if num_params == 1 {
51
35
if !has_self {
52
- current_parameter = Some ( 0 ) ;
36
+ call_info . active_parameter = Some ( 0 ) ;
53
37
}
54
38
} else if num_params > 1 {
55
39
// Count how many parameters into the call we are.
@@ -74,11 +58,11 @@ fn signature_and_active_param(
74
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 ) ]
129
- struct FnSignatureInfo {
130
- label : String ,
131
- params : Vec < String > ,
132
- doc : Option < String > ,
133
- }
134
-
135
- impl FnSignatureInfo {
112
+ impl CallInfo {
136
113
fn new ( node : & ast:: FnDef ) -> Option < Self > {
137
114
let mut doc = None ;
138
115
@@ -150,7 +127,7 @@ impl FnSignatureInfo {
150
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
131
let comment_range = comment_range
155
132
. checked_sub ( node. syntax ( ) . range ( ) . start ( ) )
156
133
. unwrap ( ) ;
@@ -182,12 +159,11 @@ impl FnSignatureInfo {
182
159
}
183
160
}
184
161
185
- let params = FnSignatureInfo :: param_list ( node) ;
186
-
187
- Some ( FnSignatureInfo {
188
- params,
162
+ Some ( CallInfo {
163
+ parameters : CallInfo :: param_list ( node) ,
189
164
label : label. trim ( ) . to_owned ( ) ,
190
165
doc,
166
+ active_parameter : None ,
191
167
} )
192
168
}
193
169
0 commit comments