Skip to content

Conversation

@daladim
Copy link
Contributor

@daladim daladim commented Oct 23, 2025

Resolve #19943

This makes the following code highliting possible. How lovely.
image

See the issue for more info on how to have it actually used by VSCode's extension (basically, this requires "rust-analyzer.semanticHighlighting.operator.specialization.enable": true in VSCode's user config)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 23, 2025
(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.

Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

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

Thanks!

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Oct 23, 2025
Merged via the queue into rust-lang:master with commit d3d844c Oct 23, 2025
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 23, 2025
@lnicola
Copy link
Member

lnicola commented Oct 24, 2025

changelog fix (first contribution) add negation semantic token type

mendelsshop pushed a commit to mendelsshop/rust-analyzer that referenced this pull request Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Semantic Token Type "operator.logicalNot" Please!

4 participants