mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Refactor reference search a bit
This commit is contained in:
parent
674770ef04
commit
7d71cc72b5
3 changed files with 74 additions and 27 deletions
|
@ -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<Crate> {
|
||||
Some(self.module(db).krate())
|
||||
}
|
||||
|
||||
pub fn name(self, db: &impl HirDatabase) -> Option<Name> {
|
||||
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<Name> {
|
||||
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<Name> {
|
||||
let body = db.body(self.parent.into());
|
||||
match &body[self.pat_id] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue