diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 911c809fd..78c444037 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -55,7 +55,9 @@ pub struct CrateDependency { | |||
55 | impl Crate { | 55 | impl Crate { |
56 | pub fn dependencies(self, db: &impl DefDatabase) -> Vec<CrateDependency> { | 56 | pub fn dependencies(self, db: &impl DefDatabase) -> Vec<CrateDependency> { |
57 | db.crate_graph() | 57 | db.crate_graph() |
58 | .dependencies(self.id) | 58 | .crate_data(&self.id) |
59 | .dependencies | ||
60 | .iter() | ||
59 | .map(|dep| { | 61 | .map(|dep| { |
60 | let krate = Crate { id: dep.crate_id() }; | 62 | let krate = Crate { id: dep.crate_id() }; |
61 | let name = dep.as_name(); | 63 | let name = dep.as_name(); |
@@ -69,7 +71,9 @@ impl Crate { | |||
69 | let crate_graph = db.crate_graph(); | 71 | let crate_graph = db.crate_graph(); |
70 | crate_graph | 72 | crate_graph |
71 | .iter() | 73 | .iter() |
72 | .filter(|&krate| crate_graph.dependencies(krate).any(|it| it.crate_id == self.id)) | 74 | .filter(|&krate| { |
75 | crate_graph.crate_data(&krate).dependencies.iter().any(|it| it.crate_id == self.id) | ||
76 | }) | ||
73 | .map(|id| Crate { id }) | 77 | .map(|id| Crate { id }) |
74 | .collect() | 78 | .collect() |
75 | } | 79 | } |
@@ -80,12 +84,11 @@ impl Crate { | |||
80 | } | 84 | } |
81 | 85 | ||
82 | pub fn root_file(self, db: &impl DefDatabase) -> FileId { | 86 | pub fn root_file(self, db: &impl DefDatabase) -> FileId { |
83 | db.crate_graph().crate_root(self.id) | 87 | db.crate_graph().crate_data(&self.id).root_file_id |
84 | } | 88 | } |
85 | 89 | ||
86 | pub fn edition(self, db: &impl DefDatabase) -> Edition { | 90 | pub fn edition(self, db: &impl DefDatabase) -> Edition { |
87 | let crate_graph = db.crate_graph(); | 91 | db.crate_graph().crate_data(&self.id).edition |
88 | crate_graph.edition(self.id) | ||
89 | } | 92 | } |
90 | 93 | ||
91 | pub fn all(db: &impl DefDatabase) -> Vec<Crate> { | 94 | pub fn all(db: &impl DefDatabase) -> Vec<Crate> { |
@@ -496,6 +499,14 @@ impl Adt { | |||
496 | pub fn krate(self, db: &impl HirDatabase) -> Option<Crate> { | 499 | pub fn krate(self, db: &impl HirDatabase) -> Option<Crate> { |
497 | Some(self.module(db).krate()) | 500 | Some(self.module(db).krate()) |
498 | } | 501 | } |
502 | |||
503 | pub fn name(&self, db: &impl HirDatabase) -> Name { | ||
504 | match self { | ||
505 | Adt::Struct(s) => s.name(db), | ||
506 | Adt::Union(u) => u.name(db), | ||
507 | Adt::Enum(e) => e.name(db), | ||
508 | } | ||
509 | } | ||
499 | } | 510 | } |
500 | 511 | ||
501 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 512 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
@@ -523,6 +534,14 @@ impl VariantDef { | |||
523 | } | 534 | } |
524 | } | 535 | } |
525 | 536 | ||
537 | pub fn name(&self, db: &impl HirDatabase) -> Name { | ||
538 | match self { | ||
539 | VariantDef::Struct(s) => s.name(db), | ||
540 | VariantDef::Union(u) => u.name(db), | ||
541 | VariantDef::EnumVariant(e) => e.name(db), | ||
542 | } | ||
543 | } | ||
544 | |||
526 | pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { | 545 | pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { |
527 | match self { | 546 | match self { |
528 | VariantDef::Struct(it) => it.variant_data(db), | 547 | VariantDef::Struct(it) => it.variant_data(db), |
@@ -550,6 +569,14 @@ impl DefWithBody { | |||
550 | DefWithBody::Static(s) => s.module(db), | 569 | DefWithBody::Static(s) => s.module(db), |
551 | } | 570 | } |
552 | } | 571 | } |
572 | |||
573 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { | ||
574 | match self { | ||
575 | DefWithBody::Function(f) => Some(f.name(db)), | ||
576 | DefWithBody::Static(s) => s.name(db), | ||
577 | DefWithBody::Const(c) => c.name(db), | ||
578 | } | ||
579 | } | ||
553 | } | 580 | } |
554 | 581 | ||
555 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 582 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |