diff options
Diffstat (limited to 'crates/ra_hir/src/module.rs')
-rw-r--r-- | crates/ra_hir/src/module.rs | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/crates/ra_hir/src/module.rs b/crates/ra_hir/src/module.rs index b9d36f01f..24c346984 100644 --- a/crates/ra_hir/src/module.rs +++ b/crates/ra_hir/src/module.rs | |||
@@ -7,13 +7,14 @@ use log; | |||
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | algo::generate, | 8 | algo::generate, |
9 | ast::{self, AstNode, NameOwner}, | 9 | ast::{self, AstNode, NameOwner}, |
10 | SmolStr, SyntaxNode, | 10 | SyntaxNode, |
11 | }; | 11 | }; |
12 | use ra_db::{SourceRootId, FileId, Cancelable}; | 12 | use ra_db::{SourceRootId, FileId, Cancelable}; |
13 | use relative_path::RelativePathBuf; | 13 | use relative_path::RelativePathBuf; |
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
16 | DefKind, DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate, | 16 | Def, DefKind, DefLoc, DefId, |
17 | Name, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate, | ||
17 | arena::{Arena, Id}, | 18 | arena::{Arena, Id}, |
18 | }; | 19 | }; |
19 | 20 | ||
@@ -84,7 +85,7 @@ impl Module { | |||
84 | } | 85 | } |
85 | 86 | ||
86 | /// `name` is `None` for the crate's root module | 87 | /// `name` is `None` for the crate's root module |
87 | pub fn name(&self) -> Option<SmolStr> { | 88 | pub fn name(&self) -> Option<&Name> { |
88 | let link = self.module_id.parent_link(&self.tree)?; | 89 | let link = self.module_id.parent_link(&self.tree)?; |
89 | Some(link.name(&self.tree)) | 90 | Some(link.name(&self.tree)) |
90 | } | 91 | } |
@@ -100,7 +101,7 @@ impl Module { | |||
100 | } | 101 | } |
101 | 102 | ||
102 | /// Finds a child module with the specified name. | 103 | /// Finds a child module with the specified name. |
103 | pub fn child(&self, name: &str) -> Option<Module> { | 104 | pub fn child(&self, name: &Name) -> Option<Module> { |
104 | let child_id = self.module_id.child(&self.tree, name)?; | 105 | let child_id = self.module_id.child(&self.tree, name)?; |
105 | Some(Module { | 106 | Some(Module { |
106 | module_id: child_id, | 107 | module_id: child_id, |
@@ -138,13 +139,8 @@ impl Module { | |||
138 | } else { | 139 | } else { |
139 | return Ok(PerNs::none()); | 140 | return Ok(PerNs::none()); |
140 | }; | 141 | }; |
141 | let module = match curr.loc(db) { | 142 | let module = match curr.resolve(db)? { |
142 | DefLoc { | 143 | Def::Module(it) => it, |
143 | kind: DefKind::Module, | ||
144 | source_root_id, | ||
145 | module_id, | ||
146 | .. | ||
147 | } => Module::new(db, source_root_id, module_id)?, | ||
148 | // TODO here would be the place to handle enum variants... | 144 | // TODO here would be the place to handle enum variants... |
149 | _ => return Ok(PerNs::none()), | 145 | _ => return Ok(PerNs::none()), |
150 | }; | 146 | }; |
@@ -230,15 +226,15 @@ impl ModuleId { | |||
230 | .last() | 226 | .last() |
231 | .unwrap() | 227 | .unwrap() |
232 | } | 228 | } |
233 | fn child(self, tree: &ModuleTree, name: &str) -> Option<ModuleId> { | 229 | fn child(self, tree: &ModuleTree, name: &Name) -> Option<ModuleId> { |
234 | let link = tree.mods[self] | 230 | let link = tree.mods[self] |
235 | .children | 231 | .children |
236 | .iter() | 232 | .iter() |
237 | .map(|&it| &tree.links[it]) | 233 | .map(|&it| &tree.links[it]) |
238 | .find(|it| it.name == name)?; | 234 | .find(|it| it.name == *name)?; |
239 | Some(*link.points_to.first()?) | 235 | Some(*link.points_to.first()?) |
240 | } | 236 | } |
241 | fn children<'a>(self, tree: &'a ModuleTree) -> impl Iterator<Item = (SmolStr, ModuleId)> + 'a { | 237 | fn children<'a>(self, tree: &'a ModuleTree) -> impl Iterator<Item = (Name, ModuleId)> + 'a { |
242 | tree.mods[self].children.iter().filter_map(move |&it| { | 238 | tree.mods[self].children.iter().filter_map(move |&it| { |
243 | let link = &tree.links[it]; | 239 | let link = &tree.links[it]; |
244 | let module = *link.points_to.first()?; | 240 | let module = *link.points_to.first()?; |
@@ -263,8 +259,8 @@ impl LinkId { | |||
263 | fn owner(self, tree: &ModuleTree) -> ModuleId { | 259 | fn owner(self, tree: &ModuleTree) -> ModuleId { |
264 | tree.links[self].owner | 260 | tree.links[self].owner |
265 | } | 261 | } |
266 | fn name(self, tree: &ModuleTree) -> SmolStr { | 262 | fn name(self, tree: &ModuleTree) -> &Name { |
267 | tree.links[self].name.clone() | 263 | &tree.links[self].name |
268 | } | 264 | } |
269 | fn bind_source<'a>(self, tree: &ModuleTree, db: &impl HirDatabase) -> ast::ModuleNode { | 265 | fn bind_source<'a>(self, tree: &ModuleTree, db: &impl HirDatabase) -> ast::ModuleNode { |
270 | let owner = self.owner(tree); | 266 | let owner = self.owner(tree); |
@@ -328,7 +324,7 @@ impl ModuleSource { | |||
328 | #[derive(Hash, Debug, PartialEq, Eq)] | 324 | #[derive(Hash, Debug, PartialEq, Eq)] |
329 | struct LinkData { | 325 | struct LinkData { |
330 | owner: ModuleId, | 326 | owner: ModuleId, |
331 | name: SmolStr, | 327 | name: Name, |
332 | points_to: Vec<ModuleId>, | 328 | points_to: Vec<ModuleId>, |
333 | problem: Option<Problem>, | 329 | problem: Option<Problem>, |
334 | } | 330 | } |