From 73bab32aef073a101854099d6ef193737cf2a4fe Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 09:46:50 -0300 Subject: Highlight more cases of SyntaxKind when it is a punctuation --- crates/ra_ide/src/syntax_highlighting.rs | 46 ++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 6ac44c2c0..606637d11 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -539,21 +539,39 @@ fn highlight_element( _ => h, } } - T![*] => { - let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; - - let expr = prefix_expr.expr()?; - let ty = sema.type_of_expr(&expr)?; - if !ty.is_raw_ptr() { - return None; - } else { - HighlightTag::Operator | HighlightModifier::Unsafe + p if p.is_punct() => match p { + T![::] | T![->] | T![=>] | T![&] => HighlightTag::Operator.into(), + T![@] => HighlightTag::Operator | HighlightModifier::ControlFlow, + T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { + Highlight::new(HighlightTag::Macro) } - } - T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { - Highlight::new(HighlightTag::Macro) - } - p if p.is_punct() => HighlightTag::Punctuation.into(), + T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { + let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; + + let expr = prefix_expr.expr()?; + let ty = sema.type_of_expr(&expr)?; + if ty.is_raw_ptr() { + HighlightTag::Operator | HighlightModifier::Unsafe + } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() { + HighlightTag::Operator.into() + } else { + HighlightTag::Punctuation.into() + } + } + T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { + HighlightTag::NumericLiteral.into() + } + _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { + HighlightTag::Operator.into() + } + _ if element.parent().and_then(ast::BinExpr::cast).is_some() => { + HighlightTag::Operator.into() + } + _ if element.parent().and_then(ast::RangeExpr::cast).is_some() => { + HighlightTag::Operator.into() + } + _ => HighlightTag::Punctuation.into(), + }, k if k.is_keyword() => { let h = Highlight::new(HighlightTag::Keyword); -- cgit v1.2.3