From a6590ce2318676210b6b5a197b76b5861a3407c9 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Tue, 8 Jan 2019 00:30:49 +0100 Subject: Use name resolution for goto definition --- crates/ra_hir/src/code_model_impl/function.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir/src/code_model_impl') diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs index 13c57ed21..1bd4cc802 100644 --- a/crates/ra_hir/src/code_model_impl/function.rs +++ b/crates/ra_hir/src/code_model_impl/function.rs @@ -5,11 +5,11 @@ use std::sync::Arc; use ra_db::Cancelable; use ra_syntax::{ TreePtr, - ast::{self, AstNode}, + ast::{self, AstNode, NameOwner}, }; use crate::{ - DefId, DefKind, HirDatabase, Name, Function, FnSignature, Module, + DefId, DefKind, HirDatabase, Name, AsName, Function, FnSignature, Module, HirFileId, type_ref::{TypeRef, Mutability}, expr::Body, impl_block::ImplBlock, @@ -22,11 +22,14 @@ impl Function { Function { def_id } } - pub(crate) fn source_impl(&self, db: &impl HirDatabase) -> TreePtr { + pub(crate) fn source_impl(&self, db: &impl HirDatabase) -> (HirFileId, TreePtr) { let def_loc = self.def_id.loc(db); assert!(def_loc.kind == DefKind::Function); let syntax = db.file_item(def_loc.source_item_id); - ast::FnDef::cast(&syntax).unwrap().to_owned() + ( + def_loc.source_item_id.file_id, + ast::FnDef::cast(&syntax).unwrap().to_owned(), + ) } pub(crate) fn body(&self, db: &impl HirDatabase) -> Cancelable> { @@ -46,7 +49,11 @@ impl Function { impl FnSignature { pub(crate) fn fn_signature_query(db: &impl HirDatabase, def_id: DefId) -> Arc { let func = Function::new(def_id); - let node = func.source(db); + let node = func.source_impl(db).1; // TODO we're using source_impl here to avoid returning Cancelable... this is a bit hacky + let name = node + .name() + .map(|n| n.as_name()) + .unwrap_or_else(Name::missing); let mut args = Vec::new(); if let Some(param_list) = node.param_list() { if let Some(self_param) = param_list.self_param() { @@ -76,7 +83,11 @@ impl FnSignature { } else { TypeRef::unit() }; - let sig = FnSignature { args, ret_type }; + let sig = FnSignature { + name, + args, + ret_type, + }; Arc::new(sig) } } -- cgit v1.2.3