diff options
Diffstat (limited to 'crates/ra_ide_api/src/call_info.rs')
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 11dea7c14..270499612 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -11,24 +11,24 @@ use crate::{db::RootDatabase, CallInfo, FilePosition, FunctionSignature}; | |||
11 | /// Computes parameter information for the given call expression. | 11 | /// Computes parameter information for the given call expression. |
12 | pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> { | 12 | pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> { |
13 | let parse = db.parse(position.file_id); | 13 | let parse = db.parse(position.file_id); |
14 | let syntax = parse.tree().syntax(); | 14 | let syntax = parse.tree().syntax().clone(); |
15 | 15 | ||
16 | // Find the calling expression and it's NameRef | 16 | // Find the calling expression and it's NameRef |
17 | let calling_node = FnCallNode::with_node(syntax, position.offset)?; | 17 | let calling_node = FnCallNode::with_node(&syntax, position.offset)?; |
18 | let name_ref = calling_node.name_ref()?; | 18 | let name_ref = calling_node.name_ref()?; |
19 | 19 | ||
20 | let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); | 20 | let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None); |
21 | let function = match calling_node { | 21 | let function = match &calling_node { |
22 | FnCallNode::CallExpr(expr) => { | 22 | FnCallNode::CallExpr(expr) => { |
23 | //FIXME: apply subst | 23 | //FIXME: apply subst |
24 | let (callable_def, _subst) = analyzer.type_of(db, expr.expr()?)?.as_callable()?; | 24 | let (callable_def, _subst) = analyzer.type_of(db, &expr.expr()?)?.as_callable()?; |
25 | match callable_def { | 25 | match callable_def { |
26 | hir::CallableDef::Function(it) => it, | 26 | hir::CallableDef::Function(it) => it, |
27 | //FIXME: handle other callables | 27 | //FIXME: handle other callables |
28 | _ => return None, | 28 | _ => return None, |
29 | } | 29 | } |
30 | } | 30 | } |
31 | FnCallNode::MethodCallExpr(expr) => analyzer.resolve_method_call(expr)?, | 31 | FnCallNode::MethodCallExpr(expr) => analyzer.resolve_method_call(&expr)?, |
32 | }; | 32 | }; |
33 | 33 | ||
34 | let mut call_info = CallInfo::new(db, function); | 34 | let mut call_info = CallInfo::new(db, function); |
@@ -73,13 +73,13 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal | |||
73 | Some(call_info) | 73 | Some(call_info) |
74 | } | 74 | } |
75 | 75 | ||
76 | enum FnCallNode<'a> { | 76 | enum FnCallNode { |
77 | CallExpr(&'a ast::CallExpr), | 77 | CallExpr(ast::CallExpr), |
78 | MethodCallExpr(&'a ast::MethodCallExpr), | 78 | MethodCallExpr(ast::MethodCallExpr), |
79 | } | 79 | } |
80 | 80 | ||
81 | impl<'a> FnCallNode<'a> { | 81 | impl FnCallNode { |
82 | fn with_node(syntax: &'a SyntaxNode, offset: TextUnit) -> Option<FnCallNode<'a>> { | 82 | fn with_node(syntax: &SyntaxNode, offset: TextUnit) -> Option<FnCallNode> { |
83 | if let Some(expr) = find_node_at_offset::<ast::CallExpr>(syntax, offset) { | 83 | if let Some(expr) = find_node_at_offset::<ast::CallExpr>(syntax, offset) { |
84 | return Some(FnCallNode::CallExpr(expr)); | 84 | return Some(FnCallNode::CallExpr(expr)); |
85 | } | 85 | } |
@@ -89,8 +89,8 @@ impl<'a> FnCallNode<'a> { | |||
89 | None | 89 | None |
90 | } | 90 | } |
91 | 91 | ||
92 | fn name_ref(&self) -> Option<&'a ast::NameRef> { | 92 | fn name_ref(&self) -> Option<ast::NameRef> { |
93 | match *self { | 93 | match self { |
94 | FnCallNode::CallExpr(call_expr) => Some(match call_expr.expr()?.kind() { | 94 | FnCallNode::CallExpr(call_expr) => Some(match call_expr.expr()?.kind() { |
95 | ast::ExprKind::PathExpr(path_expr) => path_expr.path()?.segment()?.name_ref()?, | 95 | ast::ExprKind::PathExpr(path_expr) => path_expr.path()?.segment()?.name_ref()?, |
96 | _ => return None, | 96 | _ => return None, |
@@ -102,8 +102,8 @@ impl<'a> FnCallNode<'a> { | |||
102 | } | 102 | } |
103 | } | 103 | } |
104 | 104 | ||
105 | fn arg_list(&self) -> Option<&'a ast::ArgList> { | 105 | fn arg_list(&self) -> Option<ast::ArgList> { |
106 | match *self { | 106 | match self { |
107 | FnCallNode::CallExpr(expr) => expr.arg_list(), | 107 | FnCallNode::CallExpr(expr) => expr.arg_list(), |
108 | FnCallNode::MethodCallExpr(expr) => expr.arg_list(), | 108 | FnCallNode::MethodCallExpr(expr) => expr.arg_list(), |
109 | } | 109 | } |