diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-27 15:55:47 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-27 15:55:47 +0000 |
commit | 3f4f50baaa21cb2d0f6c102f1ca521946071a8dc (patch) | |
tree | 2de93a338992d963f265ef35b53e55f8d3f1ec66 /crates/ra_hir/src/module_tree.rs | |
parent | b2b62b9579e9eefbce27b8a9b799fbd59438ce36 (diff) | |
parent | b775fa285c985821f38f09c25507d80ee793ecfd (diff) |
Merge #690
690: Fix module resolution for non standard filenames r=matklad a=regiontog
fixes #668
Co-authored-by: Erlend Tobiassen <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/module_tree.rs')
-rw-r--r-- | crates/ra_hir/src/module_tree.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs index d1dc3fa4b..893c375b5 100644 --- a/crates/ra_hir/src/module_tree.rs +++ b/crates/ra_hir/src/module_tree.rs | |||
@@ -172,6 +172,7 @@ impl ModuleTree { | |||
172 | file_id: HirFileId, | 172 | file_id: HirFileId, |
173 | decl_id: Option<SourceFileItemId>, | 173 | decl_id: Option<SourceFileItemId>, |
174 | ) -> ModuleId { | 174 | ) -> ModuleId { |
175 | let is_root = parent.is_none(); | ||
175 | let id = self.alloc_mod(ModuleData { | 176 | let id = self.alloc_mod(ModuleData { |
176 | file_id, | 177 | file_id, |
177 | decl_id, | 178 | decl_id, |
@@ -191,7 +192,7 @@ impl ModuleTree { | |||
191 | }); | 192 | }); |
192 | 193 | ||
193 | let (points_to, problem) = if sub.is_declaration { | 194 | let (points_to, problem) = if sub.is_declaration { |
194 | let (points_to, problem) = resolve_submodule(db, file_id, &sub.name); | 195 | let (points_to, problem) = resolve_submodule(db, file_id, &sub.name, is_root); |
195 | let points_to = points_to | 196 | let points_to = points_to |
196 | .into_iter() | 197 | .into_iter() |
197 | .map(|file_id| { | 198 | .map(|file_id| { |
@@ -295,6 +296,7 @@ fn resolve_submodule( | |||
295 | db: &impl HirDatabase, | 296 | db: &impl HirDatabase, |
296 | file_id: HirFileId, | 297 | file_id: HirFileId, |
297 | name: &Name, | 298 | name: &Name, |
299 | is_root: bool, | ||
298 | ) -> (Vec<FileId>, Option<Problem>) { | 300 | ) -> (Vec<FileId>, Option<Problem>) { |
299 | // FIXME: handle submodules of inline modules properly | 301 | // FIXME: handle submodules of inline modules properly |
300 | let file_id = file_id.original_file(db); | 302 | let file_id = file_id.original_file(db); |
@@ -303,7 +305,7 @@ fn resolve_submodule( | |||
303 | let root = RelativePathBuf::default(); | 305 | let root = RelativePathBuf::default(); |
304 | let dir_path = path.parent().unwrap_or(&root); | 306 | let dir_path = path.parent().unwrap_or(&root); |
305 | let mod_name = path.file_stem().unwrap_or("unknown"); | 307 | let mod_name = path.file_stem().unwrap_or("unknown"); |
306 | let is_dir_owner = mod_name == "mod" || mod_name == "lib" || mod_name == "main"; | 308 | let is_dir_owner = is_root || mod_name == "mod"; |
307 | 309 | ||
308 | let file_mod = dir_path.join(format!("{}.rs", name)); | 310 | let file_mod = dir_path.join(format!("{}.rs", name)); |
309 | let dir_mod = dir_path.join(format!("{}/mod.rs", name)); | 311 | let dir_mod = dir_path.join(format!("{}/mod.rs", name)); |