diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index b71ee764a..2944926e6 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -27,7 +27,7 @@ use hir_ty::{ | |||
27 | use ra_db::{CrateId, Edition, FileId}; | 27 | use ra_db::{CrateId, Edition, FileId}; |
28 | use ra_prof::profile; | 28 | use ra_prof::profile; |
29 | use ra_syntax::{ | 29 | use ra_syntax::{ |
30 | ast::{self, AttrsOwner}, | 30 | ast::{self, AttrsOwner, NameOwner}, |
31 | AstNode, | 31 | AstNode, |
32 | }; | 32 | }; |
33 | use rustc_hash::FxHashSet; | 33 | use rustc_hash::FxHashSet; |
@@ -603,6 +603,10 @@ impl Static { | |||
603 | pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { | 603 | pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { |
604 | Some(self.module(db).krate()) | 604 | Some(self.module(db).krate()) |
605 | } | 605 | } |
606 | |||
607 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { | ||
608 | db.static_data(self.id).name.clone() | ||
609 | } | ||
606 | } | 610 | } |
607 | 611 | ||
608 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 612 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -674,6 +678,11 @@ impl MacroDef { | |||
674 | let module_id = db.crate_def_map(krate).root; | 678 | let module_id = db.crate_def_map(krate).root; |
675 | Some(Module::new(Crate { id: krate }, module_id)) | 679 | Some(Module::new(Crate { id: krate }, module_id)) |
676 | } | 680 | } |
681 | |||
682 | /// XXX: this parses the file | ||
683 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { | ||
684 | self.source(db).value.name().map(|it| it.as_name()) | ||
685 | } | ||
677 | } | 686 | } |
678 | 687 | ||
679 | /// Invariant: `inner.as_assoc_item(db).is_some()` | 688 | /// Invariant: `inner.as_assoc_item(db).is_some()` |
@@ -783,6 +792,7 @@ pub struct Local { | |||
783 | } | 792 | } |
784 | 793 | ||
785 | impl Local { | 794 | impl Local { |
795 | // FIXME: why is this an option? It shouldn't be? | ||
786 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { | 796 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { |
787 | let body = db.body(self.parent.into()); | 797 | let body = db.body(self.parent.into()); |
788 | match &body[self.pat_id] { | 798 | match &body[self.pat_id] { |