diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 1804dc7228..50371d620e 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -50,6 +50,8 @@ pub struct HighlightConfig { pub specialize_operator: bool, /// Whether to inject highlights into doc comments pub inject_doc_comment: bool, + /// Whether to highlight the macro call bang + pub macro_bang: bool, /// Whether to highlight unresolved things be their syntax pub syntactic_name_ref_highlighting: bool, } @@ -457,10 +459,12 @@ fn traverse( match &mut highlight.tag { HlTag::StringLiteral if !config.strings => continue, // If punctuation is disabled, make the macro bang part of the macro call again. - tag @ HlTag::Punctuation(HlPunct::MacroBang) - if !config.punctuation || !config.specialize_punctuation => - { - *tag = HlTag::Symbol(SymbolKind::Macro); + tag @ HlTag::Punctuation(HlPunct::MacroBang) => { + if !config.macro_bang { + *tag = HlTag::Symbol(SymbolKind::Macro); + } else if !config.specialize_punctuation { + *tag = HlTag::Punctuation(HlPunct::Other); + } } HlTag::Punctuation(_) if !config.punctuation => continue, tag @ HlTag::Punctuation(_) if !config.specialize_punctuation => { diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs index 832f19b1c8..e91fd7f125 100644 --- a/crates/ide/src/syntax_highlighting/html.rs +++ b/crates/ide/src/syntax_highlighting/html.rs @@ -32,6 +32,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo specialize_operator: true, operator: true, inject_doc_comment: true, + macro_bang: true, syntactic_name_ref_highlighting: false, }, file_id, diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index 9db35b17c0..3949f1189b 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -199,7 +199,7 @@ impl fmt::Display for HlTag { } impl HlMod { - const ALL: &'static [HlMod; HlMod::Unsafe as u8 as usize + 1] = &[ + const ALL: &'static [HlMod; 19] = &[ HlMod::Associated, HlMod::Async, HlMod::Attribute, diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 3d086935f0..51ddea63ac 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -13,6 +13,7 @@ const HL_CONFIG: HighlightConfig = HighlightConfig { specialize_operator: true, operator: true, inject_doc_comment: true, + macro_bang: true, syntactic_name_ref_highlighting: false, }; diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index a3a4f9f3f1..0538aeb65e 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -394,13 +394,16 @@ config_data! { /// Use semantic tokens for punctuations. /// /// When disabled, rust-analyzer will emit semantic tokens only for punctuation tokens when - /// they are tagged with modifiers. + /// they are tagged with modifiers or have a special role. semanticHighlighting_punctuation_enable: bool = "false", /// Use specialized semantic tokens for punctuations. /// /// When enabled, rust-analyzer will emit special token types for punctuation tokens instead /// of the generic `punctuation` token type. semanticHighlighting_punctuation_specialization_enable: bool = "false", + /// When enabled, rust-analyzer will emit a punctuation semantic token for the `!` of macro + /// calls. + semanticHighlighting_punctuation_separate_macro_bang: bool = "false", /// Use semantic tokens for operators. /// /// When disabled, rust-analyzer will emit semantic tokens only for operator tokens when @@ -1203,6 +1206,7 @@ impl Config { specialize_punctuation: self .data .semanticHighlighting_punctuation_specialization_enable, + macro_bang: self.data.semanticHighlighting_punctuation_separate_macro_bang, operator: self.data.semanticHighlighting_operator_enable, specialize_operator: self.data.semanticHighlighting_operator_specialization_enable, inject_doc_comment: self.data.semanticHighlighting_doc_comment_inject_enable,