mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Adapt format specifier highlighting to support escaped squences and unicode identifiers
This commit is contained in:
parent
b2829a5216
commit
445052f6d4
4 changed files with 208 additions and 143 deletions
|
@ -245,28 +245,29 @@ pub(crate) fn highlight(
|
|||
stack.push();
|
||||
if is_format_string {
|
||||
string.lex_format_specifier(|piece_range, kind| {
|
||||
let highlight = match kind {
|
||||
FormatSpecifier::Open
|
||||
| FormatSpecifier::Close
|
||||
| FormatSpecifier::Colon
|
||||
| FormatSpecifier::Fill
|
||||
| FormatSpecifier::Align
|
||||
| FormatSpecifier::Sign
|
||||
| FormatSpecifier::NumberSign
|
||||
| FormatSpecifier::DollarSign
|
||||
| FormatSpecifier::Dot
|
||||
| FormatSpecifier::Asterisk
|
||||
| FormatSpecifier::QuestionMark => HighlightTag::Attribute,
|
||||
FormatSpecifier::Integer | FormatSpecifier::Zero => {
|
||||
HighlightTag::NumericLiteral
|
||||
}
|
||||
FormatSpecifier::Identifier => HighlightTag::Local,
|
||||
};
|
||||
stack.add(HighlightedRange {
|
||||
range: piece_range + range.start(),
|
||||
highlight: highlight.into(),
|
||||
binding_hash: None,
|
||||
});
|
||||
if let Some(highlight) = highlight_format_specifier(kind) {
|
||||
stack.add(HighlightedRange {
|
||||
range: piece_range + range.start(),
|
||||
highlight: highlight.into(),
|
||||
binding_hash: None,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
stack.pop();
|
||||
} else if let Some(string) =
|
||||
element_to_highlight.as_token().cloned().and_then(ast::RawString::cast)
|
||||
{
|
||||
stack.push();
|
||||
if is_format_string {
|
||||
string.lex_format_specifier(|piece_range, kind| {
|
||||
if let Some(highlight) = highlight_format_specifier(kind) {
|
||||
stack.add(HighlightedRange {
|
||||
range: piece_range + range.start(),
|
||||
highlight: highlight.into(),
|
||||
binding_hash: None,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
stack.pop();
|
||||
|
@ -277,6 +278,24 @@ pub(crate) fn highlight(
|
|||
stack.flattened()
|
||||
}
|
||||
|
||||
fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> {
|
||||
Some(match kind {
|
||||
FormatSpecifier::Open
|
||||
| FormatSpecifier::Close
|
||||
| FormatSpecifier::Colon
|
||||
| FormatSpecifier::Fill
|
||||
| FormatSpecifier::Align
|
||||
| FormatSpecifier::Sign
|
||||
| FormatSpecifier::NumberSign
|
||||
| FormatSpecifier::DollarSign
|
||||
| FormatSpecifier::Dot
|
||||
| FormatSpecifier::Asterisk
|
||||
| FormatSpecifier::QuestionMark => HighlightTag::Attribute,
|
||||
FormatSpecifier::Integer | FormatSpecifier::Zero => HighlightTag::NumericLiteral,
|
||||
FormatSpecifier::Identifier => HighlightTag::Local,
|
||||
})
|
||||
}
|
||||
|
||||
fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
|
||||
let path = macro_call.path()?;
|
||||
let name_ref = path.segment()?.name_ref()?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue