Make punctuation highlighting configurable, disable it by default

This commit is contained in:
Lukas Wirth
2022-08-22 13:15:42 +02:00
parent 6627b473e2
commit 16315edaee
4 changed files with 56 additions and 13 deletions

View File

@@ -18,7 +18,7 @@ use vfs::AbsPath;
use crate::{
cargo_target_spec::CargoTargetSpec,
config::{CallInfoConfig, Config},
config::{CallInfoConfig, Config, HighlightingConfig},
global_state::GlobalStateSnapshot,
line_index::{LineEndings, LineIndex, OffsetEncoding},
lsp_ext,
@@ -517,19 +517,37 @@ pub(crate) fn semantic_tokens(
text: &str,
line_index: &LineIndex,
highlights: Vec<HlRange>,
highlight_strings: bool,
config: HighlightingConfig,
) -> lsp_types::SemanticTokens {
let id = TOKEN_RESULT_COUNTER.fetch_add(1, Ordering::SeqCst).to_string();
let mut builder = semantic_tokens::SemanticTokensBuilder::new(id);
for highlight_range in highlights {
for mut highlight_range in highlights {
if highlight_range.highlight.is_empty() {
continue;
}
let (ty, mods) = semantic_token_type_and_modifiers(highlight_range.highlight);
if !highlight_strings && ty == lsp_types::SemanticTokenType::STRING {
continue;
// apply config filtering
match &mut highlight_range.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);
}
HlTag::Punctuation(_)
if !config.punctuation && highlight_range.highlight.mods.is_empty() =>
{
continue
}
tag @ HlTag::Punctuation(_) if !config.specialize_punctuation => {
*tag = HlTag::Punctuation(HlPunct::Other);
}
_ => (),
}
let (ty, mods) = semantic_token_type_and_modifiers(highlight_range.highlight);
let token_index = semantic_tokens::type_index(ty);
let modifier_bitset = mods.0;