aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/base_db/src/lib.rs16
-rw-r--r--crates/hir_def/src/test_db.rs4
-rw-r--r--crates/hir_expand/src/test_db.rs4
-rw-r--r--crates/hir_ty/src/test_db.rs4
-rw-r--r--crates/ide/src/completion/completion_context.rs2
-rw-r--r--crates/ide_db/src/lib.rs4
-rw-r--r--crates/vfs/src/file_set.rs17
-rw-r--r--crates/vfs/src/vfs_path.rs13
8 files changed, 38 insertions, 26 deletions
diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs
index 1bc4690c9..3e0b6637d 100644
--- a/crates/base_db/src/lib.rs
+++ b/crates/base_db/src/lib.rs
@@ -96,7 +96,7 @@ pub trait FileLoader {
96 /// `#[path = "C://no/way"]` 96 /// `#[path = "C://no/way"]`
97 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId>; 97 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId>;
98 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>; 98 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>;
99 fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)>; 99 fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String>;
100} 100}
101 101
102/// Database which stores all significant input facts: source code and project 102/// Database which stores all significant input facts: source code and project
@@ -166,11 +166,11 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
166 self.0.source_root_crates(source_root) 166 self.0.source_root_crates(source_root)
167 } 167 }
168 168
169 fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> { 169 fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> {
170 fn possible_sudmobules_opt( 170 fn possible_sudmobules_opt(
171 module_files: &FileSet, 171 module_files: &FileSet,
172 module_file: FileId, 172 module_file: FileId,
173 ) -> Option<Vec<(FileId, String)>> { 173 ) -> Option<Vec<FileId>> {
174 match module_files.file_name_and_extension(module_file)? { 174 match module_files.file_name_and_extension(module_file)? {
175 ("mod", Some("rs")) | ("lib", Some("rs")) => { 175 ("mod", Some("rs")) | ("lib", Some("rs")) => {
176 module_files.list_files(module_file, None) 176 module_files.list_files(module_file, None)
@@ -181,8 +181,16 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
181 } 181 }
182 } 182 }
183 183
184 possible_sudmobules_opt(&self.source_root(module_file).file_set, module_file) 184 let module_files = &self.source_root(module_file).file_set;
185 possible_sudmobules_opt(module_files, module_file)
185 .unwrap_or_default() 186 .unwrap_or_default()
187 .into_iter()
188 .filter_map(|submodule_file| module_files.file_name_and_extension(submodule_file))
189 .map(|(file_name, extension)| match extension {
190 Some(extension) => format!("{}.{}", file_name, extension),
191 None => file_name.to_owned(),
192 })
193 .collect()
186 } 194 }
187} 195}
188 196
diff --git a/crates/hir_def/src/test_db.rs b/crates/hir_def/src/test_db.rs
index a35ed4f3c..5bcfaf464 100644
--- a/crates/hir_def/src/test_db.rs
+++ b/crates/hir_def/src/test_db.rs
@@ -63,8 +63,8 @@ impl FileLoader for TestDB {
63 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { 63 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
64 FileLoaderDelegate(self).relevant_crates(file_id) 64 FileLoaderDelegate(self).relevant_crates(file_id)
65 } 65 }
66 fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> { 66 fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> {
67 FileLoaderDelegate(self).possible_sudmobules(module_file) 67 FileLoaderDelegate(self).possible_sudmobule_names(module_file)
68 } 68 }
69} 69}
70 70
diff --git a/crates/hir_expand/src/test_db.rs b/crates/hir_expand/src/test_db.rs
index a0d1525b0..cf42dde7a 100644
--- a/crates/hir_expand/src/test_db.rs
+++ b/crates/hir_expand/src/test_db.rs
@@ -46,7 +46,7 @@ impl FileLoader for TestDB {
46 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { 46 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
47 FileLoaderDelegate(self).relevant_crates(file_id) 47 FileLoaderDelegate(self).relevant_crates(file_id)
48 } 48 }
49 fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> { 49 fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> {
50 FileLoaderDelegate(self).possible_sudmobules(module_file) 50 FileLoaderDelegate(self).possible_sudmobule_names(module_file)
51 } 51 }
52} 52}
diff --git a/crates/hir_ty/src/test_db.rs b/crates/hir_ty/src/test_db.rs
index 6f61e7dfe..0696f41dd 100644
--- a/crates/hir_ty/src/test_db.rs
+++ b/crates/hir_ty/src/test_db.rs
@@ -73,8 +73,8 @@ impl FileLoader for TestDB {
73 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { 73 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
74 FileLoaderDelegate(self).relevant_crates(file_id) 74 FileLoaderDelegate(self).relevant_crates(file_id)
75 } 75 }
76 fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> { 76 fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> {
77 FileLoaderDelegate(self).possible_sudmobules(module_file) 77 FileLoaderDelegate(self).possible_sudmobule_names(module_file)
78 } 78 }
79} 79}
80 80
diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs
index cbfc77a46..b4c6eeb35 100644
--- a/crates/ide/src/completion/completion_context.rs
+++ b/crates/ide/src/completion/completion_context.rs
@@ -122,7 +122,7 @@ impl<'a> CompletionContext<'a> {
122 } 122 }
123 let module_definition_source_file = definition_source.file_id.original_file(db); 123 let module_definition_source_file = definition_source.file_id.original_file(db);
124 let mod_declaration_candidates = 124 let mod_declaration_candidates =
125 db.possible_sudmobules(module_definition_source_file); 125 db.possible_sudmobule_names(module_definition_source_file);
126 dbg!(mod_declaration_candidates); 126 dbg!(mod_declaration_candidates);
127 // TODO kb exlude existing children from the candidates 127 // TODO kb exlude existing children from the candidates
128 let existing_children = current_module.children(db).collect::<Vec<_>>(); 128 let existing_children = current_module.children(db).collect::<Vec<_>>();
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs
index dc1d2b9fe..9f3be8601 100644
--- a/crates/ide_db/src/lib.rs
+++ b/crates/ide_db/src/lib.rs
@@ -74,8 +74,8 @@ impl FileLoader for RootDatabase {
74 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { 74 fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
75 FileLoaderDelegate(self).relevant_crates(file_id) 75 FileLoaderDelegate(self).relevant_crates(file_id)
76 } 76 }
77 fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> { 77 fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> {
78 FileLoaderDelegate(self).possible_sudmobules(module_file) 78 FileLoaderDelegate(self).possible_sudmobule_names(module_file)
79 } 79 }
80} 80}
81 81
diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs
index 3f49f31e5..956cffb29 100644
--- a/crates/vfs/src/file_set.rs
+++ b/crates/vfs/src/file_set.rs
@@ -34,22 +34,27 @@ impl FileSet {
34 &self, 34 &self,
35 anchor: FileId, 35 anchor: FileId,
36 anchor_relative_path: Option<&str>, 36 anchor_relative_path: Option<&str>,
37 ) -> Option<Vec<(FileId, String)>> { 37 ) -> Option<Vec<FileId>> {
38 let anchor_directory = { 38 let anchor_directory = {
39 let path = self.paths[&anchor].clone(); 39 let path = self.paths[&anchor].clone();
40 match anchor_relative_path { 40 match anchor_relative_path {
41 Some(anchor_relative_path) => path.join(anchor_relative_path), 41 Some(anchor_relative_path) => path.join(anchor_relative_path),
42 None => path.join("../"), 42 None => path.parent(),
43 } 43 }
44 }?; 44 }?;
45 45
46 Some( 46 Some(
47 self.paths 47 self.paths
48 .iter() 48 .iter()
49 .filter(|(_, path)| path.starts_with(&anchor_directory)) 49 .filter_map(|(&file_id, path)| {
50 // TODO kb need to ensure that no / exists after the anchor_directory 50 if path.parent()? == anchor_directory
51 .filter(|(_, path)| path.ends_with(".rs")) 51 && matches!(path.file_name_and_extension(), Some((_, Some("rs"))))
52 .map(|(&file_id, path)| (file_id, path.to_string())) 52 {
53 Some(file_id)
54 } else {
55 None
56 }
57 })
53 .collect(), 58 .collect(),
54 ) 59 )
55 } 60 }
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs
index f2d07038b..9a3690a89 100644
--- a/crates/vfs/src/vfs_path.rs
+++ b/crates/vfs/src/vfs_path.rs
@@ -48,10 +48,12 @@ impl VfsPath {
48 (VfsPathRepr::VirtualPath(_), _) => false, 48 (VfsPathRepr::VirtualPath(_), _) => false,
49 } 49 }
50 } 50 }
51 pub fn ends_with(&self, suffix: &str) -> bool { 51 pub fn parent(&self) -> Option<VfsPath> {
52 match &self.0 { 52 let mut parent = self.clone();
53 VfsPathRepr::PathBuf(p) => p.ends_with(suffix), 53 if parent.pop() {
54 VfsPathRepr::VirtualPath(p) => p.ends_with(suffix), 54 Some(parent)
55 } else {
56 None
55 } 57 }
56 } 58 }
57 59
@@ -265,9 +267,6 @@ impl VirtualPath {
265 fn starts_with(&self, other: &VirtualPath) -> bool { 267 fn starts_with(&self, other: &VirtualPath) -> bool {
266 self.0.starts_with(&other.0) 268 self.0.starts_with(&other.0)
267 } 269 }
268 fn ends_with(&self, suffix: &str) -> bool {
269 self.0.ends_with(suffix)
270 }
271 fn pop(&mut self) -> bool { 270 fn pop(&mut self) -> bool {
272 let pos = match self.0.rfind('/') { 271 let pos = match self.0.rfind('/') {
273 Some(pos) => pos, 272 Some(pos) => pos,