diff options
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 87c78d98e..5a3e24e9e 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -174,15 +174,15 @@ pub use hir_def::attr::Attrs; | |||
174 | 174 | ||
175 | impl Module { | 175 | impl Module { |
176 | pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module { | 176 | pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module { |
177 | Module { id: ModuleId { krate: krate.crate_id, module_id: crate_module_id } } | 177 | Module { id: ModuleId { krate: krate.crate_id, local_id: crate_module_id } } |
178 | } | 178 | } |
179 | 179 | ||
180 | /// Name of this module. | 180 | /// Name of this module. |
181 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 181 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { |
182 | let def_map = db.crate_def_map(self.id.krate); | 182 | let def_map = db.crate_def_map(self.id.krate); |
183 | let parent = def_map[self.id.module_id].parent?; | 183 | let parent = def_map[self.id.local_id].parent?; |
184 | def_map[parent].children.iter().find_map(|(name, module_id)| { | 184 | def_map[parent].children.iter().find_map(|(name, module_id)| { |
185 | if *module_id == self.id.module_id { | 185 | if *module_id == self.id.local_id { |
186 | Some(name.clone()) | 186 | Some(name.clone()) |
187 | } else { | 187 | } else { |
188 | None | 188 | None |
@@ -206,14 +206,14 @@ impl Module { | |||
206 | /// Finds a child module with the specified name. | 206 | /// Finds a child module with the specified name. |
207 | pub fn child(self, db: &impl DefDatabase, name: &Name) -> Option<Module> { | 207 | pub fn child(self, db: &impl DefDatabase, name: &Name) -> Option<Module> { |
208 | let def_map = db.crate_def_map(self.id.krate); | 208 | let def_map = db.crate_def_map(self.id.krate); |
209 | let child_id = def_map[self.id.module_id].children.get(name)?; | 209 | let child_id = def_map[self.id.local_id].children.get(name)?; |
210 | Some(self.with_module_id(*child_id)) | 210 | Some(self.with_module_id(*child_id)) |
211 | } | 211 | } |
212 | 212 | ||
213 | /// Iterates over all child modules. | 213 | /// Iterates over all child modules. |
214 | pub fn children(self, db: &impl DefDatabase) -> impl Iterator<Item = Module> { | 214 | pub fn children(self, db: &impl DefDatabase) -> impl Iterator<Item = Module> { |
215 | let def_map = db.crate_def_map(self.id.krate); | 215 | let def_map = db.crate_def_map(self.id.krate); |
216 | let children = def_map[self.id.module_id] | 216 | let children = def_map[self.id.local_id] |
217 | .children | 217 | .children |
218 | .iter() | 218 | .iter() |
219 | .map(|(_, module_id)| self.with_module_id(*module_id)) | 219 | .map(|(_, module_id)| self.with_module_id(*module_id)) |
@@ -224,7 +224,7 @@ impl Module { | |||
224 | /// Finds a parent module. | 224 | /// Finds a parent module. |
225 | pub fn parent(self, db: &impl DefDatabase) -> Option<Module> { | 225 | pub fn parent(self, db: &impl DefDatabase) -> Option<Module> { |
226 | let def_map = db.crate_def_map(self.id.krate); | 226 | let def_map = db.crate_def_map(self.id.krate); |
227 | let parent_id = def_map[self.id.module_id].parent?; | 227 | let parent_id = def_map[self.id.local_id].parent?; |
228 | Some(self.with_module_id(parent_id)) | 228 | Some(self.with_module_id(parent_id)) |
229 | } | 229 | } |
230 | 230 | ||
@@ -240,7 +240,7 @@ impl Module { | |||
240 | 240 | ||
241 | /// Returns a `ModuleScope`: a set of items, visible in this module. | 241 | /// Returns a `ModuleScope`: a set of items, visible in this module. |
242 | pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef, Option<Import>)> { | 242 | pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef, Option<Import>)> { |
243 | db.crate_def_map(self.id.krate)[self.id.module_id] | 243 | db.crate_def_map(self.id.krate)[self.id.local_id] |
244 | .scope | 244 | .scope |
245 | .entries() | 245 | .entries() |
246 | .map(|(name, res)| { | 246 | .map(|(name, res)| { |
@@ -250,7 +250,7 @@ impl Module { | |||
250 | } | 250 | } |
251 | 251 | ||
252 | pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { | 252 | pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { |
253 | db.crate_def_map(self.id.krate).add_diagnostics(db, self.id.module_id, sink); | 253 | db.crate_def_map(self.id.krate).add_diagnostics(db, self.id.local_id, sink); |
254 | for decl in self.declarations(db) { | 254 | for decl in self.declarations(db) { |
255 | match decl { | 255 | match decl { |
256 | crate::ModuleDef::Function(f) => f.diagnostics(db, sink), | 256 | crate::ModuleDef::Function(f) => f.diagnostics(db, sink), |
@@ -275,12 +275,12 @@ impl Module { | |||
275 | 275 | ||
276 | pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> { | 276 | pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> { |
277 | let def_map = db.crate_def_map(self.id.krate); | 277 | let def_map = db.crate_def_map(self.id.krate); |
278 | def_map[self.id.module_id].scope.declarations().map(ModuleDef::from).collect() | 278 | def_map[self.id.local_id].scope.declarations().map(ModuleDef::from).collect() |
279 | } | 279 | } |
280 | 280 | ||
281 | pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> { | 281 | pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> { |
282 | let def_map = db.crate_def_map(self.id.krate); | 282 | let def_map = db.crate_def_map(self.id.krate); |
283 | def_map[self.id.module_id].impls.iter().copied().map(ImplBlock::from).collect() | 283 | def_map[self.id.local_id].impls.iter().copied().map(ImplBlock::from).collect() |
284 | } | 284 | } |
285 | 285 | ||
286 | fn with_module_id(self, module_id: LocalModuleId) -> Module { | 286 | fn with_module_id(self, module_id: LocalModuleId) -> Module { |