Skip to content

Commit f6f0516

Browse files
committed
Add config for macro bang token highlighting, disable by default
1 parent b26733f commit f6f0516

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

crates/ide/src/syntax_highlighting.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ pub struct HighlightConfig {
5050
pub specialize_operator: bool,
5151
/// Whether to inject highlights into doc comments
5252
pub inject_doc_comment: bool,
53+
/// Whether to highlight the macro call bang
54+
pub macro_bang: bool,
5355
/// Whether to highlight unresolved things be their syntax
5456
pub syntactic_name_ref_highlighting: bool,
5557
}
@@ -457,10 +459,12 @@ fn traverse(
457459
match &mut highlight.tag {
458460
HlTag::StringLiteral if !config.strings => continue,
459461
// If punctuation is disabled, make the macro bang part of the macro call again.
460-
tag @ HlTag::Punctuation(HlPunct::MacroBang)
461-
if !config.punctuation || !config.specialize_punctuation =>
462-
{
463-
*tag = HlTag::Symbol(SymbolKind::Macro);
462+
tag @ HlTag::Punctuation(HlPunct::MacroBang) => {
463+
if !config.macro_bang {
464+
*tag = HlTag::Symbol(SymbolKind::Macro);
465+
} else if !config.specialize_punctuation {
466+
*tag = HlTag::Punctuation(HlPunct::Other);
467+
}
464468
}
465469
HlTag::Punctuation(_) if !config.punctuation => continue,
466470
tag @ HlTag::Punctuation(_) if !config.specialize_punctuation => {

crates/ide/src/syntax_highlighting/html.rs

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

crates/ide/src/syntax_highlighting/tags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl fmt::Display for HlTag {
199199
}
200200

201201
impl HlMod {
202-
const ALL: &'static [HlMod; HlMod::Unsafe as u8 as usize + 1] = &[
202+
const ALL: &'static [HlMod; 19] = &[
203203
HlMod::Associated,
204204
HlMod::Async,
205205
HlMod::Attribute,

crates/ide/src/syntax_highlighting/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const HL_CONFIG: HighlightConfig = HighlightConfig {
1313
specialize_operator: true,
1414
operator: true,
1515
inject_doc_comment: true,
16+
macro_bang: true,
1617
syntactic_name_ref_highlighting: false,
1718
};
1819

crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,16 @@ config_data! {
394394
/// Use semantic tokens for punctuations.
395395
///
396396
/// When disabled, rust-analyzer will emit semantic tokens only for punctuation tokens when
397-
/// they are tagged with modifiers.
397+
/// they are tagged with modifiers or have a special role.
398398
semanticHighlighting_punctuation_enable: bool = "false",
399399
/// Use specialized semantic tokens for punctuations.
400400
///
401401
/// When enabled, rust-analyzer will emit special token types for punctuation tokens instead
402402
/// of the generic `punctuation` token type.
403403
semanticHighlighting_punctuation_specialization_enable: bool = "false",
404+
/// When enabled, rust-analyzer will emit a punctuation semantic token for the `!` of macro
405+
/// calls.
406+
semanticHighlighting_punctuation_separate_macro_bang: bool = "false",
404407
/// Use semantic tokens for operators.
405408
///
406409
/// When disabled, rust-analyzer will emit semantic tokens only for operator tokens when
@@ -1203,6 +1206,7 @@ impl Config {
12031206
specialize_punctuation: self
12041207
.data
12051208
.semanticHighlighting_punctuation_specialization_enable,
1209+
macro_bang: self.data.semanticHighlighting_punctuation_separate_macro_bang,
12061210
operator: self.data.semanticHighlighting_operator_enable,
12071211
specialize_operator: self.data.semanticHighlighting_operator_specialization_enable,
12081212
inject_doc_comment: self.data.semanticHighlighting_doc_comment_inject_enable,

0 commit comments

Comments
 (0)