From ef67581104eb00a0c199f0b2a3b558da8a6f90a2 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 23 Dec 2018 17:13:11 +0100 Subject: Resolve paths to defs (functions currently) during type inference --- crates/ra_hir/src/function.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/function.rs') diff --git a/crates/ra_hir/src/function.rs b/crates/ra_hir/src/function.rs index 360e9e9a0..d36477b48 100644 --- a/crates/ra_hir/src/function.rs +++ b/crates/ra_hir/src/function.rs @@ -5,12 +5,13 @@ use std::{ sync::Arc, }; +use ra_db::Cancelable; use ra_syntax::{ TextRange, TextUnit, ast::{self, AstNode, DocCommentsOwner, NameOwner}, }; -use crate::{ DefId, HirDatabase, ty::InferenceResult }; +use crate::{ DefId, HirDatabase, ty::InferenceResult, Module }; pub use self::scope::FnScopes; @@ -18,7 +19,7 @@ pub use self::scope::FnScopes; pub struct FnId(pub(crate) DefId); pub struct Function { - fn_id: FnId, + pub(crate) fn_id: FnId, } impl Function { @@ -27,6 +28,10 @@ impl Function { Function { fn_id } } + pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode { + db.fn_syntax(self.fn_id) + } + pub fn scopes(&self, db: &impl HirDatabase) -> Arc { db.fn_scopes(self.fn_id) } @@ -36,9 +41,14 @@ impl Function { FnSignatureInfo::new(syntax.borrowed()) } - pub fn infer(&self, db: &impl HirDatabase) -> Arc { + pub fn infer(&self, db: &impl HirDatabase) -> Cancelable> { db.infer(self.fn_id) } + + pub fn module(&self, db: &impl HirDatabase) -> Cancelable { + let loc = self.fn_id.0.loc(db); + Module::new(db, loc.source_root_id, loc.module_id) + } } #[derive(Debug, Clone)] -- cgit v1.2.3