diff --git a/crates/mun_hir/src/module_tree.rs b/crates/mun_hir/src/module_tree.rs index b035c5db9..f8e1be50c 100644 --- a/crates/mun_hir/src/module_tree.rs +++ b/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; @@ -40,7 +40,7 @@ impl std::ops::Index 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, @@ -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 { 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()) @@ -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); } @@ -232,10 +228,6 @@ mod test { path_to_module_path(RelativePath::new("mod.mun")), Vec::::new() ); - assert_eq!( - path_to_module_path(RelativePath::new("foo-bar/mod.mun")), - vec!["foo_bar"] - ); } #[test]