mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Better API
This commit is contained in:
parent
4bed588001
commit
17870a3e2c
@ -96,7 +96,7 @@ pub trait FileLoader {
|
|||||||
/// `#[path = "C://no/way"]`
|
/// `#[path = "C://no/way"]`
|
||||||
fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId>;
|
fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId>;
|
||||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>;
|
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>;
|
||||||
fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)>;
|
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Database which stores all significant input facts: source code and project
|
/// Database which stores all significant input facts: source code and project
|
||||||
@ -166,8 +166,25 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
|
|||||||
self.0.source_root_crates(source_root)
|
self.0.source_root_crates(source_root)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> {
|
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> {
|
||||||
self.source_root(anchor).file_set.list_some_random_files_todo(anchor)
|
fn possible_sudmobules_opt(
|
||||||
|
module_files: &FileSet,
|
||||||
|
module_file: FileId,
|
||||||
|
) -> Option<Vec<(FileId, String)>> {
|
||||||
|
// TODO kb resolve path thinks that the input is a file...
|
||||||
|
let directory_with_module_file = module_files.resolve_path(module_file, "/../")?;
|
||||||
|
let directory_with_applicable_modules =
|
||||||
|
match module_files.file_name_and_extension(module_file)? {
|
||||||
|
("mod", "rs") | ("lib", "rs") => Some(directory_with_module_file),
|
||||||
|
(directory_with_module_name, "rs") => module_files
|
||||||
|
.resolve_path(directory_with_module_file, directory_with_module_name),
|
||||||
|
_ => None,
|
||||||
|
}?;
|
||||||
|
Some(module_files.list_files(directory_with_applicable_modules))
|
||||||
|
}
|
||||||
|
|
||||||
|
possible_sudmobules_opt(&self.source_root(module_file).file_set, module_file)
|
||||||
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,9 @@ impl FileLoader for TestDB {
|
|||||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||||
}
|
}
|
||||||
|
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> {
|
||||||
|
FileLoaderDelegate(self).possible_sudmobules(module_file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestDB {
|
impl TestDB {
|
||||||
|
@ -46,4 +46,7 @@ impl FileLoader for TestDB {
|
|||||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||||
}
|
}
|
||||||
|
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> {
|
||||||
|
FileLoaderDelegate(self).possible_sudmobules(module_file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,9 @@ impl FileLoader for TestDB {
|
|||||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||||
}
|
}
|
||||||
|
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> {
|
||||||
|
FileLoaderDelegate(self).possible_sudmobules(module_file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestDB {
|
impl TestDB {
|
||||||
|
@ -120,11 +120,10 @@ impl<'a> CompletionContext<'a> {
|
|||||||
if !matches!(definition_source.value, ModuleSource::SourceFile(_)) {
|
if !matches!(definition_source.value, ModuleSource::SourceFile(_)) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let definition_source_file = definition_source.file_id.original_file(db);
|
let module_definition_source_file = definition_source.file_id.original_file(db);
|
||||||
|
let mod_declaration_candidates =
|
||||||
// TODO kb for all possible candidates
|
db.possible_sudmobules(module_definition_source_file);
|
||||||
let zz = db.list_some_random_files_todo(definition_source_file);
|
dbg!(mod_declaration_candidates);
|
||||||
dbg!(zz);
|
|
||||||
// TODO kb exlude existing children from the candidates
|
// TODO kb exlude existing children from the candidates
|
||||||
let existing_children = current_module.children(db).collect::<Vec<_>>();
|
let existing_children = current_module.children(db).collect::<Vec<_>>();
|
||||||
dbg!(existing_children);
|
dbg!(existing_children);
|
||||||
|
@ -74,8 +74,8 @@ impl FileLoader for RootDatabase {
|
|||||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||||
}
|
}
|
||||||
fn list_some_random_files_todo(&self, anchor: FileId) -> Vec<(FileId, String)> {
|
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> {
|
||||||
FileLoaderDelegate(self).list_some_random_files_todo(anchor)
|
FileLoaderDelegate(self).possible_sudmobules(module_file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,15 +20,24 @@ impl FileSet {
|
|||||||
self.files.len()
|
self.files.len()
|
||||||
}
|
}
|
||||||
pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
|
pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
|
||||||
let mut base = self.paths[&anchor].clone();
|
let mut base = dbg!(self.paths[&anchor].clone());
|
||||||
base.pop();
|
base.pop();
|
||||||
let path = base.join(path)?;
|
let path = dbg!(base).join(dbg!(path))?;
|
||||||
self.files.get(&path).copied()
|
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();
|
pub fn file_name_and_extension(&self, file: FileId) -> Option<(&str, &str)> {
|
||||||
|
self.paths[&file].file_name_and_extension()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_files(&self, directory: FileId) -> Vec<(FileId, String)> {
|
||||||
|
// 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?
|
||||||
|
// cache results in Salsa?
|
||||||
|
|
||||||
|
dbg!(directory);
|
||||||
/*
|
/*
|
||||||
[crates/vfs/src/file_set.rs:30] anchor_path = "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/lib.rs"
|
[crates/vfs/src/file_set.rs:30] directory = "/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/"
|
||||||
[crates/vfs/src/file_set.rs:31] self.files.keys() = [
|
[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/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/test_mod_2.rs",
|
||||||
@ -38,15 +47,6 @@ impl FileSet {
|
|||||||
"/Users/someonetoignore/Downloads/tmp_dir/zzzz/src/test_mod_3.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()
|
Vec::new()
|
||||||
}
|
}
|
||||||
pub fn insert(&mut self, file_id: FileId, path: VfsPath) {
|
pub fn insert(&mut self, file_id: FileId, path: VfsPath) {
|
||||||
|
@ -49,6 +49,16 @@ impl VfsPath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn file_name_and_extension(&self) -> Option<(&str, &str)> {
|
||||||
|
match &self.0 {
|
||||||
|
VfsPathRepr::PathBuf(p) => p
|
||||||
|
.file_stem()
|
||||||
|
.zip(p.extension())
|
||||||
|
.and_then(|(name, extension)| Some((name.to_str()?, extension.to_str()?))),
|
||||||
|
VfsPathRepr::VirtualPath(p) => p.file_name_and_extension(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't make this `pub`
|
// Don't make this `pub`
|
||||||
pub(crate) fn encode(&self, buf: &mut Vec<u8>) {
|
pub(crate) fn encode(&self, buf: &mut Vec<u8>) {
|
||||||
let tag = match &self.0 {
|
let tag = match &self.0 {
|
||||||
@ -268,4 +278,9 @@ impl VirtualPath {
|
|||||||
res.0 = format!("{}/{}", res.0, path);
|
res.0 = format!("{}/{}", res.0, path);
|
||||||
Some(res)
|
Some(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn file_name_and_extension(&self) -> Option<(&str, &str)> {
|
||||||
|
// TODO kb check if is a file
|
||||||
|
Some(("test_mod_1", "rs"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user