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 25, 2020
1 parent 026741d commit 702e615
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions crates/mun_hir/src/module_tree.rs
@@ -1,12 +1,12 @@
use crate::ids::{ModuleId, PackageId};
use crate::module_tree::diagnostics::ModuleTreeDiagnostic;
use crate::visibility::RawVisibility;
use crate::{
arena::{Arena, Idx},
ids::{ModuleId, PackageId},
module_tree::diagnostics::ModuleTreeDiagnostic,
visibility::RawVisibility,
DefDatabase, FileId, Name, SourceDatabase, Visibility,
};
use itertools::Itertools;
use relative_path::{Component, RelativePath};
use relative_path::RelativePath;
use rustc_hash::FxHashMap;
use std::sync::Arc;

Expand Down Expand Up @@ -40,7 +40,7 @@ impl std::ops::Index<LocalModuleId> for ModuleTree {
}

impl ModuleTree {
/// Construct the tree of modules from the set of files in a package
/// Constructs the tree of modules from the set of files in a package
pub(crate) fn module_tree_query(
db: &dyn SourceDatabase,
package: PackageId,
Expand Down Expand Up @@ -148,15 +148,10 @@ impl ModuleTree {
}
}

/// Given a path name, returns the module name
fn normalize_module_name(name: Component) -> String {
name.as_str().replace("-", "_")
}

/// Given a relative path, returns a Vec with all the module names
fn path_to_module_path(path: &RelativePath) -> Vec<String> {
if path.extension().is_none() {
path.components().map(normalize_module_name).collect()
path.components().map(|c| c.as_str().to_owned()).collect()
} else if path
.file_stem()
.map(|stem| stem.to_lowercase())
Expand Down Expand Up @@ -207,6 +202,7 @@ mod test {
assert_eq!(is_valid_module_name("foo_bar"), true);
assert_eq!(is_valid_module_name("3bar"), false);
assert_eq!(is_valid_module_name("bar3"), true);
assert_eq!(is_valid_module_name("foo-bar"), false);
assert_eq!(is_valid_module_name(""), false);
}

Expand All @@ -232,10 +228,6 @@ mod test {
path_to_module_path(RelativePath::new("mod.mun")),
Vec::<String>::new()
);
assert_eq!(
path_to_module_path(RelativePath::new("foo-bar/mod.mun")),
vec!["foo_bar"]
);
}

#[test]
Expand Down

0 comments on commit 702e615

Please sign in to comment.