mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
More clarifications
This commit is contained in:
parent
bc287b8f9b
commit
f9c1336873
6 changed files with 17 additions and 17 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_or_reference(sema.db)),
|
||||
ast::Name(name) => classify_name(&sema, &name).map(|d| d.reference_or_definition(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_or_reference(sema.db);
|
||||
let def = classify_name(&sema, &name)?.reference_or_definition(sema.db);
|
||||
let nav = def.try_to_nav(sema.db)?;
|
||||
vec![nav]
|
||||
},
|
||||
|
|
|
@ -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_or_reference(sema.db);
|
||||
let def = classify_name(sema, &name)?.reference_or_definition(sema.db);
|
||||
let range = name.syntax().text_range();
|
||||
return Some(RangeInfo::new(range, def));
|
||||
}
|
||||
|
|
|
@ -459,9 +459,9 @@ fn highlight_element(
|
|||
highlight_def(db, def) | HighlightModifier::Definition
|
||||
}
|
||||
Some(NameClass::ConstReference(def)) => highlight_def(db, def),
|
||||
Some(NameClass::PatFieldShorthand { field, .. }) => {
|
||||
Some(NameClass::PatFieldShorthand { field_ref, .. }) => {
|
||||
let mut h = HighlightTag::Field.into();
|
||||
if let Definition::Field(field) = field {
|
||||
if let Definition::Field(field) = field_ref {
|
||||
if let VariantDef::Union(_) = field.parent_def(db) {
|
||||
h |= HighlightModifier::Unsafe;
|
||||
}
|
||||
|
|
|
@ -81,12 +81,12 @@ impl Definition {
|
|||
pub enum NameClass {
|
||||
ExternCrate(Crate),
|
||||
Definition(Definition),
|
||||
/// `None` in `if let None = Some(82) {}`
|
||||
/// `None` in `if let None = Some(82) {}`.
|
||||
ConstReference(Definition),
|
||||
/// `field` in `if let Foo { field } = todo!() {}`
|
||||
/// `field` in `if let Foo { field } = foo`.
|
||||
PatFieldShorthand {
|
||||
local: Local,
|
||||
field: Definition,
|
||||
local_def: Local,
|
||||
field_ref: Definition,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -96,18 +96,18 @@ impl NameClass {
|
|||
NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()),
|
||||
NameClass::Definition(it) => it,
|
||||
NameClass::ConstReference(_) => return None,
|
||||
/// Both `local` and `field` are definitions here, but only `local`
|
||||
/// is the definition which is introduced by this name.
|
||||
NameClass::PatFieldShorthand { local, field: _ } => Definition::Local(local),
|
||||
NameClass::PatFieldShorthand { local_def, field_ref: _ } => {
|
||||
Definition::Local(local_def)
|
||||
}
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
|
||||
pub fn definition_or_reference(self, db: &dyn HirDatabase) -> Definition {
|
||||
pub fn reference_or_definition(self, db: &dyn HirDatabase) -> Definition {
|
||||
match self {
|
||||
NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()),
|
||||
NameClass::Definition(it) | NameClass::ConstReference(it) => it,
|
||||
NameClass::PatFieldShorthand { local: _, field } => field,
|
||||
NameClass::PatFieldShorthand { local_def: _, field_ref } => field_ref,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
|
|||
if record_pat_field.name_ref().is_none() {
|
||||
if let Some(field) = sema.resolve_record_pat_field(&record_pat_field) {
|
||||
let field = Definition::Field(field);
|
||||
return Some(NameClass::PatFieldShorthand { local, field });
|
||||
return Some(NameClass::PatFieldShorthand { local_def: local, field_ref: field });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -314,9 +314,9 @@ impl<'a> FindUsages<'a> {
|
|||
|
||||
fn found_name(&self, name: &ast::Name, sink: &mut dyn FnMut(Reference) -> bool) -> bool {
|
||||
match classify_name(self.sema, name) {
|
||||
Some(NameClass::PatFieldShorthand { local: _, field }) => {
|
||||
Some(NameClass::PatFieldShorthand { local_def: _, field_ref }) => {
|
||||
let reference = match self.def {
|
||||
Definition::Field(_) if &field == self.def => Reference {
|
||||
Definition::Field(_) if &field_ref == self.def => Reference {
|
||||
file_range: self.sema.original_range(name.syntax()),
|
||||
kind: ReferenceKind::FieldShorthandForField,
|
||||
// FIXME: mutable patterns should have `Write` access
|
||||
|
|
Loading…
Reference in a new issue