aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/Cargo.toml1
-rw-r--r--crates/ra_hir/src/module/imp.rs37
2 files changed, 20 insertions, 18 deletions
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml
index 1b9e148b2..61650cee9 100644
--- a/crates/ra_hir/Cargo.toml
+++ b/crates/ra_hir/Cargo.toml
@@ -5,6 +5,7 @@ version = "0.1.0"
5authors = ["Aleksey Kladov <[email protected]>"] 5authors = ["Aleksey Kladov <[email protected]>"]
6 6
7[dependencies] 7[dependencies]
8arrayvec = "0.4.9"
8log = "0.4.5" 9log = "0.4.5"
9relative-path = "0.4.0" 10relative-path = "0.4.0"
10salsa = "0.8.0" 11salsa = "0.8.0"
diff --git a/crates/ra_hir/src/module/imp.rs b/crates/ra_hir/src/module/imp.rs
index 4a19842c4..d04d24a61 100644
--- a/crates/ra_hir/src/module/imp.rs
+++ b/crates/ra_hir/src/module/imp.rs
@@ -4,9 +4,9 @@ use ra_syntax::{
4 ast::{self, NameOwner}, 4 ast::{self, NameOwner},
5 SmolStr, 5 SmolStr,
6}; 6};
7use relative_path::RelativePathBuf;
8use rustc_hash::{FxHashMap, FxHashSet}; 7use rustc_hash::{FxHashMap, FxHashSet};
9use ra_db::{SourceRoot, SourceRootId, FileResolverImp, Cancelable, FileId,}; 8use arrayvec::ArrayVec;
9use ra_db::{SourceRoot, SourceRootId, Cancelable, FileId};
10 10
11use crate::{ 11use crate::{
12 HirDatabase, 12 HirDatabase,
@@ -110,8 +110,7 @@ fn build_subtree(
110 110
111 let (points_to, problem) = match sub { 111 let (points_to, problem) = match sub {
112 Submodule::Declaration(name) => { 112 Submodule::Declaration(name) => {
113 let (points_to, problem) = 113 let (points_to, problem) = resolve_submodule(db, source, &name);
114 resolve_submodule(source, &name, &source_root.file_resolver);
115 let points_to = points_to 114 let points_to = points_to
116 .into_iter() 115 .into_iter()
117 .map(|file_id| match roots.remove(&file_id) { 116 .map(|file_id| match roots.remove(&file_id) {
@@ -153,30 +152,32 @@ fn build_subtree(
153} 152}
154 153
155fn resolve_submodule( 154fn resolve_submodule(
155 db: &impl HirDatabase,
156 source: ModuleSource, 156 source: ModuleSource,
157 name: &SmolStr, 157 name: &SmolStr,
158 file_resolver: &FileResolverImp,
159) -> (Vec<FileId>, Option<Problem>) { 158) -> (Vec<FileId>, Option<Problem>) {
160 // TODO: handle submodules of inline modules properly 159 // FIXME: handle submodules of inline modules properly
161 let file_id = source.file_id(); 160 let file_id = source.file_id();
162 let mod_name = file_resolver.file_stem(file_id); 161 let source_root_id = db.file_source_root(file_id);
162 let path = db.file_relative_path(file_id);
163 let dir_path = path.parent().unwrap();
164 let mod_name = path.file_stem().unwrap_or("unknown");
163 let is_dir_owner = mod_name == "mod" || mod_name == "lib" || mod_name == "main"; 165 let is_dir_owner = mod_name == "mod" || mod_name == "lib" || mod_name == "main";
164 166
165 let file_mod = RelativePathBuf::from(format!("../{}.rs", name)); 167 let file_mod = dir_path.join(format!("{}.rs", name));
166 let dir_mod = RelativePathBuf::from(format!("../{}/mod.rs", name)); 168 let dir_mod = dir_path.join(format!("{}/mod.rs", name));
167 let file_dir_mod = RelativePathBuf::from(format!("../{}/{}.rs", mod_name, name)); 169 let file_dir_mod = dir_path.join(format!("{}/{}.rs", mod_name, name));
168 let tmp1; 170 let mut candidates = ArrayVec::<[_; 2]>::new();
169 let tmp2; 171 if is_dir_owner {
170 let candidates = if is_dir_owner { 172 candidates.push(file_mod.clone());
171 tmp1 = [&file_mod, &dir_mod]; 173 candidates.push(dir_mod);
172 tmp1.iter()
173 } else { 174 } else {
174 tmp2 = [&file_dir_mod]; 175 candidates.push(file_dir_mod.clone());
175 tmp2.iter()
176 }; 176 };
177 177
178 let points_to = candidates 178 let points_to = candidates
179 .filter_map(|path| file_resolver.resolve(file_id, path)) 179 .into_iter()
180 .filter_map(|path| db.source_root_file_by_path(source_root_id, path))
180 .collect::<Vec<_>>(); 181 .collect::<Vec<_>>();
181 let problem = if points_to.is_empty() { 182 let problem = if points_to.is_empty() {
182 Some(Problem::UnresolvedModule { 183 Some(Problem::UnresolvedModule {