From ac92973a6c5934377c6eca9906f3b7f17e220d4e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 8 Jan 2019 20:11:13 +0300 Subject: move function to code_model_api --- crates/ra_hir/src/code_model_api.rs | 65 ++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/code_model_api.rs') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index f06f1ae66..902032e14 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -5,10 +5,12 @@ use ra_db::{CrateId, Cancelable, FileId}; use ra_syntax::{ast, TreePtr, SyntaxNode}; use crate::{ - Name, DefId, Path, PerNs, + Name, DefId, Path, PerNs, ScopesWithSyntaxMapping, type_ref::TypeRef, nameres::ModuleScope, db::HirDatabase, + expr::BodySyntaxMapping, + ty::InferenceResult, }; /// hir::Crate describes a single crate. It's the main inteface with which @@ -37,6 +39,14 @@ impl Crate { } } +pub enum Def { + Module(Module), + Struct(Struct), + Enum(Enum), + Function(Function), + Item, +} + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Module { pub(crate) def_id: DefId, @@ -207,3 +217,56 @@ impl Enum { Ok(db.enum_data(self.def_id)?.variants.clone()) } } + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Function { + pub(crate) def_id: DefId, +} + +/// The declared signature of a function. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct FnSignature { + pub(crate) args: Vec, + pub(crate) ret_type: TypeRef, +} + +impl FnSignature { + pub fn args(&self) -> &[TypeRef] { + &self.args + } + + pub fn ret_type(&self) -> &TypeRef { + &self.ret_type + } +} + +impl Function { + pub fn def_id(&self) -> DefId { + self.def_id + } + + pub fn source(&self, db: &impl HirDatabase) -> TreePtr { + self.source_impl(db) + } + + pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Cancelable> { + db.body_syntax_mapping(self.def_id) + } + + pub fn scopes(&self, db: &impl HirDatabase) -> Cancelable { + let scopes = db.fn_scopes(self.def_id)?; + let syntax_mapping = db.body_syntax_mapping(self.def_id)?; + Ok(ScopesWithSyntaxMapping { + scopes, + syntax_mapping, + }) + } + + pub fn signature(&self, db: &impl HirDatabase) -> Arc { + db.fn_signature(self.def_id) + } + + pub fn infer(&self, db: &impl HirDatabase) -> Cancelable> { + db.infer(self.def_id) + } +} -- cgit v1.2.3