Skip to content

Commit

Permalink
misc: fixes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Oct 26, 2020
1 parent 7b50951 commit b1e14eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions crates/mun_hir/src/name_resolution/path_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ impl PackageDefs {
}

/// Resolves the specified `path` from within the specified `module`. Also returns whether or
/// not an additions to the PackageDef would change the result. This is useful when resolving
/// all imports.
/// not additions to the `PackageDef` would change the result or whether a fixed point has been
/// reached. This is useful when resolving all imports.
pub(super) fn resolve_path_with_fixedpoint(
&self,
db: &dyn DefDatabase,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl PackageDefs {
}
.into(),
Visibility::Public,
))
)),
};

for (i, segment) in segments {
Expand Down
11 changes: 5 additions & 6 deletions crates/mun_hir/src/package_defs.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
mod collector;

use crate::ids::PackageId;
use crate::item_scope::ItemScope;
use crate::module_tree::ModuleTree;
use crate::{arena::map::ArenaMap, module_tree::LocalModuleId, DefDatabase};
use std::ops::Index;
use std::sync::Arc;
use crate::{
arena::map::ArenaMap, ids::PackageId, item_scope::ItemScope, module_tree::LocalModuleId,
module_tree::ModuleTree, DefDatabase,
};
use std::{ops::Index, sync::Arc};

/// Contains all top-level definitions for a package.
#[derive(Debug, PartialEq, Eq)]
Expand Down
14 changes: 8 additions & 6 deletions crates/mun_hir/src/package_defs/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ pub(super) fn collect(db: &dyn DefDatabase, package_id: PackageId) -> PackageDef
collector.finish()
}

/// A helper struct to collect all definitions for all modules in a package.
struct DefCollector<'db> {
db: &'db dyn DefDatabase,
package_id: PackageId,
modules: ArenaMap<LocalModuleId, ItemScope>,
module_tree: Arc<ModuleTree>,
}

impl<'t> DefCollector<'t> {
impl<'db> DefCollector<'db> {
/// Collects all information and stores it in the instance
fn collect(&mut self) {
// Collect all definitions in each module
let module_tree = self.module_tree.clone();

fn collect_modules_recursive<'t>(
collector: &mut DefCollector<'t>,
fn collect_modules_recursive(
collector: &mut DefCollector,
module_id: LocalModuleId,
parent: Option<(Name, LocalModuleId)>,
) {
Expand All @@ -48,13 +49,14 @@ impl<'t> DefCollector<'t> {
let module_data = &collector.module_tree[module_id];
if let Some(file_id) = module_data.file {
let item_tree = collector.db.item_tree(file_id);
ModCollector {
let mut mod_collector = ModCollector {
def_collector: collector,
module_id,
file_id,
item_tree: &item_tree,
}
.collect(item_tree.top_level_items());
};

mod_collector.collect(item_tree.top_level_items());
}

// Insert this module into the scope of the parent
Expand Down

0 comments on commit b1e14eb

Please sign in to comment.