diff options
author | Aleksey Kladov <[email protected]> | 2018-12-04 20:01:53 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-04 20:01:53 +0000 |
commit | 947e3350e045aab1db9b232542425a3faa856907 (patch) | |
tree | c2e047aa204c2a1177b85b9736e9be572ae778a6 | |
parent | 45fce9034909f2f0c5f6ac70eca7cf87ec3db856 (diff) |
module-scoped defloc
-rw-r--r-- | crates/ra_hir/src/lib.rs | 27 | ||||
-rw-r--r-- | crates/ra_hir/src/module/mod.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir/src/module/nameres.rs | 23 |
3 files changed, 43 insertions, 24 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 0f84b2d61..ffc99fd5f 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -61,15 +61,18 @@ impl FnId { | |||
61 | pub struct DefId(u32); | 61 | pub struct DefId(u32); |
62 | ra_db::impl_numeric_id!(DefId); | 62 | ra_db::impl_numeric_id!(DefId); |
63 | 63 | ||
64 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
65 | pub(crate) enum DefKind { | ||
66 | Module, | ||
67 | Item, | ||
68 | } | ||
69 | |||
64 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | 70 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] |
65 | pub enum DefLoc { | 71 | pub struct DefLoc { |
66 | Module { | 72 | pub(crate) kind: DefKind, |
67 | id: ModuleId, | 73 | source_root_id: SourceRootId, |
68 | source_root: SourceRootId, | 74 | module_id: ModuleId, |
69 | }, | 75 | source_item_id: SourceItemId, |
70 | Item { | ||
71 | source_item_id: SourceItemId, | ||
72 | }, | ||
73 | } | 76 | } |
74 | 77 | ||
75 | impl DefId { | 78 | impl DefId { |
@@ -92,12 +95,12 @@ pub enum Def { | |||
92 | impl DefId { | 95 | impl DefId { |
93 | pub fn resolve(self, db: &impl HirDatabase) -> Cancelable<Def> { | 96 | pub fn resolve(self, db: &impl HirDatabase) -> Cancelable<Def> { |
94 | let loc = self.loc(db); | 97 | let loc = self.loc(db); |
95 | let res = match loc { | 98 | let res = match loc.kind { |
96 | DefLoc::Module { id, source_root } => { | 99 | DefKind::Module => { |
97 | let descr = Module::new(db, source_root, id)?; | 100 | let descr = Module::new(db, loc.source_root_id, loc.module_id)?; |
98 | Def::Module(descr) | 101 | Def::Module(descr) |
99 | } | 102 | } |
100 | DefLoc::Item { .. } => Def::Item, | 103 | DefKind::Item => Def::Item, |
101 | }; | 104 | }; |
102 | Ok(res) | 105 | Ok(res) |
103 | } | 106 | } |
diff --git a/crates/ra_hir/src/module/mod.rs b/crates/ra_hir/src/module/mod.rs index fa9ee94eb..08ce7c8d1 100644 --- a/crates/ra_hir/src/module/mod.rs +++ b/crates/ra_hir/src/module/mod.rs | |||
@@ -14,7 +14,7 @@ use ra_db::{SourceRootId, FileId, FilePosition, Cancelable}; | |||
14 | use relative_path::RelativePathBuf; | 14 | use relative_path::RelativePathBuf; |
15 | 15 | ||
16 | use crate::{ | 16 | use crate::{ |
17 | DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, | 17 | DefKind, DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, |
18 | arena::{Arena, Id}, | 18 | arena::{Arena, Id}, |
19 | }; | 19 | }; |
20 | 20 | ||
@@ -127,9 +127,11 @@ impl Module { | |||
127 | } | 127 | } |
128 | 128 | ||
129 | pub fn def_id(&self, db: &impl HirDatabase) -> DefId { | 129 | pub fn def_id(&self, db: &impl HirDatabase) -> DefId { |
130 | let def_loc = DefLoc::Module { | 130 | let def_loc = DefLoc { |
131 | id: self.module_id, | 131 | kind: DefKind::Module, |
132 | source_root: self.source_root_id, | 132 | source_root_id: self.source_root_id, |
133 | module_id: self.module_id, | ||
134 | source_item_id: self.module_id.source(&self.tree).0, | ||
133 | }; | 135 | }; |
134 | def_loc.id(db) | 136 | def_loc.id(db) |
135 | } | 137 | } |
@@ -161,7 +163,12 @@ impl Module { | |||
161 | let segments = path.segments; | 163 | let segments = path.segments; |
162 | for name in segments.iter() { | 164 | for name in segments.iter() { |
163 | let module = match curr.loc(db) { | 165 | let module = match curr.loc(db) { |
164 | DefLoc::Module { id, source_root } => Module::new(db, source_root, id)?, | 166 | DefLoc { |
167 | kind: DefKind::Module, | ||
168 | source_root_id, | ||
169 | module_id, | ||
170 | .. | ||
171 | } => Module::new(db, source_root_id, module_id)?, | ||
165 | _ => return Ok(None), | 172 | _ => return Ok(None), |
166 | }; | 173 | }; |
167 | let scope = module.scope(db)?; | 174 | let scope = module.scope(db)?; |
diff --git a/crates/ra_hir/src/module/nameres.rs b/crates/ra_hir/src/module/nameres.rs index 8529e16b3..c2b380a80 100644 --- a/crates/ra_hir/src/module/nameres.rs +++ b/crates/ra_hir/src/module/nameres.rs | |||
@@ -28,7 +28,7 @@ use ra_db::SourceRootId; | |||
28 | 28 | ||
29 | use crate::{ | 29 | use crate::{ |
30 | Cancelable, FileId, | 30 | Cancelable, FileId, |
31 | DefId, DefLoc, | 31 | DefId, DefLoc, DefKind, |
32 | SourceItemId, SourceFileItemId, SourceFileItems, | 32 | SourceItemId, SourceFileItemId, SourceFileItems, |
33 | Path, PathKind, | 33 | Path, PathKind, |
34 | HirDatabase, | 34 | HirDatabase, |
@@ -247,7 +247,10 @@ where | |||
247 | // handle submodules separatelly | 247 | // handle submodules separatelly |
248 | continue; | 248 | continue; |
249 | } | 249 | } |
250 | let def_loc = DefLoc::Item { | 250 | let def_loc = DefLoc { |
251 | kind: DefKind::Item, | ||
252 | source_root_id: self.source_root, | ||
253 | module_id, | ||
251 | source_item_id: SourceItemId { | 254 | source_item_id: SourceItemId { |
252 | file_id, | 255 | file_id, |
253 | item_id: item.id, | 256 | item_id: item.id, |
@@ -261,10 +264,12 @@ where | |||
261 | module_items.items.insert(item.name.clone(), resolution); | 264 | module_items.items.insert(item.name.clone(), resolution); |
262 | } | 265 | } |
263 | 266 | ||
264 | for (name, mod_id) in module_id.children(&self.module_tree) { | 267 | for (name, module_id) in module_id.children(&self.module_tree) { |
265 | let def_loc = DefLoc::Module { | 268 | let def_loc = DefLoc { |
266 | id: mod_id, | 269 | kind: DefKind::Module, |
267 | source_root: self.source_root, | 270 | source_root_id: self.source_root, |
271 | module_id, | ||
272 | source_item_id: module_id.source(&self.module_tree).0, | ||
268 | }; | 273 | }; |
269 | let def_id = def_loc.id(self.db); | 274 | let def_id = def_loc.id(self.db); |
270 | let resolution = Resolution { | 275 | let resolution = Resolution { |
@@ -316,7 +321,11 @@ where | |||
316 | 321 | ||
317 | if !is_last { | 322 | if !is_last { |
318 | curr = match def_id.loc(self.db) { | 323 | curr = match def_id.loc(self.db) { |
319 | DefLoc::Module { id, .. } => id, | 324 | DefLoc { |
325 | kind: DefKind::Module, | ||
326 | module_id, | ||
327 | .. | ||
328 | } => module_id, | ||
320 | _ => return, | 329 | _ => return, |
321 | } | 330 | } |
322 | } else { | 331 | } else { |