diff options
Diffstat (limited to 'crates/ra_analysis/src/descriptors/module/mod.rs')
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/mod.rs | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 047454cff..cfdffcdbc 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | pub(super) mod imp; | 1 | pub(super) mod imp; |
2 | pub(crate) mod scope; | 2 | pub(super) mod nameres; |
3 | 3 | ||
4 | use std::sync::Arc; | 4 | use std::sync::Arc; |
5 | 5 | ||
@@ -18,7 +18,7 @@ use crate::{ | |||
18 | input::SourceRootId | 18 | input::SourceRootId |
19 | }; | 19 | }; |
20 | 20 | ||
21 | pub(crate) use self::scope::ModuleScope; | 21 | pub(crate) use self::{nameres::ModuleScope}; |
22 | 22 | ||
23 | /// `ModuleDescriptor` is API entry point to get all the information | 23 | /// `ModuleDescriptor` is API entry point to get all the information |
24 | /// about a particular module. | 24 | /// about a particular module. |
@@ -102,9 +102,11 @@ impl ModuleDescriptor { | |||
102 | 102 | ||
103 | /// The root of the tree this module is part of | 103 | /// The root of the tree this module is part of |
104 | pub fn crate_root(&self) -> ModuleDescriptor { | 104 | pub fn crate_root(&self) -> ModuleDescriptor { |
105 | generate(Some(self.clone()), |it| it.parent()) | 105 | let root_id = self.module_id.crate_root(&self.tree); |
106 | .last() | 106 | ModuleDescriptor { |
107 | .unwrap() | 107 | module_id: root_id, |
108 | ..self.clone() | ||
109 | } | ||
108 | } | 110 | } |
109 | 111 | ||
110 | /// `name` is `None` for the crate's root module | 112 | /// `name` is `None` for the crate's root module |
@@ -123,8 +125,10 @@ impl ModuleDescriptor { | |||
123 | } | 125 | } |
124 | 126 | ||
125 | /// Returns a `ModuleScope`: a set of items, visible in this module. | 127 | /// Returns a `ModuleScope`: a set of items, visible in this module. |
126 | pub fn scope(&self, db: &impl DescriptorDatabase) -> Cancelable<Arc<ModuleScope>> { | 128 | pub(crate) fn scope(&self, db: &impl DescriptorDatabase) -> Cancelable<ModuleScope> { |
127 | db._module_scope(self.source_root_id, self.module_id) | 129 | let item_map = db._item_map(self.source_root_id)?; |
130 | let res = item_map.per_module[&self.module_id].clone(); | ||
131 | Ok(res) | ||
128 | } | 132 | } |
129 | 133 | ||
130 | pub fn problems(&self, db: &impl DescriptorDatabase) -> Vec<(SyntaxNode, Problem)> { | 134 | pub fn problems(&self, db: &impl DescriptorDatabase) -> Vec<(SyntaxNode, Problem)> { |
@@ -146,6 +150,13 @@ pub(crate) struct ModuleTree { | |||
146 | } | 150 | } |
147 | 151 | ||
148 | impl ModuleTree { | 152 | impl ModuleTree { |
153 | fn modules<'a>(&'a self) -> impl Iterator<Item = ModuleId> + 'a { | ||
154 | self.mods | ||
155 | .iter() | ||
156 | .enumerate() | ||
157 | .map(|(idx, _)| ModuleId(idx as u32)) | ||
158 | } | ||
159 | |||
149 | fn modules_for_source(&self, source: ModuleSource) -> Vec<ModuleId> { | 160 | fn modules_for_source(&self, source: ModuleSource) -> Vec<ModuleId> { |
150 | self.mods | 161 | self.mods |
151 | .iter() | 162 | .iter() |
@@ -204,6 +215,11 @@ impl ModuleId { | |||
204 | let link = self.parent_link(tree)?; | 215 | let link = self.parent_link(tree)?; |
205 | Some(tree.link(link).owner) | 216 | Some(tree.link(link).owner) |
206 | } | 217 | } |
218 | fn crate_root(self, tree: &ModuleTree) -> ModuleId { | ||
219 | generate(Some(self), move |it| it.parent(tree)) | ||
220 | .last() | ||
221 | .unwrap() | ||
222 | } | ||
207 | fn child(self, tree: &ModuleTree, name: &str) -> Option<ModuleId> { | 223 | fn child(self, tree: &ModuleTree, name: &str) -> Option<ModuleId> { |
208 | let link = tree | 224 | let link = tree |
209 | .module(self) | 225 | .module(self) |
@@ -213,6 +229,13 @@ impl ModuleId { | |||
213 | .find(|it| it.name == name)?; | 229 | .find(|it| it.name == name)?; |
214 | Some(*link.points_to.first()?) | 230 | Some(*link.points_to.first()?) |
215 | } | 231 | } |
232 | fn children<'a>(self, tree: &'a ModuleTree) -> impl Iterator<Item = (SmolStr, ModuleId)> + 'a { | ||
233 | tree.module(self).children.iter().filter_map(move |&it| { | ||
234 | let link = tree.link(it); | ||
235 | let module = *link.points_to.first()?; | ||
236 | Some((link.name.clone(), module)) | ||
237 | }) | ||
238 | } | ||
216 | fn problems(self, tree: &ModuleTree, db: &impl SyntaxDatabase) -> Vec<(SyntaxNode, Problem)> { | 239 | fn problems(self, tree: &ModuleTree, db: &impl SyntaxDatabase) -> Vec<(SyntaxNode, Problem)> { |
217 | tree.module(self) | 240 | tree.module(self) |
218 | .children | 241 | .children |