1 //! Syntax highlighting for format macro strings.
2 use ide_db::{helpers::format_string::is_format_string, SymbolKind};
4 ast::{self, FormatSpecifier, HasFormatSpecifier},
8 use crate::{syntax_highlighting::highlights::Highlights, HlRange, HlTag};
10 pub(super) fn highlight_format_string(
11 stack: &mut Highlights,
13 expanded_string: &ast::String,
16 if !is_format_string(expanded_string) {
20 string.lex_format_specifier(|piece_range, kind| {
21 if let Some(highlight) = highlight_format_specifier(kind) {
23 range: piece_range + range.start(),
24 highlight: highlight.into(),
31 fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HlTag> {
34 | FormatSpecifier::Close
35 | FormatSpecifier::Colon
36 | FormatSpecifier::Fill
37 | FormatSpecifier::Align
38 | FormatSpecifier::Sign
39 | FormatSpecifier::NumberSign
40 | FormatSpecifier::DollarSign
41 | FormatSpecifier::Dot
42 | FormatSpecifier::Asterisk
43 | FormatSpecifier::QuestionMark => HlTag::FormatSpecifier,
45 FormatSpecifier::Integer | FormatSpecifier::Zero => HlTag::NumericLiteral,
47 FormatSpecifier::Identifier => HlTag::Symbol(SymbolKind::Local),