Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/ide/src/syntax_highlighting/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn punctuation(
}
(T![!], MACRO_RULES) => HlPunct::MacroBang.into(),
(T![!], NEVER_TYPE) => HlTag::BuiltinType.into(),
(T![!], PREFIX_EXPR) => HlOperator::Logical.into(),
(T![!], PREFIX_EXPR) => HlOperator::Negation.into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(T![!], PREFIX_EXPR) => HlOperator::Negation.into(),
(T![!], PREFIX_EXPR) => HlOperator::Negation.into() | HlOperator::Logical.into(),

We should include both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review. It looks however (I did not find the online cargo-doc-generation of Rust-analyzer to provide a link) that Highlight only provides BitOr for HlMod, not for other Highlights

Copy link
Contributor Author

@daladim daladim Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also hesitated to know whether Negation was actually disjoint from Logical (since they are now two separate variants of the HlOperator enum).

I think we could find reasons for both. My reason for "it is OK to dissociate them" is the fact that ! is unary while &&and || are binary, so they may be seen as quite a different class of operators.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing in the name "logical" implies a binary operator. And in fact, the boolean negation operator is a logical operator by common definition.

However you're right that there is currently no way to combine operator tags, and implementing that won't be trivial (although it's possible), therefore I'll accept this PR.

(T![*], PTR_TYPE) => HlTag::Keyword.into(),
(T![*], PREFIX_EXPR) => {
let h = HlTag::Operator(HlOperator::Other).into();
Expand Down
5 changes: 4 additions & 1 deletion crates/ide/src/syntax_highlighting/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ pub enum HlOperator {
Bitwise,
/// +, -, *, /, +=, -=, *=, /=
Arithmetic,
/// &&, ||, !
/// &&, ||
Logical,
/// !
Negation,
/// >, <, ==, >=, <=, !=
Comparison,
/// Other operators
Expand Down Expand Up @@ -194,6 +196,7 @@ impl HlTag {
HlOperator::Arithmetic => "arithmetic",
HlOperator::Logical => "logical",
HlOperator::Comparison => "comparison",
HlOperator::Negation => "negation",
HlOperator::Other => "operator",
},
HlTag::StringLiteral => "string_literal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<span class="keyword">let</span> <span class="variable declaration">baz</span> <span class="operator">=</span> <span class="parenthesis">(</span><span class="numeric_literal">-</span><span class="numeric_literal">42</span><span class="comma">,</span><span class="parenthesis">)</span><span class="semicolon">;</span>
<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="operator">.</span><span class="field library">0</span><span class="semicolon">;</span>

<span class="keyword">let</span> <span class="punctuation">_</span> <span class="operator">=</span> <span class="logical">!</span><span class="bool_literal">true</span><span class="semicolon">;</span>
<span class="keyword">let</span> <span class="punctuation">_</span> <span class="operator">=</span> <span class="negation">!</span><span class="bool_literal">true</span><span class="semicolon">;</span>

<span class="label declaration">'foo</span><span class="colon">:</span> <span class="keyword control">loop</span> <span class="brace">{</span>
<span class="keyword control">break</span> <span class="label">'foo</span><span class="semicolon">;</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
.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">&gt;&gt;</span> <span class="numeric_literal">1</span> <span class="bitwise">&lt;&lt;</span> <span class="numeric_literal">1</span><span class="semicolon">;</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="negation">!</span> <span class="numeric_literal">1</span> <span class="bitwise">^</span> <span class="numeric_literal">1</span> <span class="bitwise">&gt;&gt;</span> <span class="numeric_literal">1</span> <span class="bitwise">&lt;&lt;</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>
Expand Down
1 change: 1 addition & 0 deletions crates/rust-analyzer/src/lsp/semantic_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ define_semantic_token_types![
(LIFETIME, "lifetime"),
(LOGICAL, "logical") => OPERATOR,
(MACRO_BANG, "macroBang") => MACRO,
(NEGATION, "negation") => OPERATOR,
(PARENTHESIS, "parenthesis"),
(PROC_MACRO, "procMacro") => MACRO,
(PUNCTUATION, "punctuation"),
Expand Down
1 change: 1 addition & 0 deletions crates/rust-analyzer/src/lsp/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ fn semantic_token_type_and_modifiers(
HlOperator::Bitwise => types::BITWISE,
HlOperator::Arithmetic => types::ARITHMETIC,
HlOperator::Logical => types::LOGICAL,
HlOperator::Negation => types::NEGATION,
HlOperator::Comparison => types::COMPARISON,
HlOperator::Other => types::OPERATOR,
},
Expand Down