From 3fb88e95aa5e122a521beec766d5b1264ca4de3b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 23 Mar 2019 18:35:14 +0300 Subject: switch modules to new diagnostics --- crates/ra_hir/src/code_model_impl/module.rs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 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 52a33e981..14237060c 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -1,8 +1,8 @@ use ra_db::FileId; -use ra_syntax::{ast, SyntaxNode, TreeArc, AstNode}; +use ra_syntax::{ast, TreeArc, AstNode}; use crate::{ - Module, ModuleSource, Problem, Name, + Module, ModuleSource, Name, nameres::{CrateModuleId, ImportId}, HirDatabase, DefDatabase, HirFileId, SourceItemId, @@ -108,19 +108,4 @@ impl Module { let parent_id = def_map[self.module_id].parent?; Some(self.with_module_id(parent_id)) } - - pub(crate) fn problems_impl( - &self, - db: &impl HirDatabase, - ) -> Vec<(TreeArc, Problem)> { - let def_map = db.crate_def_map(self.krate); - let (my_file_id, _) = self.definition_source(db); - // FIXME: not entirely corret filterint by module - def_map - .problems() - .iter() - .filter(|(source_item_id, _problem)| my_file_id == source_item_id.file_id) - .map(|(source_item_id, problem)| (db.file_item(*source_item_id), problem.clone())) - .collect() - } } -- cgit v1.2.3 From 5270bca5f72fa65f0515be776e06d3d6a4d1efca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 26 Mar 2019 13:09:39 +0300 Subject: store macro def inside macro id This solves the problem of "macro expansion can't call into name resolution, because name resolution calls back into macro expansion" Because we store macro def as a part of call id, macro expansion just knows the def! --- crates/ra_hir/src/code_model_impl/module.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 14237060c..790e2b80f 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -76,7 +76,7 @@ impl Module { import: ImportId, ) -> TreeArc { let (file_id, source) = self.definition_source(db); - let (_, source_map) = db.raw_items_with_source_map(file_id.original_file(db)); + let (_, source_map) = db.raw_items_with_source_map(file_id); source_map.get(&source, import) } -- cgit v1.2.3 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