diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index ee341585065..71e85c6ac76 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs @@ -96,6 +96,7 @@ pub trait FileLoader { /// `#[path = "C://no/way"]` fn resolve_path(&self, anchor: FileId, path: &str) -> Option; fn relevant_crates(&self, file_id: FileId) -> Arc>; + fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)>; } /// Database which stores all significant input facts: source code and project @@ -155,8 +156,8 @@ impl FileLoader for FileLoaderDelegate<&'_ T> { } fn resolve_path(&self, anchor: FileId, path: &str) -> Option { // FIXME: this *somehow* should be platform agnostic... - let source_root = self.0.file_source_root(anchor); - let source_root = self.0.source_root(source_root); + // self.source_root(anchor) + let source_root = self.source_root(anchor); source_root.file_set.resolve_path(anchor, path) } @@ -164,4 +165,15 @@ impl FileLoader for FileLoaderDelegate<&'_ T> { let source_root = self.0.file_source_root(file_id); self.0.source_root_crates(source_root) } + + fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> { + self.source_root(anchor).file_set.list_some_random_files_todo(anchor) + } +} + +impl FileLoaderDelegate<&'_ T> { + fn source_root(&self, anchor: FileId) -> Arc { + let source_root = self.0.file_source_root(anchor); + self.0.source_root(source_root) + } } diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs index 47355d5dcba..4d8b3670b3e 100644 --- a/crates/ide/src/completion/completion_context.rs +++ b/crates/ide/src/completion/completion_context.rs @@ -1,7 +1,7 @@ //! FIXME: write short doc here -use base_db::SourceDatabase; -use hir::{Semantics, SemanticsScope, Type}; +use base_db::{FileLoader, SourceDatabase}; +use hir::{ModuleSource, Semantics, SemanticsScope, Type}; use ide_db::RootDatabase; use syntax::{ algo::{find_covering_element, find_node_at_offset}, @@ -112,6 +112,27 @@ impl<'a> CompletionContext<'a> { }; let fake_ident_token = file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap(); + { + let module_names_for_import = sema + .to_module_def(position.file_id) + .and_then(|current_module| { + let definition_source = current_module.definition_source(db); + if !matches!(definition_source.value, ModuleSource::SourceFile(_)) { + return None; + } + let definition_source_file = definition_source.file_id.original_file(db); + + // TODO kb for all possible candidates + let zz = db.list_some_random_files_todo(definition_source_file); + dbg!(zz); + // TODO kb exlude existing children from the candidates + let existing_children = current_module.children(db).collect::>(); + dbg!(existing_children); + None::> + }) + .unwrap_or_default(); + dbg!(module_names_for_import); + }; let krate = sema.to_module_def(position.file_id).map(|m| m.krate()); let original_token = diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs index 70ada02f312..f3197cc397b 100644 --- a/crates/ide_db/src/lib.rs +++ b/crates/ide_db/src/lib.rs @@ -74,6 +74,9 @@ impl FileLoader for RootDatabase { fn relevant_crates(&self, file_id: FileId) -> Arc> { FileLoaderDelegate(self).relevant_crates(file_id) } + fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> { + FileLoaderDelegate(self).list_some_random_files_todo(anchor) + } } impl salsa::Database for RootDatabase { diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs index e9196fcd2f9..8bce17bc091 100644 --- a/crates/vfs/src/file_set.rs +++ b/crates/vfs/src/file_set.rs @@ -23,8 +23,31 @@ impl FileSet { let mut base = self.paths[&anchor].clone(); base.pop(); let path = base.join(path)?; - let res = self.files.get(&path).copied(); - res + self.files.get(&path).copied() + } + pub fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> { + let anchor_path = self.paths[&anchor].clone(); + /* + [crates/vfs/src/file_set.rs:30] anchor_path = "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/lib.rs" + [crates/vfs/src/file_set.rs:31] self.files.keys() = [ + "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1/test_mod_2/test_mod_3.rs", + "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1/test_mod_2.rs", + "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_1.rs", + "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/lib.rs", + "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_3/test_mod_3_1.rs", + "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_3.rs", + ] + */ + + // TODO kb determine the ways to list all applicable files + // Maybe leave list directory here only and the move the rest of the logic into the database impl? + + // Need to get the following things: + // * name of the anchor_path file (file_name, validate that it's a file!) + // * list of all files in the file's contai/ning directory (file_dir) + // * list of all files in `file_dir/file_name` or just `file_dir/`, for lib.rs or mod.rs + // * consider special case for /src/bin/foo.rs as a mod<|> source + Vec::new() } pub fn insert(&mut self, file_id: FileId, path: VfsPath) { self.files.insert(path.clone(), file_id);