aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model_impl')
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs29
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs1
2 files changed, 19 insertions, 11 deletions
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index c68c6bfbf..d8dafb10e 100644
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ b/crates/ra_hir/src/code_model_impl/function.rs
@@ -2,41 +2,48 @@ mod scope;
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use ra_syntax::{TreeArc, ast::{self, NameOwner}}; 5use ra_syntax::ast::{self, NameOwner};
6 6
7use crate::{ 7use crate::{
8 DefId, HirDatabase, Name, AsName, Function, FnSignature, Module, 8 HirDatabase, Name, AsName, Function, FnSignature, Module, HirFileId,
9 type_ref::{TypeRef, Mutability}, 9 type_ref::{TypeRef, Mutability},
10 expr::Body, 10 expr::Body,
11 impl_block::ImplBlock, 11 impl_block::ImplBlock,
12 code_model_impl::def_id_to_ast, 12 ids::FunctionLoc,
13}; 13};
14 14
15pub use self::scope::{FnScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}; 15pub use self::scope::{FnScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax};
16 16
17impl Function { 17impl Function {
18 pub(crate) fn new(def_id: DefId) -> Function { 18 pub(crate) fn from_ast(
19 Function { def_id } 19 db: &impl HirDatabase,
20 module: Module,
21 file_id: HirFileId,
22 ast: &ast::FnDef,
23 ) -> Function {
24 let loc: FunctionLoc = FunctionLoc::from_ast(db, module, file_id, ast);
25 let id = loc.id(db);
26 Function { id }
20 } 27 }
21 28
22 pub(crate) fn body(&self, db: &impl HirDatabase) -> Arc<Body> { 29 pub(crate) fn body(&self, db: &impl HirDatabase) -> Arc<Body> {
23 db.body_hir(self.def_id) 30 db.body_hir(*self)
24 } 31 }
25 32
26 pub(crate) fn module(&self, db: &impl HirDatabase) -> Module { 33 pub(crate) fn module(&self, db: &impl HirDatabase) -> Module {
27 self.def_id.module(db) 34 self.id.loc(db).module
28 } 35 }
29 36
30 /// The containing impl block, if this is a method. 37 /// The containing impl block, if this is a method.
31 pub(crate) fn impl_block(&self, db: &impl HirDatabase) -> Option<ImplBlock> { 38 pub(crate) fn impl_block(&self, db: &impl HirDatabase) -> Option<ImplBlock> {
32 self.def_id.impl_block(db) 39 let module_impls = db.impls_in_module(self.module(db));
40 ImplBlock::containing(module_impls, (*self).into())
33 } 41 }
34} 42}
35 43
36impl FnSignature { 44impl FnSignature {
37 pub(crate) fn fn_signature_query(db: &impl HirDatabase, def_id: DefId) -> Arc<FnSignature> { 45 pub(crate) fn fn_signature_query(db: &impl HirDatabase, func: Function) -> Arc<FnSignature> {
38 // FIXME: we're using def_id_to_ast here to avoid returning Cancelable... this is a bit hacky 46 let (_, node) = func.source(db);
39 let node: TreeArc<ast::FnDef> = def_id_to_ast(db, def_id).1;
40 let name = node 47 let name = node
41 .name() 48 .name()
42 .map(|n| n.as_name()) 49 .map(|n| n.as_name())
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 5d00e905b..b2828c7be 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -135,6 +135,7 @@ impl Module {
135 None => PerNs::none(), 135 None => PerNs::none(),
136 } 136 }
137 } 137 }
138 ModuleDef::Function(_) => PerNs::none(),
138 ModuleDef::Def(def) => { 139 ModuleDef::Def(def) => {
139 match def.resolve(db) { 140 match def.resolve(db) {
140 Def::Enum(e) => { 141 Def::Enum(e) => {