aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/base_db/src/lib.rs16
-rw-r--r--crates/ide/src/completion/completion_context.rs25
-rw-r--r--crates/ide_db/src/lib.rs3
-rw-r--r--crates/vfs/src/file_set.rs27
4 files changed, 65 insertions, 6 deletions
diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs
index ee3415850..71e85c6ac 100644
--- a/crates/base_db/src/lib.rs
+++ b/crates/base_db/src/lib.rs
@@ -96,6 +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} 100}
100 101
101/// Database which stores all significant input facts: source code and project 102/// Database which stores all significant input facts: source code and project
@@ -155,8 +156,8 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
155 } 156 }
156 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { 157 fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
157 // FIXME: this *somehow* should be platform agnostic... 158 // FIXME: this *somehow* should be platform agnostic...
158 let source_root = self.0.file_source_root(anchor); 159 // self.source_root(anchor)
159 let source_root = self.0.source_root(source_root); 160 let source_root = self.source_root(anchor);
160 source_root.file_set.resolve_path(anchor, path) 161 source_root.file_set.resolve_path(anchor, path)
161 } 162 }
162 163
@@ -164,4 +165,15 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
164 let source_root = self.0.file_source_root(file_id); 165 let source_root = self.0.file_source_root(file_id);
165 self.0.source_root_crates(source_root) 166 self.0.source_root_crates(source_root)
166 } 167 }
168
169 fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> {
170 self.source_root(anchor).file_set.list_some_random_files_todo(anchor)
171 }
172}
173
174impl<T: SourceDatabaseExt> FileLoaderDelegate<&'_ T> {
175 fn source_root(&self, anchor: FileId) -> Arc<SourceRoot> {
176 let source_root = self.0.file_source_root(anchor);
177 self.0.source_root(source_root)
178 }
167} 179}
diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs
index 47355d5dc..4d8b3670b 100644
--- a/crates/ide/src/completion/completion_context.rs
+++ b/crates/ide/src/completion/completion_context.rs
@@ -1,7 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use base_db::SourceDatabase; 3use base_db::{FileLoader, SourceDatabase};
4use hir::{Semantics, SemanticsScope, Type}; 4use hir::{ModuleSource, Semantics, SemanticsScope, Type};
5use ide_db::RootDatabase; 5use ide_db::RootDatabase;
6use syntax::{ 6use syntax::{
7 algo::{find_covering_element, find_node_at_offset}, 7 algo::{find_covering_element, find_node_at_offset},
@@ -112,6 +112,27 @@ impl<'a> CompletionContext<'a> {
112 }; 112 };
113 let fake_ident_token = 113 let fake_ident_token =
114 file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap(); 114 file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap();
115 {
116 let module_names_for_import = sema
117 .to_module_def(position.file_id)
118 .and_then(|current_module| {
119 let definition_source = current_module.definition_source(db);
120 if !matches!(definition_source.value, ModuleSource::SourceFile(_)) {
121 return None;
122 }
123 let definition_source_file = definition_source.file_id.original_file(db);
124
125 // TODO kb for all possible candidates
126 let zz = db.list_some_random_files_todo(definition_source_file);
127 dbg!(zz);
128 // TODO kb exlude existing children from the candidates
129 let existing_children = current_module.children(db).collect::<Vec<_>>();
130 dbg!(existing_children);
131 None::<Vec<String>>
132 })
133 .unwrap_or_default();
134 dbg!(module_names_for_import);
135 };
115 136
116 let krate = sema.to_module_def(position.file_id).map(|m| m.krate()); 137 let krate = sema.to_module_def(position.file_id).map(|m| m.krate());
117 let original_token = 138 let original_token =
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs
index 70ada02f3..f3197cc39 100644
--- a/crates/ide_db/src/lib.rs
+++ b/crates/ide_db/src/lib.rs
@@ -74,6 +74,9 @@ 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)> {
78 FileLoaderDelegate(self).list_some_random_files_todo(anchor)
79 }
77} 80}
78 81
79impl salsa::Database for RootDatabase { 82impl salsa::Database for RootDatabase {
diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs
index e9196fcd2..8bce17bc0 100644
--- a/crates/vfs/src/file_set.rs
+++ b/crates/vfs/src/file_set.rs
@@ -23,8 +23,31 @@ impl FileSet {
23 let mut base = self.paths[&anchor].clone(); 23 let mut base = self.paths[&anchor].clone();
24 base.pop(); 24 base.pop();
25 let path = base.join(path)?; 25 let path = base.join(path)?;
26 let res = self.files.get(&path).copied(); 26 self.files.get(&path).copied()
27 res 27 }
28 pub fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> {
29 let anchor_path = self.paths[&anchor].clone();
30 /*
31 [crates/vfs/src/file_set.rs:30] anchor_path = "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/lib.rs"
32 [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",
34 "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1/test_mod_2.rs",
35 "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1.rs",
36 "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/lib.rs",
37 "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_3/test_mod_3_1.rs",
38 "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_3.rs",
39 ]
40 */
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()
28 } 51 }
29 pub fn insert(&mut self, file_id: FileId, path: VfsPath) { 52 pub fn insert(&mut self, file_id: FileId, path: VfsPath) {
30 self.files.insert(path.clone(), file_id); 53 self.files.insert(path.clone(), file_id);