From fb8b354dcc837d5eb9b81fc205e4282a203df177 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 26 Mar 2019 17:25:14 +0300 Subject: add typed ids --- crates/ra_hir/src/code_model_impl/module.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'crates/ra_hir/src/code_model_impl') diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 790e2b80f..0edb8ade5 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -1,18 +1,18 @@ use ra_db::FileId; -use ra_syntax::{ast, TreeArc, AstNode}; +use ra_syntax::{ast, TreeArc}; use crate::{ - Module, ModuleSource, Name, + Module, ModuleSource, Name, AstId, nameres::{CrateModuleId, ImportId}, HirDatabase, DefDatabase, - HirFileId, SourceItemId, + HirFileId, }; impl ModuleSource { pub(crate) fn new( db: &impl DefDatabase, file_id: Option, - decl_id: Option, + decl_id: Option>, ) -> ModuleSource { match (file_id, decl_id) { (Some(file_id), _) => { @@ -20,8 +20,7 @@ impl ModuleSource { ModuleSource::SourceFile(source_file) } (None, Some(item_id)) => { - let module = db.file_item(item_id); - let module = ast::Module::cast(&*module).unwrap(); + let module = item_id.to_node(db); assert!(module.item_list().is_some(), "expected inline module"); ModuleSource::Module(module.to_owned()) } @@ -55,7 +54,7 @@ impl Module { let decl_id = def_map[self.module_id].declaration; let file_id = def_map[self.module_id].definition; let module_source = ModuleSource::new(db, file_id, decl_id); - let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id); + let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id()); (file_id, module_source) } @@ -65,9 +64,8 @@ impl Module { ) -> Option<(HirFileId, TreeArc)> { let def_map = db.crate_def_map(self.krate); let decl = def_map[self.module_id].declaration?; - let syntax_node = db.file_item(decl); - let ast = ast::Module::cast(&syntax_node).unwrap().to_owned(); - Some((decl.file_id, ast)) + let ast = decl.to_node(db); + Some((decl.file_id(), ast)) } pub(crate) fn import_source_impl( -- cgit v1.2.3