Clarify NameClass names a bit

This commit is contained in:
Aleksey Kladov 2020-10-15 16:15:01 +02:00
parent 7fadc78ebb
commit fa3c449d8f
6 changed files with 7 additions and 7 deletions

View file

@ -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,
}
};

View file

@ -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]
},

View file

@ -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,
}
};

View file

@ -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));
}

View file

@ -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,

View file

@ -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)
}