aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-10-25 22:05:30 +0000
committerLukas Wirth <[email protected]>2020-10-25 22:05:30 +0000
commitc9af469b85854ec96318b96d7d1fde0935ee4e34 (patch)
treeffd9c15ba01fc180781b70cb31a0f64a398193b9 /crates/ide
parent91c1af36120ed9b5ad1da4972ab18d0d042e991f (diff)
Fix unary minus highlighting
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/syntax_highlighting.rs9
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlighting.html3
-rw-r--r--crates/ide/src/syntax_highlighting/tests.rs3
3 files changed, 14 insertions, 1 deletions
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(
579 } 579 }
580 } 580 }
581 T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { 581 T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
582 HighlightTag::NumericLiteral.into() 582 let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?;
583
584 let expr = prefix_expr.expr()?;
585 match expr {
586 ast::Expr::Literal(_) => HighlightTag::NumericLiteral,
587 _ => HighlightTag::Operator,
588 }
589 .into()
583 } 590 }
584 _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { 591 _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
585 HighlightTag::Operator.into() 592 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
176 176
177 <span class="keyword">let</span> <span class="variable declaration callable">a</span> <span class="operator">=</span> <span class="punctuation">|</span><span class="value_param declaration">x</span><span class="punctuation">|</span> <span class="value_param">x</span><span class="punctuation">;</span> 177 <span class="keyword">let</span> <span class="variable declaration callable">a</span> <span class="operator">=</span> <span class="punctuation">|</span><span class="value_param declaration">x</span><span class="punctuation">|</span> <span class="value_param">x</span><span class="punctuation">;</span>
178 <span class="keyword">let</span> <span class="variable declaration callable">bar</span> <span class="operator">=</span> <span class="struct">Foo</span><span class="operator">::</span><span class="function">baz</span><span class="punctuation">;</span> 178 <span class="keyword">let</span> <span class="variable declaration callable">bar</span> <span class="operator">=</span> <span class="struct">Foo</span><span class="operator">::</span><span class="function">baz</span><span class="punctuation">;</span>
179
180 <span class="keyword">let</span> <span class="variable declaration">baz</span> <span class="operator">=</span> <span class="numeric_literal">-</span><span class="numeric_literal">42</span><span class="punctuation">;</span>
181 <span class="keyword">let</span> <span class="variable declaration">baz</span> <span class="operator">=</span> <span class="operator">-</span><span class="variable">baz</span><span class="punctuation">;</span>
179<span class="punctuation">}</span> 182<span class="punctuation">}</span>
180 183
181<span class="keyword">enum</span> <span class="enum declaration">Option</span><span class="punctuation">&lt;</span><span class="type_param declaration">T</span><span class="punctuation">&gt;</span> <span class="punctuation">{</span> 184<span class="keyword">enum</span> <span class="enum declaration">Option</span><span class="punctuation">&lt;</span><span class="type_param declaration">T</span><span class="punctuation">&gt;</span> <span class="punctuation">{</span>
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() {
150 150
151 let a = |x| x; 151 let a = |x| x;
152 let bar = Foo::baz; 152 let bar = Foo::baz;
153
154 let baz = -42;
155 let baz = -baz;
153} 156}
154 157
155enum Option<T> { 158enum Option<T> {