about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-08-22 13:44:07 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-08-23 14:05:55 +0200
commit9700c95ced0abb3047ace17afe9aba0086679a76 (patch)
treeecfcafc295b28971ea36110b44556d8ce3feea49
parent9a201873b828b64dd276df42b3dbd263682392b7 (diff)
downloadrust-9700c95ced0abb3047ace17afe9aba0086679a76.tar.gz
rust-9700c95ced0abb3047ace17afe9aba0086679a76.zip
Make doc comment highlight injection configurable
-rw-r--r--crates/ide/src/syntax_highlighting.rs18
-rw-r--r--crates/ide/src/syntax_highlighting/html.rs1
-rw-r--r--crates/ide/src/syntax_highlighting/tests.rs1
-rw-r--r--crates/rust-analyzer/src/config.rs6
4 files changed, 22 insertions, 4 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 21beeb44a9d..1804dc72289 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -38,11 +38,19 @@ pub struct HlRange {
 
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
 pub struct HighlightConfig {
+    /// Whether to highlight strings
     pub strings: bool,
+    /// Whether to highlight punctuation
     pub punctuation: bool,
+    /// Whether to specialize punctuation highlights
     pub specialize_punctuation: bool,
-    pub specialize_operator: bool,
+    /// Whether to highlight operator
     pub operator: bool,
+    /// Whether to specialize operator highlights
+    pub specialize_operator: bool,
+    /// Whether to inject highlights into doc comments
+    pub inject_doc_comment: bool,
+    /// Whether to highlight unresolved things be their syntax
     pub syntactic_name_ref_highlighting: bool,
 }
 
@@ -325,9 +333,11 @@ fn traverse(
             Enter(it) => it,
             Leave(NodeOrToken::Token(_)) => continue,
             Leave(NodeOrToken::Node(node)) => {
-                // Doc comment highlighting injection, we do this when leaving the node
-                // so that we overwrite the highlighting of the doc comment itself.
-                inject::doc_comment(hl, sema, config, file_id, &node);
+                if config.inject_doc_comment {
+                    // Doc comment highlighting injection, we do this when leaving the node
+                    // so that we overwrite the highlighting of the doc comment itself.
+                    inject::doc_comment(hl, sema, config, file_id, &node);
+                }
                 continue;
             }
         };
diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs
index c841456aef3..832f19b1c8a 100644
--- a/crates/ide/src/syntax_highlighting/html.rs
+++ b/crates/ide/src/syntax_highlighting/html.rs
@@ -31,6 +31,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
             specialize_punctuation: true,
             specialize_operator: true,
             operator: true,
+            inject_doc_comment: true,
             syntactic_name_ref_highlighting: false,
         },
         file_id,
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index 246c6e37225..3d086935f07 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -12,6 +12,7 @@ const HL_CONFIG: HighlightConfig = HighlightConfig {
     specialize_punctuation: true,
     specialize_operator: true,
     operator: true,
+    inject_doc_comment: true,
     syntactic_name_ref_highlighting: false,
 };
 
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 3badc890958..a3a4f9f3f13 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -411,6 +411,11 @@ config_data! {
         /// When enabled, rust-analyzer will emit special token types for operator tokens instead
         /// of the generic `operator` token type.
         semanticHighlighting_operator_specialization_enable: bool = "false",
+        /// Inject additional highlighting into doc comments.
+        ///
+        /// When enabled, rust-analyzer will highlight rust source in doc comments as well as intra
+        /// doc links.
+        semanticHighlighting_doc_comment_inject_enable: bool = "true",
 
         /// Show full signature of the callable. Only shows parameters if disabled.
         signatureInfo_detail: SignatureDetail                           = "\"full\"",
@@ -1200,6 +1205,7 @@ impl Config {
                 .semanticHighlighting_punctuation_specialization_enable,
             operator: self.data.semanticHighlighting_operator_enable,
             specialize_operator: self.data.semanticHighlighting_operator_specialization_enable,
+            inject_doc_comment: self.data.semanticHighlighting_doc_comment_inject_enable,
             syntactic_name_ref_highlighting: false,
         }
     }