diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/base_db/src/lib.rs | 23 | ||||
-rw-r--r-- | crates/hir_def/src/test_db.rs | 3 | ||||
-rw-r--r-- | crates/hir_expand/src/test_db.rs | 3 | ||||
-rw-r--r-- | crates/hir_ty/src/test_db.rs | 3 | ||||
-rw-r--r-- | crates/ide/src/completion/completion_context.rs | 9 | ||||
-rw-r--r-- | crates/ide_db/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/vfs/src/file_set.rs | 28 | ||||
-rw-r--r-- | crates/vfs/src/vfs_path.rs | 15 |
8 files changed, 64 insertions, 24 deletions
diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index 71e85c6ac..37a8432bd 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 list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)>; | 99 | fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, 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,8 +166,25 @@ 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 list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> { | 169 | fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> { |
170 | self.source_root(anchor).file_set.list_some_random_files_todo(anchor) | 170 | fn possible_sudmobules_opt( |
171 | module_files: &FileSet, | ||
172 | module_file: FileId, | ||
173 | ) -> Option<Vec<(FileId, String)>> { | ||
174 | // TODO kb resolve path thinks that the input is a file... | ||
175 | let directory_with_module_file = module_files.resolve_path(module_file, "/../")?; | ||
176 | let directory_with_applicable_modules = | ||
177 | match module_files.file_name_and_extension(module_file)? { | ||
178 | ("mod", "rs") | ("lib", "rs") => Some(directory_with_module_file), | ||
179 | (directory_with_module_name, "rs") => module_files | ||
180 | .resolve_path(directory_with_module_file, directory_with_module_name), | ||
181 | _ => None, | ||
182 | }?; | ||
183 | Some(module_files.list_files(directory_with_applicable_modules)) | ||
184 | } | ||
185 | |||
186 | possible_sudmobules_opt(&self.source_root(module_file).file_set, module_file) | ||
187 | .unwrap_or_default() | ||
171 | } | 188 | } |
172 | } | 189 | } |
173 | 190 | ||
diff --git a/crates/hir_def/src/test_db.rs b/crates/hir_def/src/test_db.rs index 42a762936..a35ed4f3c 100644 --- a/crates/hir_def/src/test_db.rs +++ b/crates/hir_def/src/test_db.rs | |||
@@ -63,6 +63,9 @@ 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)> { | ||
67 | FileLoaderDelegate(self).possible_sudmobules(module_file) | ||
68 | } | ||
66 | } | 69 | } |
67 | 70 | ||
68 | impl TestDB { | 71 | impl TestDB { |
diff --git a/crates/hir_expand/src/test_db.rs b/crates/hir_expand/src/test_db.rs index 86a5d867e..a0d1525b0 100644 --- a/crates/hir_expand/src/test_db.rs +++ b/crates/hir_expand/src/test_db.rs | |||
@@ -46,4 +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)> { | ||
50 | FileLoaderDelegate(self).possible_sudmobules(module_file) | ||
51 | } | ||
49 | } | 52 | } |
diff --git a/crates/hir_ty/src/test_db.rs b/crates/hir_ty/src/test_db.rs index 15b8435e9..6f61e7dfe 100644 --- a/crates/hir_ty/src/test_db.rs +++ b/crates/hir_ty/src/test_db.rs | |||
@@ -73,6 +73,9 @@ 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)> { | ||
77 | FileLoaderDelegate(self).possible_sudmobules(module_file) | ||
78 | } | ||
76 | } | 79 | } |
77 | 80 | ||
78 | impl TestDB { | 81 | impl TestDB { |
diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs index 4d8b3670b..cbfc77a46 100644 --- a/crates/ide/src/completion/completion_context.rs +++ b/crates/ide/src/completion/completion_context.rs | |||
@@ -120,11 +120,10 @@ impl<'a> CompletionContext<'a> { | |||
120 | if !matches!(definition_source.value, ModuleSource::SourceFile(_)) { | 120 | if !matches!(definition_source.value, ModuleSource::SourceFile(_)) { |
121 | return None; | 121 | return None; |
122 | } | 122 | } |
123 | let definition_source_file = definition_source.file_id.original_file(db); | 123 | let module_definition_source_file = definition_source.file_id.original_file(db); |
124 | 124 | let mod_declaration_candidates = | |
125 | // TODO kb for all possible candidates | 125 | db.possible_sudmobules(module_definition_source_file); |
126 | let zz = db.list_some_random_files_todo(definition_source_file); | 126 | dbg!(mod_declaration_candidates); |
127 | dbg!(zz); | ||
128 | // TODO kb exlude existing children from the candidates | 127 | // TODO kb exlude existing children from the candidates |
129 | let existing_children = current_module.children(db).collect::<Vec<_>>(); | 128 | let existing_children = current_module.children(db).collect::<Vec<_>>(); |
130 | dbg!(existing_children); | 129 | dbg!(existing_children); |
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs index f3197cc39..dc1d2b9fe 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 list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> { | 77 | fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> { |
78 | FileLoaderDelegate(self).list_some_random_files_todo(anchor) | 78 | FileLoaderDelegate(self).possible_sudmobules(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 8bce17bc0..0caddc3bc 100644 --- a/crates/vfs/src/file_set.rs +++ b/crates/vfs/src/file_set.rs | |||
@@ -20,15 +20,24 @@ impl FileSet { | |||
20 | self.files.len() | 20 | self.files.len() |
21 | } | 21 | } |
22 | pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { | 22 | pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
23 | let mut base = self.paths[&anchor].clone(); | 23 | let mut base = dbg!(self.paths[&anchor].clone()); |
24 | base.pop(); | 24 | base.pop(); |
25 | let path = base.join(path)?; | 25 | let path = dbg!(base).join(dbg!(path))?; |
26 | self.files.get(&path).copied() | 26 | self.files.get(&path).copied() |
27 | } | 27 | } |
28 | pub fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> { | 28 | |
29 | let anchor_path = self.paths[&anchor].clone(); | 29 | pub fn file_name_and_extension(&self, file: FileId) -> Option<(&str, &str)> { |
30 | self.paths[&file].file_name_and_extension() | ||
31 | } | ||
32 | |||
33 | pub fn list_files(&self, directory: FileId) -> Vec<(FileId, String)> { | ||
34 | // TODO kb determine the ways to list all applicable files | ||
35 | // Maybe leave list directory here only and the move the rest of the logic into the database impl? | ||
36 | // cache results in Salsa? | ||
37 | |||
38 | dbg!(directory); | ||
30 | /* | 39 | /* |
31 | [crates/vfs/src/file_set.rs:30] anchor_path = "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/lib.rs" | 40 | [crates/vfs/src/file_set.rs:30] directory = "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/" |
32 | [crates/vfs/src/file_set.rs:31] self.files.keys() = [ | 41 | [crates/vfs/src/file_set.rs:31] self.files.keys() = [ |
33 | "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1/test_mod_2/test_mod_3.rs", | 42 | "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1/test_mod_2/test_mod_3.rs", |
34 | "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1/test_mod_2.rs", | 43 | "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1/test_mod_2.rs", |
@@ -38,15 +47,6 @@ impl FileSet { | |||
38 | "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_3.rs", | 47 | "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_3.rs", |
39 | ] | 48 | ] |
40 | */ | 49 | */ |
41 | |||
42 | // TODO kb determine the ways to list all applicable files | ||
43 | // Maybe leave list directory here only and the move the rest of the logic into the database impl? | ||
44 | |||
45 | // Need to get the following things: | ||
46 | // * name of the anchor_path file (file_name, validate that it's a file!) | ||
47 | // * list of all files in the file's contai/ning directory (file_dir) | ||
48 | // * list of all files in `file_dir/file_name` or just `file_dir/`, for lib.rs or mod.rs | ||
49 | // * consider special case for /src/bin/foo.rs as a mod<|> source | ||
50 | Vec::new() | 50 | Vec::new() |
51 | } | 51 | } |
52 | pub fn insert(&mut self, file_id: FileId, path: VfsPath) { | 52 | pub fn insert(&mut self, file_id: FileId, path: VfsPath) { |
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs index 944a702df..7b965bb4c 100644 --- a/crates/vfs/src/vfs_path.rs +++ b/crates/vfs/src/vfs_path.rs | |||
@@ -49,6 +49,16 @@ impl VfsPath { | |||
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | pub fn file_name_and_extension(&self) -> Option<(&str, &str)> { | ||
53 | match &self.0 { | ||
54 | VfsPathRepr::PathBuf(p) => p | ||
55 | .file_stem() | ||
56 | .zip(p.extension()) | ||
57 | .and_then(|(name, extension)| Some((name.to_str()?, extension.to_str()?))), | ||
58 | VfsPathRepr::VirtualPath(p) => p.file_name_and_extension(), | ||
59 | } | ||
60 | } | ||
61 | |||
52 | // Don't make this `pub` | 62 | // Don't make this `pub` |
53 | pub(crate) fn encode(&self, buf: &mut Vec<u8>) { | 63 | pub(crate) fn encode(&self, buf: &mut Vec<u8>) { |
54 | let tag = match &self.0 { | 64 | let tag = match &self.0 { |
@@ -268,4 +278,9 @@ impl VirtualPath { | |||
268 | res.0 = format!("{}/{}", res.0, path); | 278 | res.0 = format!("{}/{}", res.0, path); |
269 | Some(res) | 279 | Some(res) |
270 | } | 280 | } |
281 | |||
282 | pub fn file_name_and_extension(&self) -> Option<(&str, &str)> { | ||
283 | // TODO kb check if is a file | ||
284 | Some(("test_mod_1", "rs")) | ||
285 | } | ||
271 | } | 286 | } |