From 9c7a2aef30cb35347af646dea5a5611af1224676 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 15 Nov 2019 10:26:31 +0300 Subject: Refactor Module::from_source to properly descend from root file --- crates/ra_hir_def/src/nameres.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'crates/ra_hir_def/src/nameres.rs') diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index d3ecabb9b..1331fbe30 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -258,6 +258,13 @@ impl CrateDefMap { let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path); (res.resolved_def, res.segment_index) } + + pub fn modules_for_file(&self, file_id: FileId) -> impl Iterator + '_ { + self.modules + .iter() + .filter(move |(_id, data)| data.definition == Some(file_id)) + .map(|(id, _data)| id) + } } mod diagnostics { -- cgit v1.2.3 From a28907af8ca93077601053cf168ac2429855c394 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 15 Nov 2019 10:42:54 +0300 Subject: Privatize modules --- crates/ra_hir_def/src/nameres.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_def/src/nameres.rs') diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 1331fbe30..5fc592150 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -87,7 +87,7 @@ pub struct CrateDefMap { prelude: Option, extern_prelude: FxHashMap, root: CrateModuleId, - pub modules: Arena, + modules: Arena, /// Some macros are not well-behavior, which leads to infinite loop /// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } } @@ -259,6 +259,10 @@ impl CrateDefMap { (res.resolved_def, res.segment_index) } + pub fn modules(&self) -> impl Iterator + '_ { + self.modules.iter().map(|(id, _data)| id) + } + pub fn modules_for_file(&self, file_id: FileId) -> impl Iterator + '_ { self.modules .iter() -- cgit v1.2.3 From 2f6c0c314b749e25431f3fd6caaac5d3270751b6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 15 Nov 2019 14:47:26 +0300 Subject: Move scope tests to hir_def --- crates/ra_hir_def/src/nameres.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/nameres.rs') diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 5fc592150..21d5f62e0 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -58,7 +58,7 @@ mod tests; use std::sync::Arc; -use hir_expand::{diagnostics::DiagnosticSink, name::Name, MacroDefId}; +use hir_expand::{ast_id_map::FileAstId, diagnostics::DiagnosticSink, name::Name, MacroDefId}; use once_cell::sync::Lazy; use ra_arena::Arena; use ra_db::{CrateId, Edition, FileId}; @@ -73,7 +73,7 @@ use crate::{ diagnostics::DefDiagnostic, path_resolution::ResolveMode, per_ns::PerNs, raw::ImportId, }, path::Path, - AstId, CrateModuleId, ModuleDefId, ModuleId, TraitId, + AstId, CrateModuleId, FunctionId, ModuleDefId, ModuleId, TraitId, }; /// Contains all top-level defs from a macro-expanded crate @@ -124,6 +124,11 @@ pub struct ModuleData { pub definition: Option, } +#[derive(Default, Debug, PartialEq, Eq, Clone)] +pub(crate) struct Declarations { + fns: FxHashMap, FunctionId>, +} + #[derive(Debug, Default, PartialEq, Eq, Clone)] pub struct ModuleScope { pub items: FxHashMap, -- cgit v1.2.3