diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 6ac44c2c0..d456d5d36 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -539,21 +539,52 @@ fn highlight_element( | |||
539 | _ => h, | 539 | _ => h, |
540 | } | 540 | } |
541 | } | 541 | } |
542 | T![*] => { | 542 | p if p.is_punct() => match p { |
543 | let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; | 543 | T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => { |
544 | 544 | HighlightTag::Operator.into() | |
545 | let expr = prefix_expr.expr()?; | ||
546 | let ty = sema.type_of_expr(&expr)?; | ||
547 | if !ty.is_raw_ptr() { | ||
548 | return None; | ||
549 | } else { | ||
550 | HighlightTag::Operator | HighlightModifier::Unsafe | ||
551 | } | 545 | } |
552 | } | 546 | T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { |
553 | T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { | 547 | HighlightTag::Macro.into() |
554 | Highlight::new(HighlightTag::Macro) | 548 | } |
555 | } | 549 | T![*] if element.parent().and_then(ast::PointerType::cast).is_some() => { |
556 | p if p.is_punct() => HighlightTag::Punctuation.into(), | 550 | HighlightTag::Keyword.into() |
551 | } | ||
552 | T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { | ||
553 | let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; | ||
554 | |||
555 | let expr = prefix_expr.expr()?; | ||
556 | let ty = sema.type_of_expr(&expr)?; | ||
557 | if ty.is_raw_ptr() { | ||
558 | HighlightTag::Operator | HighlightModifier::Unsafe | ||
559 | } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() { | ||
560 | HighlightTag::Operator.into() | ||
561 | } else { | ||
562 | HighlightTag::Punctuation.into() | ||
563 | } | ||
564 | } | ||
565 | T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { | ||
566 | HighlightTag::NumericLiteral.into() | ||
567 | } | ||
568 | _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { | ||
569 | HighlightTag::Operator.into() | ||
570 | } | ||
571 | _ if element.parent().and_then(ast::BinExpr::cast).is_some() => { | ||
572 | HighlightTag::Operator.into() | ||
573 | } | ||
574 | _ if element.parent().and_then(ast::RangeExpr::cast).is_some() => { | ||
575 | HighlightTag::Operator.into() | ||
576 | } | ||
577 | _ if element.parent().and_then(ast::RangePat::cast).is_some() => { | ||
578 | HighlightTag::Operator.into() | ||
579 | } | ||
580 | _ if element.parent().and_then(ast::DotDotPat::cast).is_some() => { | ||
581 | HighlightTag::Operator.into() | ||
582 | } | ||
583 | _ if element.parent().and_then(ast::Attr::cast).is_some() => { | ||
584 | HighlightTag::Attribute.into() | ||
585 | } | ||
586 | _ => HighlightTag::Punctuation.into(), | ||
587 | }, | ||
557 | 588 | ||
558 | k if k.is_keyword() => { | 589 | k if k.is_keyword() => { |
559 | let h = Highlight::new(HighlightTag::Keyword); | 590 | let h = Highlight::new(HighlightTag::Keyword); |