Skip to content

Commit c4e2e36

Browse files
bors[bot]ava57r
andcommitted
Merge #1528
1528: More resolution modules with attribute path r=matklad a=andreevlex #1211 Co-authored-by: Alexander Andreev <[email protected]>
2 parents f1bfa8f + 9c75f30 commit c4e2e36

File tree

2 files changed

+534
-11
lines changed

2 files changed

+534
-11
lines changed

crates/ra_hir/src/nameres/collector.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::borrow::Cow;
2+
13
use arrayvec::ArrayVec;
24
use ra_db::FileId;
35
use ra_syntax::{ast, SmolStr};
@@ -84,7 +86,7 @@ struct DefCollector<DB> {
8486
global_macro_scope: FxHashMap<Name, MacroDefId>,
8587

8688
/// 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.
89+
/// To prevent stack overflow, we add a deep counter here for prevent that.
8890
macro_stack_monitor: MacroStackMonitor,
8991
}
9092

@@ -649,7 +651,8 @@ fn resolve_submodule(
649651
let file_dir_mod = dir_path.join(format!("{}/{}.rs", mod_name, name));
650652
let mut candidates = ArrayVec::<[_; 3]>::new();
651653
let file_attr_mod = attr_path.map(|file_path| {
652-
let file_attr_mod = dir_path.join(file_path.to_string());
654+
let file_path = normalize_attribute_path(file_path);
655+
let file_attr_mod = dir_path.join(file_path.as_ref()).normalize();
653656
candidates.push(file_attr_mod.clone());
654657

655658
file_attr_mod
@@ -675,6 +678,21 @@ fn resolve_submodule(
675678
}
676679
}
677680

681+
fn normalize_attribute_path(file_path: &SmolStr) -> Cow<str> {
682+
let current_dir = "./";
683+
let windows_path_separator = r#"\"#;
684+
let current_dir_normalize = if file_path.starts_with(current_dir) {
685+
&file_path[current_dir.len()..]
686+
} else {
687+
file_path.as_str()
688+
};
689+
if current_dir_normalize.contains(windows_path_separator) {
690+
Cow::Owned(current_dir_normalize.replace(windows_path_separator, "/"))
691+
} else {
692+
Cow::Borrowed(current_dir_normalize)
693+
}
694+
}
695+
678696
#[cfg(test)]
679697
mod tests {
680698
use ra_db::SourceDatabase;

0 commit comments

Comments
 (0)