Skip to content

Commit 9c75f30

Browse files
committed
Fixed request comments
1 parent 22b863c commit 9c75f30

File tree

2 files changed

+72
-66
lines changed

2 files changed

+72
-66
lines changed

crates/ra_hir/src/nameres/collector.rs

+13-7
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};
@@ -650,7 +652,7 @@ fn resolve_submodule(
650652
let mut candidates = ArrayVec::<[_; 3]>::new();
651653
let file_attr_mod = attr_path.map(|file_path| {
652654
let file_path = normalize_attribute_path(file_path);
653-
let file_attr_mod = dir_path.join(file_path).normalize();
655+
let file_attr_mod = dir_path.join(file_path.as_ref()).normalize();
654656
candidates.push(file_attr_mod.clone());
655657

656658
file_attr_mod
@@ -676,14 +678,18 @@ fn resolve_submodule(
676678
}
677679
}
678680

679-
fn normalize_attribute_path(file_path: &SmolStr) -> String {
681+
fn normalize_attribute_path(file_path: &SmolStr) -> Cow<str> {
680682
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()..])
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, "/"))
685691
} else {
686-
separator(file_path.as_str())
692+
Cow::Borrowed(current_dir_normalize)
687693
}
688694
}
689695

0 commit comments

Comments
 (0)