From ec7ed054e06cb2e23fd3911932766b32014c8fa1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 24 Jan 2019 15:28:50 +0300 Subject: Functions use new id scheme --- crates/ra_hir/src/code_model_impl/function.rs | 29 +++++++++++++++++---------- crates/ra_hir/src/code_model_impl/module.rs | 1 + 2 files changed, 19 insertions(+), 11 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 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; use std::sync::Arc; -use ra_syntax::{TreeArc, ast::{self, NameOwner}}; +use ra_syntax::ast::{self, NameOwner}; use crate::{ - DefId, HirDatabase, Name, AsName, Function, FnSignature, Module, + HirDatabase, Name, AsName, Function, FnSignature, Module, HirFileId, type_ref::{TypeRef, Mutability}, expr::Body, impl_block::ImplBlock, - code_model_impl::def_id_to_ast, + ids::FunctionLoc, }; pub use self::scope::{FnScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}; impl Function { - pub(crate) fn new(def_id: DefId) -> Function { - Function { def_id } + pub(crate) fn from_ast( + db: &impl HirDatabase, + module: Module, + file_id: HirFileId, + ast: &ast::FnDef, + ) -> Function { + let loc: FunctionLoc = FunctionLoc::from_ast(db, module, file_id, ast); + let id = loc.id(db); + Function { id } } pub(crate) fn body(&self, db: &impl HirDatabase) -> Arc { - db.body_hir(self.def_id) + db.body_hir(*self) } pub(crate) fn module(&self, db: &impl HirDatabase) -> Module { - self.def_id.module(db) + self.id.loc(db).module } /// The containing impl block, if this is a method. pub(crate) fn impl_block(&self, db: &impl HirDatabase) -> Option { - self.def_id.impl_block(db) + let module_impls = db.impls_in_module(self.module(db)); + ImplBlock::containing(module_impls, (*self).into()) } } impl FnSignature { - pub(crate) fn fn_signature_query(db: &impl HirDatabase, def_id: DefId) -> Arc { - // FIXME: we're using def_id_to_ast here to avoid returning Cancelable... this is a bit hacky - let node: TreeArc = def_id_to_ast(db, def_id).1; + pub(crate) fn fn_signature_query(db: &impl HirDatabase, func: Function) -> Arc { + let (_, node) = func.source(db); let name = node .name() .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 { None => PerNs::none(), } } + ModuleDef::Function(_) => PerNs::none(), ModuleDef::Def(def) => { match def.resolve(db) { Def::Enum(e) => { -- cgit v1.2.3