Skip to content

Commit 9700c95

Browse files
committed
Make doc comment highlight injection configurable
1 parent 9a20187 commit 9700c95

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

crates/ide/src/syntax_highlighting.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,19 @@ pub struct HlRange {
3838

3939
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
4040
pub struct HighlightConfig {
41+
/// Whether to highlight strings
4142
pub strings: bool,
43+
/// Whether to highlight punctuation
4244
pub punctuation: bool,
45+
/// Whether to specialize punctuation highlights
4346
pub specialize_punctuation: bool,
44-
pub specialize_operator: bool,
47+
/// Whether to highlight operator
4548
pub operator: bool,
49+
/// Whether to specialize operator highlights
50+
pub specialize_operator: bool,
51+
/// Whether to inject highlights into doc comments
52+
pub inject_doc_comment: bool,
53+
/// Whether to highlight unresolved things be their syntax
4654
pub syntactic_name_ref_highlighting: bool,
4755
}
4856

@@ -325,9 +333,11 @@ fn traverse(
325333
Enter(it) => it,
326334
Leave(NodeOrToken::Token(_)) => continue,
327335
Leave(NodeOrToken::Node(node)) => {
328-
// Doc comment highlighting injection, we do this when leaving the node
329-
// so that we overwrite the highlighting of the doc comment itself.
330-
inject::doc_comment(hl, sema, config, file_id, &node);
336+
if config.inject_doc_comment {
337+
// Doc comment highlighting injection, we do this when leaving the node
338+
// so that we overwrite the highlighting of the doc comment itself.
339+
inject::doc_comment(hl, sema, config, file_id, &node);
340+
}
331341
continue;
332342
}
333343
};

crates/ide/src/syntax_highlighting/html.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
3131
specialize_punctuation: true,
3232
specialize_operator: true,
3333
operator: true,
34+
inject_doc_comment: true,
3435
syntactic_name_ref_highlighting: false,
3536
},
3637
file_id,

crates/ide/src/syntax_highlighting/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const HL_CONFIG: HighlightConfig = HighlightConfig {
1212
specialize_punctuation: true,
1313
specialize_operator: true,
1414
operator: true,
15+
inject_doc_comment: true,
1516
syntactic_name_ref_highlighting: false,
1617
};
1718

crates/rust-analyzer/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ config_data! {
411411
/// When enabled, rust-analyzer will emit special token types for operator tokens instead
412412
/// of the generic `operator` token type.
413413
semanticHighlighting_operator_specialization_enable: bool = "false",
414+
/// Inject additional highlighting into doc comments.
415+
///
416+
/// When enabled, rust-analyzer will highlight rust source in doc comments as well as intra
417+
/// doc links.
418+
semanticHighlighting_doc_comment_inject_enable: bool = "true",
414419

415420
/// Show full signature of the callable. Only shows parameters if disabled.
416421
signatureInfo_detail: SignatureDetail = "\"full\"",
@@ -1200,6 +1205,7 @@ impl Config {
12001205
.semanticHighlighting_punctuation_specialization_enable,
12011206
operator: self.data.semanticHighlighting_operator_enable,
12021207
specialize_operator: self.data.semanticHighlighting_operator_specialization_enable,
1208+
inject_doc_comment: self.data.semanticHighlighting_doc_comment_inject_enable,
12031209
syntactic_name_ref_highlighting: false,
12041210
}
12051211
}

0 commit comments

Comments
 (0)