Skip to content

Commit 1f0e9c1

Browse files
committed
More resolution modules with attribute path
#1211
1 parent f1bfa8f commit 1f0e9c1

File tree

2 files changed

+521
-4
lines changed

2 files changed

+521
-4
lines changed

crates/ra_hir/src/nameres/collector.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct DefCollector<DB> {
8484
global_macro_scope: FxHashMap<Name, MacroDefId>,
8585

8686
/// Some macro use `$tt:tt which mean we have to handle the macro perfectly
87-
/// To prevent stackoverflow, we add a deep counter here for prevent that.
87+
/// To prevent stack overflow, we add a deep counter here for prevent that.
8888
macro_stack_monitor: MacroStackMonitor,
8989
}
9090

@@ -497,7 +497,7 @@ where
497497

498498
fn collect_module(&mut self, module: &raw::ModuleData) {
499499
match module {
500-
// inline module, just recurse
500+
// inline module, just recursive
501501
raw::ModuleData::Definition { name, items, ast_id } => {
502502
let module_id =
503503
self.push_child_module(name.clone(), ast_id.with_file_id(self.file_id), None);
@@ -509,7 +509,7 @@ where
509509
}
510510
.collect(&*items);
511511
}
512-
// out of line module, resolve, parse and recurse
512+
// out of line module, resolve, parse and recursive
513513
raw::ModuleData::Declaration { name, ast_id, attr_path } => {
514514
let ast_id = ast_id.with_file_id(self.file_id);
515515
let is_root = self.def_collector.def_map.modules[self.module_id].parent.is_none();
@@ -649,7 +649,8 @@ fn resolve_submodule(
649649
let file_dir_mod = dir_path.join(format!("{}/{}.rs", mod_name, name));
650650
let mut candidates = ArrayVec::<[_; 3]>::new();
651651
let file_attr_mod = attr_path.map(|file_path| {
652-
let file_attr_mod = dir_path.join(file_path.to_string());
652+
let file_path = normalize_attribute_path(file_path);
653+
let file_attr_mod = dir_path.join(file_path).normalize();
653654
candidates.push(file_attr_mod.clone());
654655

655656
file_attr_mod
@@ -675,6 +676,17 @@ fn resolve_submodule(
675676
}
676677
}
677678

679+
fn normalize_attribute_path(file_path: &SmolStr) -> String {
680+
let current_dir = "./";
681+
682+
let separator = |path: &str| path.replace("\\", "/");
683+
if file_path.starts_with(current_dir) {
684+
separator(&file_path[current_dir.len()..])
685+
} else {
686+
separator(file_path.as_str())
687+
}
688+
}
689+
678690
#[cfg(test)]
679691
mod tests {
680692
use ra_db::SourceDatabase;

0 commit comments

Comments
 (0)