diff options
Diffstat (limited to 'crates/ra_ide/src/call_info.rs')
-rw-r--r-- | crates/ra_ide/src/call_info.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index f95b6baf3..5da254a6e 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs | |||
@@ -19,10 +19,24 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal | |||
19 | call_info_for_token(&sema, token) | 19 | call_info_for_token(&sema, token) |
20 | } | 20 | } |
21 | 21 | ||
22 | pub(crate) fn call_info_for_token( | 22 | #[derive(Debug)] |
23 | sema: &Semantics<RootDatabase>, | 23 | pub(crate) struct ActiveParameter { |
24 | token: SyntaxToken, | 24 | /// FIXME: should be `Type` and `Name |
25 | ) -> Option<CallInfo> { | 25 | pub(crate) ty: String, |
26 | pub(crate) name: String, | ||
27 | } | ||
28 | |||
29 | impl ActiveParameter { | ||
30 | pub(crate) fn at(db: &RootDatabase, position: FilePosition) -> Option<Self> { | ||
31 | call_info(db, position)?.into_active_parameter() | ||
32 | } | ||
33 | |||
34 | pub(crate) fn at_token(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Option<Self> { | ||
35 | call_info_for_token(sema, token)?.into_active_parameter() | ||
36 | } | ||
37 | } | ||
38 | |||
39 | fn call_info_for_token(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Option<CallInfo> { | ||
26 | // Find the calling expression and it's NameRef | 40 | // Find the calling expression and it's NameRef |
27 | let calling_node = FnCallNode::with_node(&token.parent())?; | 41 | let calling_node = FnCallNode::with_node(&token.parent())?; |
28 | 42 | ||
@@ -160,6 +174,14 @@ impl FnCallNode { | |||
160 | } | 174 | } |
161 | 175 | ||
162 | impl CallInfo { | 176 | impl CallInfo { |
177 | fn into_active_parameter(self) -> Option<ActiveParameter> { | ||
178 | let idx = self.active_parameter?; | ||
179 | let ty = self.signature.parameter_types.get(idx)?.clone(); | ||
180 | let name = self.signature.parameter_names.get(idx)?.clone(); | ||
181 | let res = ActiveParameter { ty, name }; | ||
182 | Some(res) | ||
183 | } | ||
184 | |||
163 | fn with_fn(db: &RootDatabase, function: hir::Function) -> Self { | 185 | fn with_fn(db: &RootDatabase, function: hir::Function) -> Self { |
164 | let signature = FunctionSignature::from_hir(db, function); | 186 | let signature = FunctionSignature::from_hir(db, function); |
165 | 187 | ||