diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/module/imp.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/crates/ra_hir/src/module/imp.rs b/crates/ra_hir/src/module/imp.rs index d04d24a61..f3a346152 100644 --- a/crates/ra_hir/src/module/imp.rs +++ b/crates/ra_hir/src/module/imp.rs | |||
@@ -4,6 +4,7 @@ use ra_syntax::{ | |||
4 | ast::{self, NameOwner}, | 4 | ast::{self, NameOwner}, |
5 | SmolStr, | 5 | SmolStr, |
6 | }; | 6 | }; |
7 | use relative_path::{RelativePathBuf, RelativePath}; | ||
7 | use rustc_hash::{FxHashMap, FxHashSet}; | 8 | use rustc_hash::{FxHashMap, FxHashSet}; |
8 | use arrayvec::ArrayVec; | 9 | use arrayvec::ArrayVec; |
9 | use ra_db::{SourceRoot, SourceRootId, Cancelable, FileId}; | 10 | use ra_db::{SourceRoot, SourceRootId, Cancelable, FileId}; |
@@ -65,7 +66,7 @@ fn create_module_tree<'a>( | |||
65 | let mut visited = FxHashSet::default(); | 66 | let mut visited = FxHashSet::default(); |
66 | 67 | ||
67 | let source_root = db.source_root(source_root); | 68 | let source_root = db.source_root(source_root); |
68 | for &file_id in source_root.files.iter() { | 69 | for &file_id in source_root.files.values() { |
69 | let source = ModuleSource::new_file(file_id); | 70 | let source = ModuleSource::new_file(file_id); |
70 | if visited.contains(&source) { | 71 | if visited.contains(&source) { |
71 | continue; // TODO: use explicit crate_roots here | 72 | continue; // TODO: use explicit crate_roots here |
@@ -160,7 +161,8 @@ fn resolve_submodule( | |||
160 | let file_id = source.file_id(); | 161 | let file_id = source.file_id(); |
161 | let source_root_id = db.file_source_root(file_id); | 162 | let source_root_id = db.file_source_root(file_id); |
162 | let path = db.file_relative_path(file_id); | 163 | let path = db.file_relative_path(file_id); |
163 | let dir_path = path.parent().unwrap(); | 164 | let root = RelativePathBuf::default(); |
165 | let dir_path = path.parent().unwrap_or(&root); | ||
164 | let mod_name = path.file_stem().unwrap_or("unknown"); | 166 | let mod_name = path.file_stem().unwrap_or("unknown"); |
165 | let is_dir_owner = mod_name == "mod" || mod_name == "lib" || mod_name == "main"; | 167 | let is_dir_owner = mod_name == "mod" || mod_name == "lib" || mod_name == "main"; |
166 | 168 | ||
@@ -174,14 +176,19 @@ fn resolve_submodule( | |||
174 | } else { | 176 | } else { |
175 | candidates.push(file_dir_mod.clone()); | 177 | candidates.push(file_dir_mod.clone()); |
176 | }; | 178 | }; |
177 | 179 | let sr = db.source_root(source_root_id); | |
178 | let points_to = candidates | 180 | let points_to = candidates |
179 | .into_iter() | 181 | .into_iter() |
180 | .filter_map(|path| db.source_root_file_by_path(source_root_id, path)) | 182 | .filter_map(|path| sr.files.get(&path)) |
183 | .map(|&it| it) | ||
181 | .collect::<Vec<_>>(); | 184 | .collect::<Vec<_>>(); |
182 | let problem = if points_to.is_empty() { | 185 | let problem = if points_to.is_empty() { |
183 | Some(Problem::UnresolvedModule { | 186 | Some(Problem::UnresolvedModule { |
184 | candidate: if is_dir_owner { file_mod } else { file_dir_mod }, | 187 | candidate: RelativePath::new("../").join(&if is_dir_owner { |
188 | file_mod | ||
189 | } else { | ||
190 | file_dir_mod | ||
191 | }), | ||
185 | }) | 192 | }) |
186 | } else { | 193 | } else { |
187 | None | 194 | None |