mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-24 12:03:31 +00:00
Clarify NameClass names a bit
This commit is contained in:
parent
7fadc78ebb
commit
fa3c449d8f
6 changed files with 7 additions and 7 deletions
|
@ -233,7 +233,7 @@ pub(crate) fn external_docs(
|
|||
let definition = match_ast! {
|
||||
match node {
|
||||
ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)),
|
||||
ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition(sema.db)),
|
||||
ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition_or_reference(sema.db)),
|
||||
_ => None,
|
||||
}
|
||||
};
|
||||
|
|
|
@ -40,7 +40,7 @@ pub(crate) fn goto_definition(
|
|||
reference_definition(&sema, &name_ref).to_vec()
|
||||
},
|
||||
ast::Name(name) => {
|
||||
let def = classify_name(&sema, &name)?.definition(sema.db);
|
||||
let def = classify_name(&sema, &name)?.definition_or_reference(sema.db);
|
||||
let nav = def.try_to_nav(sema.db)?;
|
||||
vec![nav]
|
||||
},
|
||||
|
|
|
@ -108,7 +108,7 @@ pub(crate) fn hover(
|
|||
let definition = match_ast! {
|
||||
match node {
|
||||
ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)),
|
||||
ast::Name(name) => classify_name(&sema, &name).and_then(|d| d.into_definition(sema.db)),
|
||||
ast::Name(name) => classify_name(&sema, &name).and_then(|d| d.definition(sema.db)),
|
||||
_ => None,
|
||||
}
|
||||
};
|
||||
|
|
|
@ -132,7 +132,7 @@ fn find_name(
|
|||
opt_name: Option<ast::Name>,
|
||||
) -> Option<RangeInfo<Definition>> {
|
||||
if let Some(name) = opt_name {
|
||||
let def = classify_name(sema, &name)?.definition(sema.db);
|
||||
let def = classify_name(sema, &name)?.definition_or_reference(sema.db);
|
||||
let range = name.syntax().text_range();
|
||||
return Some(RangeInfo::new(range, def));
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ pub enum NameClass {
|
|||
}
|
||||
|
||||
impl NameClass {
|
||||
pub fn into_definition(self, db: &dyn HirDatabase) -> Option<Definition> {
|
||||
pub fn definition(self, db: &dyn HirDatabase) -> Option<Definition> {
|
||||
Some(match self {
|
||||
NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()),
|
||||
NameClass::Definition(it) => it,
|
||||
|
@ -99,7 +99,7 @@ impl NameClass {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn definition(self, db: &dyn HirDatabase) -> Definition {
|
||||
pub fn definition_or_reference(self, db: &dyn HirDatabase) -> Definition {
|
||||
match self {
|
||||
NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()),
|
||||
NameClass::Definition(it) | NameClass::ConstReference(it) => it,
|
||||
|
|
|
@ -60,5 +60,5 @@ fn get_name_definition<'a>(
|
|||
candidate_node
|
||||
};
|
||||
let name = ast::Name::cast(candidate_name_node)?;
|
||||
classify_name(sema, &name)?.into_definition(sema.db)
|
||||
classify_name(sema, &name)?.definition(sema.db)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue