aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r--crates/ra_hir/src/nameres/collector.rs22
-rw-r--r--crates/ra_hir/src/nameres/raw.rs13
2 files changed, 16 insertions, 19 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index 4fb298155..e6fd8632a 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -3,6 +3,7 @@ use rustc_hash::FxHashMap;
3use relative_path::RelativePathBuf; 3use relative_path::RelativePathBuf;
4use test_utils::tested_by; 4use test_utils::tested_by;
5use ra_db::FileId; 5use ra_db::FileId;
6use ra_syntax::ast;
6 7
7use crate::{ 8use crate::{
8 Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias, 9 Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias,
@@ -15,6 +16,7 @@ use crate::{
15 raw, 16 raw,
16 }, 17 },
17 ids::{AstItemDef, LocationCtx, MacroCallLoc, MacroCallId, MacroDefId}, 18 ids::{AstItemDef, LocationCtx, MacroCallLoc, MacroCallId, MacroDefId},
19 AstId,
18}; 20};
19 21
20pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { 22pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
@@ -364,12 +366,9 @@ where
364 fn collect_module(&mut self, module: &raw::ModuleData) { 366 fn collect_module(&mut self, module: &raw::ModuleData) {
365 match module { 367 match module {
366 // inline module, just recurse 368 // inline module, just recurse
367 raw::ModuleData::Definition { name, items, source_item_id } => { 369 raw::ModuleData::Definition { name, items, ast_id } => {
368 let module_id = self.push_child_module( 370 let module_id =
369 name.clone(), 371 self.push_child_module(name.clone(), ast_id.with_file_id(self.file_id), None);
370 source_item_id.with_file_id(self.file_id),
371 None,
372 );
373 ModCollector { 372 ModCollector {
374 def_collector: &mut *self.def_collector, 373 def_collector: &mut *self.def_collector,
375 module_id, 374 module_id,
@@ -379,13 +378,12 @@ where
379 .collect(&*items); 378 .collect(&*items);
380 } 379 }
381 // out of line module, resovle, parse and recurse 380 // out of line module, resovle, parse and recurse
382 raw::ModuleData::Declaration { name, source_item_id } => { 381 raw::ModuleData::Declaration { name, ast_id } => {
383 let source_item_id = source_item_id.with_file_id(self.file_id); 382 let ast_id = ast_id.with_file_id(self.file_id);
384 let is_root = self.def_collector.def_map.modules[self.module_id].parent.is_none(); 383 let is_root = self.def_collector.def_map.modules[self.module_id].parent.is_none();
385 match resolve_submodule(self.def_collector.db, self.file_id, name, is_root) { 384 match resolve_submodule(self.def_collector.db, self.file_id, name, is_root) {
386 Ok(file_id) => { 385 Ok(file_id) => {
387 let module_id = 386 let module_id = self.push_child_module(name.clone(), ast_id, Some(file_id));
388 self.push_child_module(name.clone(), source_item_id, Some(file_id));
389 let raw_items = self.def_collector.db.raw_items(file_id.into()); 387 let raw_items = self.def_collector.db.raw_items(file_id.into());
390 ModCollector { 388 ModCollector {
391 def_collector: &mut *self.def_collector, 389 def_collector: &mut *self.def_collector,
@@ -398,7 +396,7 @@ where
398 Err(candidate) => self.def_collector.def_map.diagnostics.push( 396 Err(candidate) => self.def_collector.def_map.diagnostics.push(
399 DefDiagnostic::UnresolvedModule { 397 DefDiagnostic::UnresolvedModule {
400 module: self.module_id, 398 module: self.module_id,
401 declaration: source_item_id, 399 declaration: ast_id,
402 candidate, 400 candidate,
403 }, 401 },
404 ), 402 ),
@@ -410,7 +408,7 @@ where
410 fn push_child_module( 408 fn push_child_module(
411 &mut self, 409 &mut self,
412 name: Name, 410 name: Name,
413 declaration: SourceItemId, 411 declaration: AstId<ast::Module>,
414 definition: Option<FileId>, 412 definition: Option<FileId>,
415 ) -> CrateModuleId { 413 ) -> CrateModuleId {
416 let modules = &mut self.def_collector.def_map.modules; 414 let modules = &mut self.def_collector.def_map.modules;
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index f32004601..09acd5a98 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -12,7 +12,7 @@ use ra_syntax::{
12 12
13use crate::{ 13use crate::{
14 DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, 14 DefDatabase, Name, AsName, Path, HirFileId, ModuleSource,
15 SourceFileItemId, SourceFileItems, 15 SourceFileItemId, SourceFileItems, FileAstId,
16}; 16};
17 17
18/// `RawItems` is a set of top-level items in a file (except for impls). 18/// `RawItems` is a set of top-level items in a file (except for impls).
@@ -115,8 +115,8 @@ impl_arena_id!(Module);
115 115
116#[derive(Debug, PartialEq, Eq)] 116#[derive(Debug, PartialEq, Eq)]
117pub(super) enum ModuleData { 117pub(super) enum ModuleData {
118 Declaration { name: Name, source_item_id: SourceFileItemId }, 118 Declaration { name: Name, ast_id: FileAstId<ast::Module> },
119 Definition { name: Name, source_item_id: SourceFileItemId, items: Vec<RawItem> }, 119 Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> },
120} 120}
121 121
122#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 122#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -221,10 +221,9 @@ impl RawItemsCollector {
221 Some(it) => it.as_name(), 221 Some(it) => it.as_name(),
222 None => return, 222 None => return,
223 }; 223 };
224 let source_item_id = self.source_file_items.id_of_unchecked(module.syntax()); 224 let ast_id = self.source_file_items.ast_id(module);
225 if module.has_semi() { 225 if module.has_semi() {
226 let item = 226 let item = self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id });
227 self.raw_items.modules.alloc(ModuleData::Declaration { name, source_item_id });
228 self.push_item(current_module, RawItem::Module(item)); 227 self.push_item(current_module, RawItem::Module(item));
229 return; 228 return;
230 } 229 }
@@ -232,7 +231,7 @@ impl RawItemsCollector {
232 if let Some(item_list) = module.item_list() { 231 if let Some(item_list) = module.item_list() {
233 let item = self.raw_items.modules.alloc(ModuleData::Definition { 232 let item = self.raw_items.modules.alloc(ModuleData::Definition {
234 name, 233 name,
235 source_item_id, 234 ast_id,
236 items: Vec::new(), 235 items: Vec::new(),
237 }); 236 });
238 self.process_module(Some(item), item_list); 237 self.process_module(Some(item), item_list);