mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Merge #5819
5819: Apply couple of rule of thumbs to simplify highlighting code
r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
686a6a26fd
1 changed files with 16 additions and 19 deletions
|
@ -484,9 +484,9 @@ fn highlight_element(
|
||||||
match name_kind {
|
match name_kind {
|
||||||
Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(),
|
Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(),
|
||||||
Some(NameClass::Definition(def)) => {
|
Some(NameClass::Definition(def)) => {
|
||||||
highlight_def(sema, db, def, None, false) | HighlightModifier::Definition
|
highlight_def(sema, db, def, None) | HighlightModifier::Definition
|
||||||
}
|
}
|
||||||
Some(NameClass::ConstReference(def)) => highlight_def(sema, db, def, None, false),
|
Some(NameClass::ConstReference(def)) => highlight_def(sema, db, def, None),
|
||||||
Some(NameClass::FieldShorthand { field, .. }) => {
|
Some(NameClass::FieldShorthand { field, .. }) => {
|
||||||
let mut h = HighlightTag::Field.into();
|
let mut h = HighlightTag::Field.into();
|
||||||
if let Definition::Field(field) = field {
|
if let Definition::Field(field) = field {
|
||||||
|
@ -519,13 +519,20 @@ fn highlight_element(
|
||||||
binding_hash = Some(calc_binding_hash(&name, *shadow_count))
|
binding_hash = Some(calc_binding_hash(&name, *shadow_count))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let possibly_unsafe = match name_ref.syntax().parent() {
|
|
||||||
Some(parent) => {
|
let mut h = highlight_def(sema, db, def, Some(name_ref.clone()));
|
||||||
matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD)
|
|
||||||
|
if let Some(parent) = name_ref.syntax().parent() {
|
||||||
|
if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) {
|
||||||
|
if let Definition::Field(field) = def {
|
||||||
|
if let VariantDef::Union(_) = field.parent_def(db) {
|
||||||
|
h |= HighlightModifier::Unsafe;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => false,
|
}
|
||||||
};
|
|
||||||
highlight_def(sema, db, def, Some(name_ref), possibly_unsafe)
|
h
|
||||||
}
|
}
|
||||||
NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
|
NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
|
||||||
},
|
},
|
||||||
|
@ -734,20 +741,10 @@ fn highlight_def(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
def: Definition,
|
def: Definition,
|
||||||
name_ref: Option<ast::NameRef>,
|
name_ref: Option<ast::NameRef>,
|
||||||
possibly_unsafe: bool,
|
|
||||||
) -> Highlight {
|
) -> Highlight {
|
||||||
match def {
|
match def {
|
||||||
Definition::Macro(_) => HighlightTag::Macro,
|
Definition::Macro(_) => HighlightTag::Macro,
|
||||||
Definition::Field(field) => {
|
Definition::Field(_) => HighlightTag::Field,
|
||||||
let mut h = HighlightTag::Field.into();
|
|
||||||
if possibly_unsafe {
|
|
||||||
if let VariantDef::Union(_) = field.parent_def(db) {
|
|
||||||
h |= HighlightModifier::Unsafe;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
Definition::ModuleDef(def) => match def {
|
Definition::ModuleDef(def) => match def {
|
||||||
hir::ModuleDef::Module(_) => HighlightTag::Module,
|
hir::ModuleDef::Module(_) => HighlightTag::Module,
|
||||||
hir::ModuleDef::Function(func) => {
|
hir::ModuleDef::Function(func) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue