From 61687b9db67d34bbcce8596496448c0717d98316 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 6 Jan 2019 13:41:12 +0300 Subject: fix tests --- crates/ra_hir/src/code_model_api.rs | 10 +++++++++- crates/ra_hir/src/code_model_impl.rs | 19 ++++++++++++++++++- crates/ra_hir/src/module/nameres/tests.rs | 4 ++-- 3 files changed, 29 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 63e2e34e8..2f968d97c 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -1,4 +1,5 @@ -use ra_db::{CrateId, Cancelable}; +use ra_db::{CrateId, Cancelable, FileId}; +use ra_syntax::ast; use crate::{Name, db::HirDatabase, DefId}; @@ -17,6 +18,9 @@ pub struct CrateDependency { } impl Crate { + pub fn crate_id(&self) -> CrateId { + self.crate_id + } pub fn dependencies(&self, db: &impl HirDatabase) -> Vec { self.dependencies_impl(db) } @@ -31,6 +35,10 @@ pub struct Module { } impl Module { + pub fn source(&self, db: &impl HirDatabase) -> (FileId, Option) { + self.source_impl(db) + } + /// Returns the crate this module is part of. pub fn krate(&self, db: &impl HirDatabase) -> Cancelable> { self.krate_impl(db) diff --git a/crates/ra_hir/src/code_model_impl.rs b/crates/ra_hir/src/code_model_impl.rs index 659af548c..83ee8186e 100644 --- a/crates/ra_hir/src/code_model_impl.rs +++ b/crates/ra_hir/src/code_model_impl.rs @@ -1,4 +1,5 @@ -use ra_db::{CrateId, Cancelable}; +use ra_db::{CrateId, Cancelable, FileId}; +use ra_syntax::{AstNode, ast}; use crate::{HirFileId, db::HirDatabase, Crate, CrateDependency, AsName, DefId, DefLoc, DefKind, Name}; @@ -48,6 +49,22 @@ impl Module { crate::code_model_api::Module { def_id } } + pub(crate) fn source_impl(&self, db: &impl HirDatabase) -> (FileId, Option) { + let loc = self.def_id.loc(db); + let source_item_id = loc.source_item_id; + let module = match source_item_id.item_id { + None => None, + Some(_) => { + let syntax_node = db.file_item(source_item_id); + let module = ast::Module::cast(syntax_node.borrowed()).unwrap().owned(); + Some(module) + } + }; + // FIXME: remove `as_original_file` here + let file_id = source_item_id.file_id.as_original_file(); + (file_id, module) + } + pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable> { let root = self.crate_root(db)?; let loc = root.def_id.loc(db); diff --git a/crates/ra_hir/src/module/nameres/tests.rs b/crates/ra_hir/src/module/nameres/tests.rs index a6a0bea31..dcbe65aec 100644 --- a/crates/ra_hir/src/module/nameres/tests.rs +++ b/crates/ra_hir/src/module/nameres/tests.rs @@ -17,7 +17,7 @@ fn item_map(fixture: &str) -> (Arc, hir::ModuleId) { let module = hir::source_binder::module_from_position(&db, pos) .unwrap() .unwrap(); - let module_id = module.module_id; + let module_id = module.def_id.loc(&db).module_id; (db.item_map(source_root).unwrap(), module_id) } @@ -155,7 +155,7 @@ fn item_map_across_crates() { let module = hir::source_binder::module_from_file_id(&db, main_id) .unwrap() .unwrap(); - let module_id = module.module_id; + let module_id = module.def_id.loc(&db).module_id; let item_map = db.item_map(source_root).unwrap(); check_module_item_map( -- cgit v1.2.3