Skip to content

Commit 73bab32

Browse files
committed
Highlight more cases of SyntaxKind when it is a punctuation
1 parent c9c518e commit 73bab32

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

crates/ra_ide/src/syntax_highlighting.rs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -539,21 +539,39 @@ fn highlight_element(
539539
_ => h,
540540
}
541541
}
542-
T![*] => {
543-
let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?;
544-
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
542+
p if p.is_punct() => match p {
543+
T![::] | T![->] | T![=>] | T![&] => HighlightTag::Operator.into(),
544+
T![@] => HighlightTag::Operator | HighlightModifier::ControlFlow,
545+
T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => {
546+
Highlight::new(HighlightTag::Macro)
551547
}
552-
}
553-
T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => {
554-
Highlight::new(HighlightTag::Macro)
555-
}
556-
p if p.is_punct() => HighlightTag::Punctuation.into(),
548+
T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
549+
let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?;
550+
551+
let expr = prefix_expr.expr()?;
552+
let ty = sema.type_of_expr(&expr)?;
553+
if ty.is_raw_ptr() {
554+
HighlightTag::Operator | HighlightModifier::Unsafe
555+
} else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() {
556+
HighlightTag::Operator.into()
557+
} else {
558+
HighlightTag::Punctuation.into()
559+
}
560+
}
561+
T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
562+
HighlightTag::NumericLiteral.into()
563+
}
564+
_ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
565+
HighlightTag::Operator.into()
566+
}
567+
_ if element.parent().and_then(ast::BinExpr::cast).is_some() => {
568+
HighlightTag::Operator.into()
569+
}
570+
_ if element.parent().and_then(ast::RangeExpr::cast).is_some() => {
571+
HighlightTag::Operator.into()
572+
}
573+
_ => HighlightTag::Punctuation.into(),
574+
},
557575

558576
k if k.is_keyword() => {
559577
let h = Highlight::new(HighlightTag::Keyword);

0 commit comments

Comments
 (0)