aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-27 18:45:05 +0000
committerGitHub <[email protected]>2019-11-27 18:45:05 +0000
commit360f6b7bb32d6280ed787075c4a54f4e5b46fcb6 (patch)
tree4c059427819ef442c785125f48fe83f81f6d667a /crates/ra_hir
parent4946169a96f3d442f463724af481fdb760381ccb (diff)
parent27b362b05910c81fd5b28f6cd5d2c075311032f9 (diff)
Merge #2430
2430: rename ra_ide_api -> ra_ide r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs20
-rw-r--r--crates/ra_hir/src/code_model/src.rs4
-rw-r--r--crates/ra_hir/src/from_source.rs13
3 files changed, 18 insertions, 19 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
175impl Module { 175impl 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 {
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index 076d86f2b..bf3ee0834 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -22,7 +22,7 @@ impl Module {
22 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. 22 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
23 pub fn definition_source(self, db: &impl DefDatabase) -> Source<ModuleSource> { 23 pub fn definition_source(self, db: &impl DefDatabase) -> Source<ModuleSource> {
24 let def_map = db.crate_def_map(self.id.krate); 24 let def_map = db.crate_def_map(self.id.krate);
25 let src = def_map[self.id.module_id].definition_source(db); 25 let src = def_map[self.id.local_id].definition_source(db);
26 src.map(|it| match it { 26 src.map(|it| match it {
27 Either::A(it) => ModuleSource::SourceFile(it), 27 Either::A(it) => ModuleSource::SourceFile(it),
28 Either::B(it) => ModuleSource::Module(it), 28 Either::B(it) => ModuleSource::Module(it),
@@ -33,7 +33,7 @@ impl Module {
33 /// `None` for the crate root. 33 /// `None` for the crate root.
34 pub fn declaration_source(self, db: &impl DefDatabase) -> Option<Source<ast::Module>> { 34 pub fn declaration_source(self, db: &impl DefDatabase) -> Option<Source<ast::Module>> {
35 let def_map = db.crate_def_map(self.id.krate); 35 let def_map = db.crate_def_map(self.id.krate);
36 def_map[self.id.module_id].declaration_source(db) 36 def_map[self.id.local_id].declaration_source(db)
37 } 37 }
38} 38}
39 39
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index 95db7161b..9f7c22b21 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -262,13 +262,12 @@ impl Module {
262 262
263 let original_file = src.file_id.original_file(db); 263 let original_file = src.file_id.original_file(db);
264 264
265 let (krate, module_id) = 265 let (krate, local_id) = db.relevant_crates(original_file).iter().find_map(|&crate_id| {
266 db.relevant_crates(original_file).iter().find_map(|&crate_id| { 266 let crate_def_map = db.crate_def_map(crate_id);
267 let crate_def_map = db.crate_def_map(crate_id); 267 let local_id = crate_def_map.modules_for_file(original_file).next()?;
268 let local_module_id = crate_def_map.modules_for_file(original_file).next()?; 268 Some((crate_id, local_id))
269 Some((crate_id, local_module_id)) 269 })?;
270 })?; 270 Some(Module { id: ModuleId { krate, local_id } })
271 Some(Module { id: ModuleId { krate, module_id } })
272 } 271 }
273} 272}
274 273