diff options
Diffstat (limited to 'crates/ide/src/syntax_highlighting/highlight.rs')
-rw-r--r-- | crates/ide/src/syntax_highlighting/highlight.rs | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 9503c936d..6834fe11a 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs | |||
@@ -48,7 +48,13 @@ pub(super) fn element( | |||
48 | match name_kind { | 48 | match name_kind { |
49 | Some(NameClass::ExternCrate(_)) => SymbolKind::Module.into(), | 49 | Some(NameClass::ExternCrate(_)) => SymbolKind::Module.into(), |
50 | Some(NameClass::Definition(def)) => { | 50 | Some(NameClass::Definition(def)) => { |
51 | highlight_def(db, krate, def) | HlMod::Definition | 51 | let mut h = highlight_def(db, krate, def) | HlMod::Definition; |
52 | if let Definition::ModuleDef(hir::ModuleDef::Trait(trait_)) = &def { | ||
53 | if trait_.is_unsafe(db) { | ||
54 | h |= HlMod::Unsafe; | ||
55 | } | ||
56 | } | ||
57 | h | ||
52 | } | 58 | } |
53 | Some(NameClass::ConstReference(def)) => highlight_def(db, krate, def), | 59 | Some(NameClass::ConstReference(def)) => highlight_def(db, krate, def), |
54 | Some(NameClass::PatFieldShorthand { field_ref, .. }) => { | 60 | Some(NameClass::PatFieldShorthand { field_ref, .. }) => { |
@@ -87,20 +93,34 @@ pub(super) fn element( | |||
87 | 93 | ||
88 | let mut h = highlight_def(db, krate, def); | 94 | let mut h = highlight_def(db, krate, def); |
89 | 95 | ||
90 | if let Definition::Local(local) = &def { | 96 | match def { |
91 | if is_consumed_lvalue(name_ref.syntax().clone().into(), local, db) { | 97 | Definition::Local(local) |
98 | if is_consumed_lvalue( | ||
99 | name_ref.syntax().clone().into(), | ||
100 | &local, | ||
101 | db, | ||
102 | ) => | ||
103 | { | ||
92 | h |= HlMod::Consuming; | 104 | h |= HlMod::Consuming; |
93 | } | 105 | } |
94 | } | 106 | Definition::ModuleDef(hir::ModuleDef::Trait(trait_)) |
95 | 107 | if trait_.is_unsafe(db) => | |
96 | if let Some(parent) = name_ref.syntax().parent() { | 108 | { |
97 | if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) { | 109 | if ast::Impl::for_trait_name_ref(&name_ref).is_some() { |
98 | if let Definition::Field(field) = def { | 110 | h |= HlMod::Unsafe; |
99 | if let hir::VariantDef::Union(_) = field.parent_def(db) { | 111 | } |
100 | h |= HlMod::Unsafe; | 112 | } |
113 | Definition::Field(field) => { | ||
114 | if let Some(parent) = name_ref.syntax().parent() { | ||
115 | if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) { | ||
116 | if let hir::VariantDef::Union(_) = field.parent_def(db) | ||
117 | { | ||
118 | h |= HlMod::Unsafe; | ||
119 | } | ||
101 | } | 120 | } |
102 | } | 121 | } |
103 | } | 122 | } |
123 | _ => (), | ||
104 | } | 124 | } |
105 | 125 | ||
106 | h | 126 | h |
@@ -131,6 +151,9 @@ pub(super) fn element( | |||
131 | } | 151 | } |
132 | STRING | BYTE_STRING => HlTag::StringLiteral.into(), | 152 | STRING | BYTE_STRING => HlTag::StringLiteral.into(), |
133 | ATTR => HlTag::Attribute.into(), | 153 | ATTR => HlTag::Attribute.into(), |
154 | INT_NUMBER if element.ancestors().nth(1).map_or(false, |it| it.kind() == FIELD_EXPR) => { | ||
155 | SymbolKind::Field.into() | ||
156 | } | ||
134 | INT_NUMBER | FLOAT_NUMBER => HlTag::NumericLiteral.into(), | 157 | INT_NUMBER | FLOAT_NUMBER => HlTag::NumericLiteral.into(), |
135 | BYTE => HlTag::ByteLiteral.into(), | 158 | BYTE => HlTag::ByteLiteral.into(), |
136 | CHAR => HlTag::CharLiteral.into(), | 159 | CHAR => HlTag::CharLiteral.into(), |
@@ -351,15 +374,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) | |||
351 | 374 | ||
352 | h | 375 | h |
353 | } | 376 | } |
354 | hir::ModuleDef::Trait(trait_) => { | 377 | hir::ModuleDef::Trait(_) => Highlight::new(HlTag::Symbol(SymbolKind::Trait)), |
355 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Trait)); | ||
356 | |||
357 | if trait_.is_unsafe(db) { | ||
358 | h |= HlMod::Unsafe; | ||
359 | } | ||
360 | |||
361 | h | ||
362 | } | ||
363 | hir::ModuleDef::TypeAlias(type_) => { | 378 | hir::ModuleDef::TypeAlias(type_) => { |
364 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias)); | 379 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias)); |
365 | 380 | ||
@@ -446,12 +461,12 @@ fn highlight_method_call( | |||
446 | krate: Option<hir::Crate>, | 461 | krate: Option<hir::Crate>, |
447 | method_call: &ast::MethodCallExpr, | 462 | method_call: &ast::MethodCallExpr, |
448 | ) -> Option<Highlight> { | 463 | ) -> Option<Highlight> { |
449 | let func = sema.resolve_method_call(&method_call)?; | 464 | let func = sema.resolve_method_call(method_call)?; |
450 | 465 | ||
451 | let mut h = SymbolKind::Function.into(); | 466 | let mut h = SymbolKind::Function.into(); |
452 | h |= HlMod::Associated; | 467 | h |= HlMod::Associated; |
453 | 468 | ||
454 | if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) { | 469 | if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(method_call) { |
455 | h |= HlMod::Unsafe; | 470 | h |= HlMod::Unsafe; |
456 | } | 471 | } |
457 | if func.is_async(sema.db) { | 472 | if func.is_async(sema.db) { |
@@ -523,11 +538,9 @@ fn highlight_name_ref_by_syntax( | |||
523 | }; | 538 | }; |
524 | 539 | ||
525 | match parent.kind() { | 540 | match parent.kind() { |
526 | METHOD_CALL_EXPR => { | 541 | METHOD_CALL_EXPR => ast::MethodCallExpr::cast(parent) |
527 | return ast::MethodCallExpr::cast(parent) | 542 | .and_then(|it| highlight_method_call(sema, krate, &it)) |
528 | .and_then(|it| highlight_method_call(sema, krate, &it)) | 543 | .unwrap_or_else(|| SymbolKind::Function.into()), |
529 | .unwrap_or_else(|| SymbolKind::Function.into()); | ||
530 | } | ||
531 | FIELD_EXPR => { | 544 | FIELD_EXPR => { |
532 | let h = HlTag::Symbol(SymbolKind::Field); | 545 | let h = HlTag::Symbol(SymbolKind::Field); |
533 | let is_union = ast::FieldExpr::cast(parent) | 546 | let is_union = ast::FieldExpr::cast(parent) |