diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-03-07 10:05:31 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-07 10:05:31 +0000 |
| commit | 31ad347b0ef7f2e98496b1cf7a99bff5e59d87c4 (patch) | |
| tree | 3f236a3a321d923b2965faf0890bcfc41be6646c | |
| parent | 5fae65dd28b450a437ebc800a410164c3af1d516 (diff) | |
| parent | 6da122889856f40bd165c68c6daf58de23def98e (diff) | |
| download | rust-31ad347b0ef7f2e98496b1cf7a99bff5e59d87c4.tar.gz rust-31ad347b0ef7f2e98496b1cf7a99bff5e59d87c4.zip | |
Merge #11644
11644: Emit more detailed highlighting for `%`, `>>`, `<<` r=Veykril a=arzg These are currently just given `operator`, when `%` can be grouped under `arithmetic`, and `>>` and `<<` can be grouped under `bitwise`. Co-authored-by: Luna Razzaghipour <aramisnoah@gmail.com>
| -rw-r--r-- | crates/ide/src/syntax_highlighting/highlight.rs | 8 | ||||
| -rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/highlight_operators.html | 57 | ||||
| -rw-r--r-- | crates/ide/src/syntax_highlighting/tests.rs | 24 |
3 files changed, 85 insertions, 4 deletions
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<RootDatabase>, 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 @@ + +<style> +body { margin: 0; } +pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; } + +.lifetime { color: #DFAF8F; font-style: italic; } +.label { color: #DFAF8F; font-style: italic; } +.comment { color: #7F9F7F; } +.documentation { color: #629755; } +.intra_doc_link { font-style: italic; } +.injected { opacity: 0.65 ; } +.struct, .enum { color: #7CB8BB; } +.enum_variant { color: #BDE0F3; } +.string_literal { color: #CC9393; } +.field { color: #94BFF3; } +.function { color: #93E0E3; } +.function.unsafe { color: #BC8383; } +.trait.unsafe { color: #BC8383; } +.operator.unsafe { color: #BC8383; } +.mutable.unsafe { color: #BC8383; text-decoration: underline; } +.keyword.unsafe { color: #BC8383; font-weight: bold; } +.parameter { color: #94BFF3; } +.text { color: #DCDCCC; } +.type { color: #7CB8BB; } +.builtin_type { color: #8CD0D3; } +.type_param { color: #DFAF8F; } +.attribute { color: #94BFF3; } +.numeric_literal { color: #BFEBBF; } +.bool_literal { color: #BFE6EB; } +.macro { color: #94BFF3; } +.derive { color: #94BFF3; font-style: italic; } +.module { color: #AFD8AF; } +.value_param { color: #DCDCCC; } +.variable { color: #DCDCCC; } +.format_specifier { color: #CC696B; } +.mutable { text-decoration: underline; } +.escape_sequence { color: #94BFF3; } +.keyword { color: #F0DFAF; font-weight: bold; } +.control { font-style: italic; } +.reference { font-style: italic; font-weight: bold; } + +.unresolved_reference { color: #FC5555; text-decoration: wavy underline; } +</style> +<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span> + <span class="numeric_literal">1</span> <span class="arithmetic">+</span> <span class="numeric_literal">1</span> <span class="arithmetic">-</span> <span class="numeric_literal">1</span> <span class="arithmetic">*</span> <span class="numeric_literal">1</span> <span class="arithmetic">/</span> <span class="numeric_literal">1</span> <span class="arithmetic">%</span> <span class="numeric_literal">1</span> <span class="bitwise">|</span> <span class="numeric_literal">1</span> <span class="bitwise">&</span> <span class="numeric_literal">1</span> <span class="logical">!</span> <span class="numeric_literal">1</span> <span class="bitwise">^</span> <span class="numeric_literal">1</span> <span class="bitwise">>></span> <span class="numeric_literal">1</span> <span class="bitwise"><<</span> <span class="numeric_literal">1</span><span class="semicolon">;</span> + <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">a</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span> + <span class="variable mutable">a</span> <span class="arithmetic mutable">+=</span> <span class="numeric_literal">1</span><span class="semicolon">;</span> + <span class="variable mutable">a</span> <span class="arithmetic mutable">-=</span> <span class="numeric_literal">1</span><span class="semicolon">;</span> + <span class="variable mutable">a</span> <span class="arithmetic mutable">*=</span> <span class="numeric_literal">1</span><span class="semicolon">;</span> + <span class="variable mutable">a</span> <span class="arithmetic mutable">/=</span> <span class="numeric_literal">1</span><span class="semicolon">;</span> + <span class="variable mutable">a</span> <span class="arithmetic mutable">%=</span> <span class="numeric_literal">1</span><span class="semicolon">;</span> + <span class="variable mutable">a</span> <span class="bitwise mutable">|=</span> <span class="numeric_literal">1</span><span class="semicolon">;</span> + <span class="variable mutable">a</span> <span class="bitwise mutable">&=</span> <span class="numeric_literal">1</span><span class="semicolon">;</span> + <span class="variable mutable">a</span> <span class="bitwise mutable">^=</span> <span class="numeric_literal">1</span><span class="semicolon">;</span> + <span class="variable mutable">a</span> <span class="bitwise mutable">>>=</span> <span class="numeric_literal">1</span><span class="semicolon">;</span> + <span class="variable mutable">a</span> <span class="bitwise mutable"><<=</span> <span class="numeric_literal">1</span><span class="semicolon">;</span> +<span class="brace">}</span></code></pre> \ 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 @@ -842,6 +842,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( r#" |
