about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-08-22 14:09:38 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-08-23 14:05:56 +0200
commitf6f0516603b50d2b4c77fc0bcabd0ee3fe1b09e9 (patch)
tree35e93e55d615df4f9c3a8753616051be1cb96e18
parentb26733f8a0b46355e385fceb2baa30aa9b4d420c (diff)
downloadrust-f6f0516603b50d2b4c77fc0bcabd0ee3fe1b09e9.tar.gz
rust-f6f0516603b50d2b4c77fc0bcabd0ee3fe1b09e9.zip
Add config for macro bang token highlighting, disable by default
-rw-r--r--crates/ide/src/syntax_highlighting.rs12
-rw-r--r--crates/ide/src/syntax_highlighting/html.rs1
-rw-r--r--crates/ide/src/syntax_highlighting/tags.rs2
-rw-r--r--crates/ide/src/syntax_highlighting/tests.rs1
-rw-r--r--crates/rust-analyzer/src/config.rs6
5 files changed, 16 insertions, 6 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 1804dc72289..50371d620eb 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 832f19b1c8a..e91fd7f1257 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 9db35b17c06..3949f1189bd 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 3d086935f07..51ddea63ac1 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 a3a4f9f3f13..0538aeb65e1 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,