diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_impl/function.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/function.rs | 23 |
1 files changed, 17 insertions, 6 deletions
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; | |||
5 | use ra_db::Cancelable; | 5 | use ra_db::Cancelable; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | TreePtr, | 7 | TreePtr, |
8 | ast::{self, AstNode}, | 8 | ast::{self, AstNode, NameOwner}, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | DefId, DefKind, HirDatabase, Name, Function, FnSignature, Module, | 12 | DefId, DefKind, HirDatabase, Name, AsName, Function, FnSignature, Module, HirFileId, |
13 | type_ref::{TypeRef, Mutability}, | 13 | type_ref::{TypeRef, Mutability}, |
14 | expr::Body, | 14 | expr::Body, |
15 | impl_block::ImplBlock, | 15 | impl_block::ImplBlock, |
@@ -22,11 +22,14 @@ impl Function { | |||
22 | Function { def_id } | 22 | Function { def_id } |
23 | } | 23 | } |
24 | 24 | ||
25 | pub(crate) fn source_impl(&self, db: &impl HirDatabase) -> TreePtr<ast::FnDef> { | 25 | pub(crate) fn source_impl(&self, db: &impl HirDatabase) -> (HirFileId, TreePtr<ast::FnDef>) { |
26 | let def_loc = self.def_id.loc(db); | 26 | let def_loc = self.def_id.loc(db); |
27 | assert!(def_loc.kind == DefKind::Function); | 27 | assert!(def_loc.kind == DefKind::Function); |
28 | let syntax = db.file_item(def_loc.source_item_id); | 28 | let syntax = db.file_item(def_loc.source_item_id); |
29 | ast::FnDef::cast(&syntax).unwrap().to_owned() | 29 | ( |
30 | def_loc.source_item_id.file_id, | ||
31 | ast::FnDef::cast(&syntax).unwrap().to_owned(), | ||
32 | ) | ||
30 | } | 33 | } |
31 | 34 | ||
32 | pub(crate) fn body(&self, db: &impl HirDatabase) -> Cancelable<Arc<Body>> { | 35 | pub(crate) fn body(&self, db: &impl HirDatabase) -> Cancelable<Arc<Body>> { |
@@ -46,7 +49,11 @@ impl Function { | |||
46 | impl FnSignature { | 49 | impl FnSignature { |
47 | pub(crate) fn fn_signature_query(db: &impl HirDatabase, def_id: DefId) -> Arc<FnSignature> { | 50 | pub(crate) fn fn_signature_query(db: &impl HirDatabase, def_id: DefId) -> Arc<FnSignature> { |
48 | let func = Function::new(def_id); | 51 | let func = Function::new(def_id); |
49 | let node = func.source(db); | 52 | let node = func.source_impl(db).1; // TODO we're using source_impl here to avoid returning Cancelable... this is a bit hacky |
53 | let name = node | ||
54 | .name() | ||
55 | .map(|n| n.as_name()) | ||
56 | .unwrap_or_else(Name::missing); | ||
50 | let mut args = Vec::new(); | 57 | let mut args = Vec::new(); |
51 | if let Some(param_list) = node.param_list() { | 58 | if let Some(param_list) = node.param_list() { |
52 | if let Some(self_param) = param_list.self_param() { | 59 | if let Some(self_param) = param_list.self_param() { |
@@ -76,7 +83,11 @@ impl FnSignature { | |||
76 | } else { | 83 | } else { |
77 | TypeRef::unit() | 84 | TypeRef::unit() |
78 | }; | 85 | }; |
79 | let sig = FnSignature { args, ret_type }; | 86 | let sig = FnSignature { |
87 | name, | ||
88 | args, | ||
89 | ret_type, | ||
90 | }; | ||
80 | Arc::new(sig) | 91 | Arc::new(sig) |
81 | } | 92 | } |
82 | } | 93 | } |