diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-14 08:24:29 +0100 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-14 08:24:29 +0100 |
commit | c4e2e36e4c3cdaf5243a4d481221804e2d71bc8e (patch) | |
tree | 3f000814aa05a6d5c9adec1c7058f57691ff087f /crates/ra_hir/src/nameres/collector.rs | |
parent | f1bfa8fc727356e398ad519a58c63974e6ff04c5 (diff) | |
parent | 9c75f30272d8c520089a9937544bb77423b52a5c (diff) |
Merge #1528
1528: More resolution modules with attribute path r=matklad a=andreevlex
#1211
Co-authored-by: Alexander Andreev <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/nameres/collector.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 552a1b6d9..7f765caf3 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | use std::borrow::Cow; | ||
2 | |||
1 | use arrayvec::ArrayVec; | 3 | use arrayvec::ArrayVec; |
2 | use ra_db::FileId; | 4 | use ra_db::FileId; |
3 | use ra_syntax::{ast, SmolStr}; | 5 | use ra_syntax::{ast, SmolStr}; |
@@ -84,7 +86,7 @@ struct DefCollector<DB> { | |||
84 | global_macro_scope: FxHashMap<Name, MacroDefId>, | 86 | global_macro_scope: FxHashMap<Name, MacroDefId>, |
85 | 87 | ||
86 | /// Some macro use `$tt:tt which mean we have to handle the macro perfectly | 88 | /// 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. |
88 | macro_stack_monitor: MacroStackMonitor, | 90 | macro_stack_monitor: MacroStackMonitor, |
89 | } | 91 | } |
90 | 92 | ||
@@ -649,7 +651,8 @@ fn resolve_submodule( | |||
649 | let file_dir_mod = dir_path.join(format!("{}/{}.rs", mod_name, name)); | 651 | let file_dir_mod = dir_path.join(format!("{}/{}.rs", mod_name, name)); |
650 | let mut candidates = ArrayVec::<[_; 3]>::new(); | 652 | let mut candidates = ArrayVec::<[_; 3]>::new(); |
651 | let file_attr_mod = attr_path.map(|file_path| { | 653 | 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(); | ||
653 | candidates.push(file_attr_mod.clone()); | 656 | candidates.push(file_attr_mod.clone()); |
654 | 657 | ||
655 | file_attr_mod | 658 | file_attr_mod |
@@ -675,6 +678,21 @@ fn resolve_submodule( | |||
675 | } | 678 | } |
676 | } | 679 | } |
677 | 680 | ||
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 | |||
678 | #[cfg(test)] | 696 | #[cfg(test)] |
679 | mod tests { | 697 | mod tests { |
680 | use ra_db::SourceDatabase; | 698 | use ra_db::SourceDatabase; |