From 505acc973b3b865195d7d0aeb47c419c35f6bbbc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 11 Apr 2019 15:34:13 +0300 Subject: Make call info to use real name resolution --- crates/ra_ide_api/src/call_info.rs | 37 ++++++++++++---------- .../src/completion/completion_context.rs | 6 ---- 2 files changed, 20 insertions(+), 23 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index dbb3853d0..d06876777 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -2,7 +2,6 @@ use test_utils::tested_by; use ra_db::SourceDatabase; use ra_syntax::{ AstNode, SyntaxNode, TextUnit, - SyntaxKind::FN_DEF, ast::{self, ArgListOwner}, algo::find_node_at_offset, }; @@ -18,19 +17,26 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option { + //FIXME: apply subst + let (callable_def, _subst) = + analyser.type_of(db, expr.expr()?.into())?.as_callable()?; + match callable_def { + hir::CallableDef::Function(it) => it, + //FIXME: handle other callables + _ => return None, + } + } + FnCallNode::MethodCallExpr(expr) => analyser.resolve_method_call(expr)?, + }; let mut call_info = CallInfo::new(db, function); // If we have a calling expression let's find which argument we are on let num_params = call_info.parameters().len(); - let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some(); + let has_self = function.signature(db).has_self_param(); if num_params == 1 { if !has_self { @@ -142,7 +148,7 @@ mod tests { } #[test] - fn test_fn_signature_two_args_first() { + fn test_fn_signature_two_args_firstx() { let info = call_info( r#"fn foo(x: u32, y: u32) -> u32 {x + y} fn bar() { foo(<|>3, ); }"#, @@ -382,11 +388,9 @@ assert_eq!(6, my_crate::add_one(5)); fn test_fn_signature_with_docs_from_actix() { let info = call_info( r#" -pub trait WriteHandler -where - Self: Actor, - Self::Context: ActorContext, -{ +struct WriteHandler; + +impl WriteHandler { /// Method is called when writer emits error. /// /// If this method returns `ErrorAction::Continue` writer processing @@ -403,8 +407,7 @@ where } } -pub fn foo() { - WriteHandler r; +pub fn foo(mut r: WriteHandler<()>) { r.finished(<|>); } diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index ce21fca9b..ddcf46b4e 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs @@ -19,7 +19,6 @@ pub(crate) struct CompletionContext<'a> { pub(super) token: SyntaxToken<'a>, pub(super) resolver: Resolver, pub(super) module: Option, - pub(super) function: Option, pub(super) function_syntax: Option<&'a ast::FnDef>, pub(super) use_item_syntax: Option<&'a ast::UseItem>, pub(super) struct_lit_syntax: Option<&'a ast::StructLit>, @@ -59,7 +58,6 @@ impl<'a> CompletionContext<'a> { offset: position.offset, resolver, module, - function: None, function_syntax: None, use_item_syntax: None, struct_lit_syntax: None, @@ -150,10 +148,6 @@ impl<'a> CompletionContext<'a> { .ancestors() .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) .find_map(ast::FnDef::cast); - if let (Some(module), Some(fn_def)) = (self.module, self.function_syntax) { - let function = source_binder::function_from_module(self.db, module, fn_def); - self.function = Some(function); - } let parent = match name_ref.syntax().parent() { Some(it) => it, -- cgit v1.2.3