mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Introduce modules_from_source fn
This commit is contained in:
parent
6502bd2c96
commit
cd878658d3
1 changed files with 6 additions and 6 deletions
|
@ -25,15 +25,19 @@ pub(crate) struct ModuleTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleTree {
|
impl ModuleTree {
|
||||||
pub(crate) fn modules_for_file(&self, file_id: FileId) -> Vec<ModuleId> {
|
pub(crate) fn modules_for_source(&self, source: ModuleSource) -> Vec<ModuleId> {
|
||||||
self.mods
|
self.mods
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|(_idx, it)| it.source.is_file(file_id))
|
.filter(|(_idx, it)| it.source == source)
|
||||||
.map(|(idx, _)| ModuleId(idx as u32))
|
.map(|(idx, _)| ModuleId(idx as u32))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn modules_for_file(&self, file_id: FileId) -> Vec<ModuleId> {
|
||||||
|
self.modules_for_source(ModuleSource::File(file_id))
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn any_module_for_file(&self, file_id: FileId) -> Option<ModuleId> {
|
pub(crate) fn any_module_for_file(&self, file_id: FileId) -> Option<ModuleId> {
|
||||||
self.modules_for_file(file_id).pop()
|
self.modules_for_file(file_id).pop()
|
||||||
}
|
}
|
||||||
|
@ -178,10 +182,6 @@ impl ModuleSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_file(self, file_id: FileId) -> bool {
|
|
||||||
self.as_file() == Some(file_id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Hash, Debug, PartialEq, Eq)]
|
#[derive(Hash, Debug, PartialEq, Eq)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue