diff options
Diffstat (limited to 'crates/ra_ide_api/src/call_info.rs')
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index efa320d83..18b9508ef 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::cmp::{max, min}; | 1 | use std::cmp::{max, min}; |
2 | 2 | ||
3 | use ra_db::{SyntaxDatabase, Cancelable}; | 3 | use ra_db::SyntaxDatabase; |
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | AstNode, SyntaxNode, TextUnit, TextRange, | 5 | AstNode, SyntaxNode, TextUnit, TextRange, |
6 | SyntaxKind::FN_DEF, | 6 | SyntaxKind::FN_DEF, |
@@ -11,21 +11,23 @@ use ra_syntax::{ | |||
11 | use crate::{FilePosition, CallInfo, db::RootDatabase}; | 11 | use crate::{FilePosition, CallInfo, db::RootDatabase}; |
12 | 12 | ||
13 | /// Computes parameter information for the given call expression. | 13 | /// Computes parameter information for the given call expression. |
14 | pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable<Option<CallInfo>> { | 14 | pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> { |
15 | let file = db.source_file(position.file_id); | 15 | let file = db.source_file(position.file_id); |
16 | let syntax = file.syntax(); | 16 | let syntax = file.syntax(); |
17 | 17 | ||
18 | // Find the calling expression and it's NameRef | 18 | // Find the calling expression and it's NameRef |
19 | let calling_node = ctry!(FnCallNode::with_node(syntax, position.offset)); | 19 | let calling_node = FnCallNode::with_node(syntax, position.offset)?; |
20 | let name_ref = ctry!(calling_node.name_ref()); | 20 | let name_ref = calling_node.name_ref()?; |
21 | 21 | ||
22 | // Resolve the function's NameRef (NOTE: this isn't entirely accurate). | 22 | // Resolve the function's NameRef (NOTE: this isn't entirely accurate). |
23 | let file_symbols = db.index_resolve(name_ref); | 23 | let file_symbols = db.index_resolve(name_ref); |
24 | let symbol = ctry!(file_symbols.into_iter().find(|it| it.ptr.kind() == FN_DEF)); | 24 | let symbol = file_symbols |
25 | .into_iter() | ||
26 | .find(|it| it.ptr.kind() == FN_DEF)?; | ||
25 | let fn_file = db.source_file(symbol.file_id); | 27 | let fn_file = db.source_file(symbol.file_id); |
26 | let fn_def = symbol.ptr.resolve(&fn_file); | 28 | let fn_def = symbol.ptr.resolve(&fn_file); |
27 | let fn_def = ast::FnDef::cast(&fn_def).unwrap(); | 29 | let fn_def = ast::FnDef::cast(&fn_def).unwrap(); |
28 | let mut call_info = ctry!(CallInfo::new(fn_def)); | 30 | let mut call_info = CallInfo::new(fn_def)?; |
29 | // If we have a calling expression let's find which argument we are on | 31 | // If we have a calling expression let's find which argument we are on |
30 | let num_params = call_info.parameters.len(); | 32 | let num_params = call_info.parameters.len(); |
31 | let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some(); | 33 | let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some(); |
@@ -61,7 +63,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable | |||
61 | } | 63 | } |
62 | } | 64 | } |
63 | 65 | ||
64 | Ok(Some(call_info)) | 66 | Some(call_info) |
65 | } | 67 | } |
66 | 68 | ||
67 | enum FnCallNode<'a> { | 69 | enum FnCallNode<'a> { |