aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-04 17:07:25 +0000
committerAleksey Kladov <[email protected]>2018-11-05 09:36:38 +0000
commitcd878658d3072ee0741cd04c16d330e7d5907f94 (patch)
tree74367519b1bf6f48ef7d795684e2418c6aefb706 /crates/ra_analysis/src/descriptors
parent6502bd2c966d57bdb8fbba7f43da9ddd004d87d3 (diff)
Introduce modules_from_source fn
Diffstat (limited to 'crates/ra_analysis/src/descriptors')
-rw-r--r--crates/ra_analysis/src/descriptors/module/mod.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs
index e22489fc1..4e871d16d 100644
--- a/crates/ra_analysis/src/descriptors/module/mod.rs
+++ b/crates/ra_analysis/src/descriptors/module/mod.rs
@@ -25,15 +25,19 @@ pub(crate) struct ModuleTree {
25} 25}
26 26
27impl ModuleTree { 27impl ModuleTree {
28 pub(crate) fn modules_for_file(&self, file_id: FileId) -> Vec<ModuleId> { 28 pub(crate) fn modules_for_source(&self, source: ModuleSource) -> Vec<ModuleId> {
29 self.mods 29 self.mods
30 .iter() 30 .iter()
31 .enumerate() 31 .enumerate()
32 .filter(|(_idx, it)| it.source.is_file(file_id)) 32 .filter(|(_idx, it)| it.source == source)
33 .map(|(idx, _)| ModuleId(idx as u32)) 33 .map(|(idx, _)| ModuleId(idx as u32))
34 .collect() 34 .collect()
35 } 35 }
36 36
37 pub(crate) fn modules_for_file(&self, file_id: FileId) -> Vec<ModuleId> {
38 self.modules_for_source(ModuleSource::File(file_id))
39 }
40
37 pub(crate) fn any_module_for_file(&self, file_id: FileId) -> Option<ModuleId> { 41 pub(crate) fn any_module_for_file(&self, file_id: FileId) -> Option<ModuleId> {
38 self.modules_for_file(file_id).pop() 42 self.modules_for_file(file_id).pop()
39 } 43 }
@@ -178,10 +182,6 @@ impl ModuleSource {
178 } 182 }
179 } 183 }
180 } 184 }
181
182 fn is_file(self, file_id: FileId) -> bool {
183 self.as_file() == Some(file_id)
184 }
185} 185}
186 186
187#[derive(Hash, Debug, PartialEq, Eq)] 187#[derive(Hash, Debug, PartialEq, Eq)]