mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
Happy path implemented
This commit is contained in:
parent
0de71f7bc9
commit
8aa740dab4
@ -96,7 +96,7 @@ pub trait FileLoader {
|
||||
/// `#[path = "C://no/way"]`
|
||||
fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId>;
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>;
|
||||
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)>;
|
||||
fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String>;
|
||||
}
|
||||
|
||||
/// Database which stores all significant input facts: source code and project
|
||||
@ -166,11 +166,11 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
|
||||
self.0.source_root_crates(source_root)
|
||||
}
|
||||
|
||||
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> {
|
||||
fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> {
|
||||
fn possible_sudmobules_opt(
|
||||
module_files: &FileSet,
|
||||
module_file: FileId,
|
||||
) -> Option<Vec<(FileId, String)>> {
|
||||
) -> Option<Vec<FileId>> {
|
||||
match module_files.file_name_and_extension(module_file)? {
|
||||
("mod", Some("rs")) | ("lib", Some("rs")) => {
|
||||
module_files.list_files(module_file, None)
|
||||
@ -181,8 +181,16 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
|
||||
}
|
||||
}
|
||||
|
||||
possible_sudmobules_opt(&self.source_root(module_file).file_set, module_file)
|
||||
let module_files = &self.source_root(module_file).file_set;
|
||||
possible_sudmobules_opt(module_files, module_file)
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.filter_map(|submodule_file| module_files.file_name_and_extension(submodule_file))
|
||||
.map(|(file_name, extension)| match extension {
|
||||
Some(extension) => format!("{}.{}", file_name, extension),
|
||||
None => file_name.to_owned(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,8 +63,8 @@ impl FileLoader for TestDB {
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||
}
|
||||
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> {
|
||||
FileLoaderDelegate(self).possible_sudmobules(module_file)
|
||||
fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> {
|
||||
FileLoaderDelegate(self).possible_sudmobule_names(module_file)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ impl FileLoader for TestDB {
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||
}
|
||||
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> {
|
||||
FileLoaderDelegate(self).possible_sudmobules(module_file)
|
||||
fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> {
|
||||
FileLoaderDelegate(self).possible_sudmobule_names(module_file)
|
||||
}
|
||||
}
|
||||
|
@ -73,8 +73,8 @@ impl FileLoader for TestDB {
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||
}
|
||||
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> {
|
||||
FileLoaderDelegate(self).possible_sudmobules(module_file)
|
||||
fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> {
|
||||
FileLoaderDelegate(self).possible_sudmobule_names(module_file)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ impl<'a> CompletionContext<'a> {
|
||||
}
|
||||
let module_definition_source_file = definition_source.file_id.original_file(db);
|
||||
let mod_declaration_candidates =
|
||||
db.possible_sudmobules(module_definition_source_file);
|
||||
db.possible_sudmobule_names(module_definition_source_file);
|
||||
dbg!(mod_declaration_candidates);
|
||||
// TODO kb exlude existing children from the candidates
|
||||
let existing_children = current_module.children(db).collect::<Vec<_>>();
|
||||
|
@ -74,8 +74,8 @@ impl FileLoader for RootDatabase {
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
|
||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||
}
|
||||
fn possible_sudmobules(&self, module_file: FileId) -> Vec<(FileId, String)> {
|
||||
FileLoaderDelegate(self).possible_sudmobules(module_file)
|
||||
fn possible_sudmobule_names(&self, module_file: FileId) -> Vec<String> {
|
||||
FileLoaderDelegate(self).possible_sudmobule_names(module_file)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,22 +34,27 @@ impl FileSet {
|
||||
&self,
|
||||
anchor: FileId,
|
||||
anchor_relative_path: Option<&str>,
|
||||
) -> Option<Vec<(FileId, String)>> {
|
||||
) -> Option<Vec<FileId>> {
|
||||
let anchor_directory = {
|
||||
let path = self.paths[&anchor].clone();
|
||||
match anchor_relative_path {
|
||||
Some(anchor_relative_path) => path.join(anchor_relative_path),
|
||||
None => path.join("../"),
|
||||
None => path.parent(),
|
||||
}
|
||||
}?;
|
||||
|
||||
Some(
|
||||
self.paths
|
||||
.iter()
|
||||
.filter(|(_, path)| path.starts_with(&anchor_directory))
|
||||
// TODO kb need to ensure that no / exists after the anchor_directory
|
||||
.filter(|(_, path)| path.ends_with(".rs"))
|
||||
.map(|(&file_id, path)| (file_id, path.to_string()))
|
||||
.filter_map(|(&file_id, path)| {
|
||||
if path.parent()? == anchor_directory
|
||||
&& matches!(path.file_name_and_extension(), Some((_, Some("rs"))))
|
||||
{
|
||||
Some(file_id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
@ -48,10 +48,12 @@ impl VfsPath {
|
||||
(VfsPathRepr::VirtualPath(_), _) => false,
|
||||
}
|
||||
}
|
||||
pub fn ends_with(&self, suffix: &str) -> bool {
|
||||
match &self.0 {
|
||||
VfsPathRepr::PathBuf(p) => p.ends_with(suffix),
|
||||
VfsPathRepr::VirtualPath(p) => p.ends_with(suffix),
|
||||
pub fn parent(&self) -> Option<VfsPath> {
|
||||
let mut parent = self.clone();
|
||||
if parent.pop() {
|
||||
Some(parent)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,9 +267,6 @@ impl VirtualPath {
|
||||
fn starts_with(&self, other: &VirtualPath) -> bool {
|
||||
self.0.starts_with(&other.0)
|
||||
}
|
||||
fn ends_with(&self, suffix: &str) -> bool {
|
||||
self.0.ends_with(suffix)
|
||||
}
|
||||
fn pop(&mut self) -> bool {
|
||||
let pos = match self.0.rfind('/') {
|
||||
Some(pos) => pos,
|
||||
|
Loading…
Reference in New Issue
Block a user