aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/module_tree.rs27
1 files changed, 13 insertions, 14 deletions
diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs
index 47c14af35..c9a15967c 100644
--- a/crates/ra_hir/src/module_tree.rs
+++ b/crates/ra_hir/src/module_tree.rs
@@ -131,6 +131,17 @@ impl ModuleTree {
131 let (res, _) = self.mods.iter().find(|(_, m)| m.source == source)?; 131 let (res, _) = self.mods.iter().find(|(_, m)| m.source == source)?;
132 Some(res) 132 Some(res)
133 } 133 }
134
135 fn alloc_mod(&mut self, data: ModuleData) -> ModuleId {
136 self.mods.alloc(data)
137 }
138
139 fn alloc_link(&mut self, data: LinkData) -> LinkId {
140 let owner = data.owner;
141 let id = self.links.alloc(data);
142 self.mods[owner].children.push(id);
143 id
144 }
134} 145}
135 146
136impl ModuleId { 147impl ModuleId {
@@ -198,18 +209,6 @@ impl LinkId {
198 } 209 }
199} 210}
200 211
201impl ModuleTree {
202 fn push_mod(&mut self, data: ModuleData) -> ModuleId {
203 self.mods.alloc(data)
204 }
205 fn push_link(&mut self, data: LinkData) -> LinkId {
206 let owner = data.owner;
207 let id = self.links.alloc(data);
208 self.mods[owner].children.push(id);
209 id
210 }
211}
212
213fn modules(root: &impl ast::ModuleItemOwner) -> impl Iterator<Item = (Name, &ast::Module)> { 212fn modules(root: &impl ast::ModuleItemOwner) -> impl Iterator<Item = (Name, &ast::Module)> {
214 root.items() 213 root.items()
215 .filter_map(|item| match item.kind() { 214 .filter_map(|item| match item.kind() {
@@ -266,13 +265,13 @@ fn build_subtree(
266 source: SourceItemId, 265 source: SourceItemId,
267) -> ModuleId { 266) -> ModuleId {
268 visited.insert(source); 267 visited.insert(source);
269 let id = tree.push_mod(ModuleData { 268 let id = tree.alloc_mod(ModuleData {
270 source, 269 source,
271 parent, 270 parent,
272 children: Vec::new(), 271 children: Vec::new(),
273 }); 272 });
274 for sub in db.submodules(source).iter() { 273 for sub in db.submodules(source).iter() {
275 let link = tree.push_link(LinkData { 274 let link = tree.alloc_link(LinkData {
276 source: sub.source, 275 source: sub.source,
277 name: sub.name.clone(), 276 name: sub.name.clone(),
278 owner: id, 277 owner: id,