aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-19 16:57:21 +0100
committerGitHub <[email protected]>2020-08-19 16:57:21 +0100
commit686a6a26fd2263e4bb958fbcf94b04244ed73e08 (patch)
tree100c26d33895d03ecf2ea03659657d4904e8f130 /crates
parent45c24ae0a5f9fedac996bdc26244cb1161810722 (diff)
parentb56e02007798db24600ccae51c0e892919635cad (diff)
Merge #5819
5819: Apply couple of rule of thumbs to simplify highlighting code r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/syntax_highlighting.rs35
1 files changed, 16 insertions, 19 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index ad49f8e17..db8aaed48 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -484,9 +484,9 @@ fn highlight_element(
484 match name_kind { 484 match name_kind {
485 Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(), 485 Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(),
486 Some(NameClass::Definition(def)) => { 486 Some(NameClass::Definition(def)) => {
487 highlight_def(sema, db, def, None, false) | HighlightModifier::Definition 487 highlight_def(sema, db, def, None) | HighlightModifier::Definition
488 } 488 }
489 Some(NameClass::ConstReference(def)) => highlight_def(sema, db, def, None, false), 489 Some(NameClass::ConstReference(def)) => highlight_def(sema, db, def, None),
490 Some(NameClass::FieldShorthand { field, .. }) => { 490 Some(NameClass::FieldShorthand { field, .. }) => {
491 let mut h = HighlightTag::Field.into(); 491 let mut h = HighlightTag::Field.into();
492 if let Definition::Field(field) = field { 492 if let Definition::Field(field) = field {
@@ -519,13 +519,20 @@ fn highlight_element(
519 binding_hash = Some(calc_binding_hash(&name, *shadow_count)) 519 binding_hash = Some(calc_binding_hash(&name, *shadow_count))
520 } 520 }
521 }; 521 };
522 let possibly_unsafe = match name_ref.syntax().parent() { 522
523 Some(parent) => { 523 let mut h = highlight_def(sema, db, def, Some(name_ref.clone()));
524 matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) 524
525 if let Some(parent) = name_ref.syntax().parent() {
526 if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) {
527 if let Definition::Field(field) = def {
528 if let VariantDef::Union(_) = field.parent_def(db) {
529 h |= HighlightModifier::Unsafe;
530 }
531 }
525 } 532 }
526 None => false, 533 }
527 }; 534
528 highlight_def(sema, db, def, Some(name_ref), possibly_unsafe) 535 h
529 } 536 }
530 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(), 537 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
531 }, 538 },
@@ -734,20 +741,10 @@ fn highlight_def(
734 db: &RootDatabase, 741 db: &RootDatabase,
735 def: Definition, 742 def: Definition,
736 name_ref: Option<ast::NameRef>, 743 name_ref: Option<ast::NameRef>,
737 possibly_unsafe: bool,
738) -> Highlight { 744) -> Highlight {
739 match def { 745 match def {
740 Definition::Macro(_) => HighlightTag::Macro, 746 Definition::Macro(_) => HighlightTag::Macro,
741 Definition::Field(field) => { 747 Definition::Field(_) => HighlightTag::Field,
742 let mut h = HighlightTag::Field.into();
743 if possibly_unsafe {
744 if let VariantDef::Union(_) = field.parent_def(db) {
745 h |= HighlightModifier::Unsafe;
746 }
747 }
748
749 return h;
750 }
751 Definition::ModuleDef(def) => match def { 748 Definition::ModuleDef(def) => match def {
752 hir::ModuleDef::Module(_) => HighlightTag::Module, 749 hir::ModuleDef::Module(_) => HighlightTag::Module,
753 hir::ModuleDef::Function(func) => { 750 hir::ModuleDef::Function(func) => {