1
- //! This module provides primitives for tracking the information about a call site.
1
+ //! This module provides primitives for showing type and function parameter information when editing
2
+ //! a call or use-site.
2
3
3
4
use either:: Either ;
4
5
use hir:: { HasAttrs , HirDisplay , Semantics } ;
@@ -11,17 +12,19 @@ use syntax::{algo, AstNode, Direction, TextRange, TextSize};
11
12
12
13
use crate :: RootDatabase ;
13
14
14
- /// Contains information about a call site. Specifically the
15
- /// `FunctionSignature`and current parameter.
15
+ /// Contains information about an item signature as seen from a use site.
16
+ ///
17
+ /// This includes the "active parameter", which is the parameter whose value is currently being
18
+ /// edited.
16
19
#[ derive( Debug ) ]
17
- pub struct CallInfo {
20
+ pub struct SignatureHelp {
18
21
pub doc : Option < String > ,
19
22
pub signature : String ,
20
23
pub active_parameter : Option < usize > ,
21
24
parameters : Vec < TextRange > ,
22
25
}
23
26
24
- impl CallInfo {
27
+ impl SignatureHelp {
25
28
pub fn parameter_labels ( & self ) -> impl Iterator < Item = & str > + ' _ {
26
29
self . parameters . iter ( ) . map ( move |& it| & self . signature [ it] )
27
30
}
@@ -49,8 +52,8 @@ impl CallInfo {
49
52
}
50
53
}
51
54
52
- /// Computes parameter information for the given call expression .
53
- pub ( crate ) fn call_info ( db : & RootDatabase , position : FilePosition ) -> Option < CallInfo > {
55
+ /// Computes parameter information for the given position .
56
+ pub ( crate ) fn signature_help ( db : & RootDatabase , position : FilePosition ) -> Option < SignatureHelp > {
54
57
let sema = Semantics :: new ( db) ;
55
58
let file = sema. parse ( position. file_id ) ;
56
59
let file = file. syntax ( ) ;
@@ -63,23 +66,23 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
63
66
let token = sema. descend_into_macros_single ( token) ;
64
67
65
68
if let Some ( ( callable, active_parameter) ) = callable_for_token ( & sema, token. clone ( ) ) {
66
- return Some ( call_info_for_callable ( db, callable, active_parameter) ) ;
69
+ return Some ( signature_help_for_callable ( db, callable, active_parameter) ) ;
67
70
}
68
71
69
72
if let Some ( ( generic_def, active_parameter) ) = generics_for_token ( & sema, token. clone ( ) ) {
70
- return call_info_for_generics ( db, generic_def, active_parameter) ;
73
+ return signature_help_for_generics ( db, generic_def, active_parameter) ;
71
74
}
72
75
73
76
None
74
77
}
75
78
76
- fn call_info_for_callable (
79
+ fn signature_help_for_callable (
77
80
db : & RootDatabase ,
78
81
callable : hir:: Callable ,
79
82
active_parameter : Option < usize > ,
80
- ) -> CallInfo {
83
+ ) -> SignatureHelp {
81
84
let mut res =
82
- CallInfo { doc : None , signature : String :: new ( ) , parameters : vec ! [ ] , active_parameter } ;
85
+ SignatureHelp { doc : None , signature : String :: new ( ) , parameters : vec ! [ ] , active_parameter } ;
83
86
84
87
match callable. kind ( ) {
85
88
hir:: CallableKind :: Function ( func) => {
@@ -134,12 +137,12 @@ fn call_info_for_callable(
134
137
res
135
138
}
136
139
137
- fn call_info_for_generics (
140
+ fn signature_help_for_generics (
138
141
db : & RootDatabase ,
139
142
mut generics_def : hir:: GenericDef ,
140
143
active_parameter : usize ,
141
- ) -> Option < CallInfo > {
142
- let mut res = CallInfo {
144
+ ) -> Option < SignatureHelp > {
145
+ let mut res = SignatureHelp {
143
146
doc : None ,
144
147
signature : String :: new ( ) ,
145
148
parameters : vec ! [ ] ,
@@ -230,7 +233,7 @@ mod tests {
230
233
"#
231
234
) ;
232
235
let ( db, position) = position ( & fixture) ;
233
- let call_info = crate :: call_info :: call_info ( & db, position) ;
236
+ let call_info = crate :: signature_help :: signature_help ( & db, position) ;
234
237
let actual = match call_info {
235
238
Some ( call_info) => {
236
239
let docs = match & call_info. doc {
0 commit comments