mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-16 07:03:57 +00:00
Add config for macro bang token highlighting, disable by default
This commit is contained in:
parent
b26733f8a0
commit
f6f0516603
5 changed files with 16 additions and 6 deletions
|
@ -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 => {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue