diff options
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 6658c7bb2..be57eeb0a 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -167,6 +167,19 @@ pub(crate) fn highlight( | |||
167 | binding_hash: None, | 167 | binding_hash: None, |
168 | }); | 168 | }); |
169 | } | 169 | } |
170 | if let Some(name) = mc.is_macro_rules() { | ||
171 | if let Some((highlight, binding_hash)) = highlight_element( | ||
172 | &sema, | ||
173 | &mut bindings_shadow_count, | ||
174 | name.syntax().clone().into(), | ||
175 | ) { | ||
176 | stack.add(HighlightedRange { | ||
177 | range: name.syntax().text_range(), | ||
178 | highlight, | ||
179 | binding_hash, | ||
180 | }); | ||
181 | } | ||
182 | } | ||
170 | continue; | 183 | continue; |
171 | } | 184 | } |
172 | WalkEvent::Leave(Some(mc)) => { | 185 | WalkEvent::Leave(Some(mc)) => { |
@@ -390,12 +403,13 @@ fn highlight_element( | |||
390 | T![break] | 403 | T![break] |
391 | | T![continue] | 404 | | T![continue] |
392 | | T![else] | 405 | | T![else] |
393 | | T![for] | ||
394 | | T![if] | 406 | | T![if] |
395 | | T![loop] | 407 | | T![loop] |
396 | | T![match] | 408 | | T![match] |
397 | | T![return] | 409 | | T![return] |
398 | | T![while] => h | HighlightModifier::ControlFlow, | 410 | | T![while] |
411 | | T![in] => h | HighlightModifier::ControlFlow, | ||
412 | T![for] if !is_child_of_impl(element) => h | HighlightModifier::ControlFlow, | ||
399 | T![unsafe] => h | HighlightModifier::Unsafe, | 413 | T![unsafe] => h | HighlightModifier::Unsafe, |
400 | _ => h, | 414 | _ => h, |
401 | } | 415 | } |
@@ -419,6 +433,13 @@ fn highlight_element( | |||
419 | } | 433 | } |
420 | } | 434 | } |
421 | 435 | ||
436 | fn is_child_of_impl(element: SyntaxElement) -> bool { | ||
437 | match element.parent() { | ||
438 | Some(e) => e.kind() == IMPL_DEF, | ||
439 | _ => false, | ||
440 | } | ||
441 | } | ||
442 | |||
422 | fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight { | 443 | fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight { |
423 | match def { | 444 | match def { |
424 | Definition::Macro(_) => HighlightTag::Macro, | 445 | Definition::Macro(_) => HighlightTag::Macro, |
@@ -431,10 +452,16 @@ fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight { | |||
431 | hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, | 452 | hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, |
432 | hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant, | 453 | hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant, |
433 | hir::ModuleDef::Const(_) => HighlightTag::Constant, | 454 | hir::ModuleDef::Const(_) => HighlightTag::Constant, |
434 | hir::ModuleDef::Static(_) => HighlightTag::Static, | ||
435 | hir::ModuleDef::Trait(_) => HighlightTag::Trait, | 455 | hir::ModuleDef::Trait(_) => HighlightTag::Trait, |
436 | hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias, | 456 | hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias, |
437 | hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, | 457 | hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, |
458 | hir::ModuleDef::Static(s) => { | ||
459 | let mut h = Highlight::new(HighlightTag::Static); | ||
460 | if s.is_mut(db) { | ||
461 | h |= HighlightModifier::Mutable; | ||
462 | } | ||
463 | return h; | ||
464 | } | ||
438 | }, | 465 | }, |
439 | Definition::SelfType(_) => HighlightTag::SelfType, | 466 | Definition::SelfType(_) => HighlightTag::SelfType, |
440 | Definition::TypeParam(_) => HighlightTag::TypeParam, | 467 | Definition::TypeParam(_) => HighlightTag::TypeParam, |