From 6da122889856f40bd165c68c6daf58de23def98e Mon Sep 17 00:00:00 2001 From: Luna Razzaghipour Date: Mon, 7 Mar 2022 20:16:03 +1100 Subject: [PATCH] Emit more detailed highlighting for `%`, `>>`, `<<` --- .../ide/src/syntax_highlighting/highlight.rs | 8 +-- .../test_data/highlight_operators.html | 57 +++++++++++++++++++ crates/ide/src/syntax_highlighting/tests.rs | 24 ++++++++ 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 crates/ide/src/syntax_highlighting/test_data/highlight_operators.html diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index a5b4ef50298..eeec8dcba8c 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -123,12 +123,12 @@ fn punctuation(sema: &Semantics, token: SyntaxToken, kind: SyntaxK } .into() } - (T![+] | T![-] | T![*] | T![/], BIN_EXPR) => HlOperator::Arithmetic.into(), - (T![+=] | T![-=] | T![*=] | T![/=], BIN_EXPR) => { + (T![+] | T![-] | T![*] | T![/] | T![%], BIN_EXPR) => HlOperator::Arithmetic.into(), + (T![+=] | T![-=] | T![*=] | T![/=] | T![%=], BIN_EXPR) => { Highlight::from(HlOperator::Arithmetic) | HlMod::Mutable } - (T![|] | T![&] | T![!] | T![^], BIN_EXPR) => HlOperator::Bitwise.into(), - (T![|=] | T![&=] | T![^=], BIN_EXPR) => { + (T![|] | T![&] | T![!] | T![^] | T![>>] | T![<<], BIN_EXPR) => HlOperator::Bitwise.into(), + (T![|=] | T![&=] | T![^=] | T![>>=] | T![<<=], BIN_EXPR) => { Highlight::from(HlOperator::Bitwise) | HlMod::Mutable } (T![&&] | T![||], BIN_EXPR) => HlOperator::Logical.into(), diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_operators.html b/crates/ide/src/syntax_highlighting/test_data/highlight_operators.html new file mode 100644 index 00000000000..46220993e68 --- /dev/null +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_operators.html @@ -0,0 +1,57 @@ + + +
fn main() {
+    1 + 1 - 1 * 1 / 1 % 1 | 1 & 1 ! 1 ^ 1 >> 1 << 1;
+    let mut a = 0;
+    a += 1;
+    a -= 1;
+    a *= 1;
+    a /= 1;
+    a %= 1;
+    a |= 1;
+    a &= 1;
+    a ^= 1;
+    a >>= 1;
+    a <<= 1;
+}
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 0af743431b6..efd03c28237 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -841,6 +841,30 @@ fn foo() { ); } +#[test] +fn test_operators() { + check_highlighting( + r##" +fn main() { + 1 + 1 - 1 * 1 / 1 % 1 | 1 & 1 ! 1 ^ 1 >> 1 << 1; + let mut a = 0; + a += 1; + a -= 1; + a *= 1; + a /= 1; + a %= 1; + a |= 1; + a &= 1; + a ^= 1; + a >>= 1; + a <<= 1; +} +"##, + expect_file!["./test_data/highlight_operators.html"], + false, + ); +} + #[test] fn test_rainbow_highlighting() { check_highlighting(