From 7d71cc72b5902300ed03db409b2a858517a1f5e0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 3 Mar 2020 18:22:52 +0100 Subject: Refactor reference search a bit --- crates/ra_hir/src/code_model.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src') 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::{ use ra_db::{CrateId, Edition, FileId}; use ra_prof::profile; use ra_syntax::{ - ast::{self, AttrsOwner}, + ast::{self, AttrsOwner, NameOwner}, AstNode, }; use rustc_hash::FxHashSet; @@ -603,6 +603,10 @@ impl Static { pub fn krate(self, db: &impl DefDatabase) -> Option { Some(self.module(db).krate()) } + + pub fn name(self, db: &impl HirDatabase) -> Option { + db.static_data(self.id).name.clone() + } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -674,6 +678,11 @@ impl MacroDef { let module_id = db.crate_def_map(krate).root; Some(Module::new(Crate { id: krate }, module_id)) } + + /// XXX: this parses the file + pub fn name(self, db: &impl HirDatabase) -> Option { + self.source(db).value.name().map(|it| it.as_name()) + } } /// Invariant: `inner.as_assoc_item(db).is_some()` @@ -783,6 +792,7 @@ pub struct Local { } impl Local { + // FIXME: why is this an option? It shouldn't be? pub fn name(self, db: &impl HirDatabase) -> Option { let body = db.body(self.parent.into()); match &body[self.pat_id] { -- cgit v1.2.3