From c9af469b85854ec96318b96d7d1fde0935ee4e34 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 25 Oct 2020 23:05:30 +0100 Subject: Fix unary minus highlighting --- crates/ide/src/syntax_highlighting.rs | 9 ++++++++- crates/ide/src/syntax_highlighting/test_data/highlighting.html | 3 +++ crates/ide/src/syntax_highlighting/tests.rs | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'crates/ide') diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 750848467..9f864179e 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -579,7 +579,14 @@ fn highlight_element( } } T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { - HighlightTag::NumericLiteral.into() + let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; + + let expr = prefix_expr.expr()?; + match expr { + ast::Expr::Literal(_) => HighlightTag::NumericLiteral, + _ => HighlightTag::Operator, + } + .into() } _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { HighlightTag::Operator.into() diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index 0cb84866d..c6b4f5a00 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html @@ -176,6 +176,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd let a = |x| x; let bar = Foo::baz; + + let baz = -42; + let baz = -baz; } enum Option<T> { diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index da20c300e..dd43f9dd9 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -150,6 +150,9 @@ fn main() { let a = |x| x; let bar = Foo::baz; + + let baz = -42; + let baz = -baz; } enum Option { -- cgit v1.2.3