Skip to content

Commit afc8cfb

Browse files
committed
Make operator highlighting configurable, disable it by default
1 parent 16315ed commit afc8cfb

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,17 @@ config_data! {
400400
///
401401
/// When enabled, rust-analyzer will emit special token types for punctuation tokens instead
402402
/// of the generic `punctuation` token type.
403-
semanticHighlighting_punctuation_specialize: bool = "false",
403+
semanticHighlighting_punctuation_specialization_enable: bool = "false",
404+
/// Use semantic tokens for operators.
405+
///
406+
/// When disabled, rust-analyzer will emit semantic tokens only for operator tokens when
407+
/// they are tagged with modifiers.
408+
semanticHighlighting_operator_enable: bool = "true",
409+
/// Use specialized semantic tokens for operators.
410+
///
411+
/// When enabled, rust-analyzer will emit special token types for operator tokens instead
412+
/// of the generic `operator` token type.
413+
semanticHighlighting_operator_specialization_enable: bool = "false",
404414

405415
/// Show full signature of the callable. Only shows parameters if disabled.
406416
signatureInfo_detail: SignatureDetail = "\"full\"",
@@ -538,6 +548,8 @@ pub struct HighlightingConfig {
538548
pub strings: bool,
539549
pub punctuation: bool,
540550
pub specialize_punctuation: bool,
551+
pub specialize_operator: bool,
552+
pub operator: bool,
541553
}
542554

543555
#[derive(Debug, Clone)]
@@ -1192,7 +1204,11 @@ impl Config {
11921204
HighlightingConfig {
11931205
strings: self.data.semanticHighlighting_strings_enable,
11941206
punctuation: self.data.semanticHighlighting_punctuation_enable,
1195-
specialize_punctuation: self.data.semanticHighlighting_punctuation_specialize,
1207+
specialize_punctuation: self
1208+
.data
1209+
.semanticHighlighting_punctuation_specialization_enable,
1210+
operator: self.data.semanticHighlighting_operator_enable,
1211+
specialize_operator: self.data.semanticHighlighting_operator_specialization_enable,
11961212
}
11971213
}
11981214

crates/rust-analyzer/src/to_proto.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,12 @@ pub(crate) fn semantic_tokens(
544544
tag @ HlTag::Punctuation(_) if !config.specialize_punctuation => {
545545
*tag = HlTag::Punctuation(HlPunct::Other);
546546
}
547+
HlTag::Operator(_) if !config.operator && highlight_range.highlight.mods.is_empty() => {
548+
continue
549+
}
550+
tag @ HlTag::Operator(_) if !config.specialize_operator => {
551+
*tag = HlTag::Operator(HlOperator::Other);
552+
}
547553
_ => (),
548554
}
549555

0 commit comments

Comments
 (0)