mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
format string highlighting: handle hex + debug type specifier
This commit is contained in:
parent
e8c803937c
commit
a15dda48c6
3 changed files with 26 additions and 0 deletions
|
@ -93,4 +93,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
|
|
||||||
<span class="macro">println!</span><span class="punctuation">(</span><span class="string_literal">"</span><span class="format_specifier">{</span><span class="escape_sequence">\x41</span><span class="format_specifier">}</span><span class="string_literal">"</span><span class="punctuation">,</span> A <span class="operator">=</span> <span class="numeric_literal">92</span><span class="punctuation">)</span><span class="punctuation">;</span>
|
<span class="macro">println!</span><span class="punctuation">(</span><span class="string_literal">"</span><span class="format_specifier">{</span><span class="escape_sequence">\x41</span><span class="format_specifier">}</span><span class="string_literal">"</span><span class="punctuation">,</span> A <span class="operator">=</span> <span class="numeric_literal">92</span><span class="punctuation">)</span><span class="punctuation">;</span>
|
||||||
<span class="macro">println!</span><span class="punctuation">(</span><span class="string_literal">"</span><span class="format_specifier">{</span><span class="variable">ничоси</span><span class="format_specifier">}</span><span class="string_literal">"</span><span class="punctuation">,</span> ничоси <span class="operator">=</span> <span class="numeric_literal">92</span><span class="punctuation">)</span><span class="punctuation">;</span>
|
<span class="macro">println!</span><span class="punctuation">(</span><span class="string_literal">"</span><span class="format_specifier">{</span><span class="variable">ничоси</span><span class="format_specifier">}</span><span class="string_literal">"</span><span class="punctuation">,</span> ничоси <span class="operator">=</span> <span class="numeric_literal">92</span><span class="punctuation">)</span><span class="punctuation">;</span>
|
||||||
|
|
||||||
|
<span class="macro">println!</span><span class="punctuation">(</span><span class="string_literal">"</span><span class="format_specifier">{</span><span class="format_specifier">:</span><span class="variable">x</span><span class="format_specifier">?</span><span class="format_specifier">}</span><span class="string_literal"> </span><span class="format_specifier">{</span><span class="format_specifier">}</span><span class="string_literal"> "</span><span class="punctuation">,</span> thingy<span class="punctuation">,</span> n2<span class="punctuation">)</span><span class="punctuation">;</span>
|
||||||
<span class="punctuation">}</span></code></pre>
|
<span class="punctuation">}</span></code></pre>
|
|
@ -340,6 +340,8 @@ fn main() {
|
||||||
|
|
||||||
println!("{\x41}", A = 92);
|
println!("{\x41}", A = 92);
|
||||||
println!("{ничоси}", ничоси = 92);
|
println!("{ничоси}", ничоси = 92);
|
||||||
|
|
||||||
|
println!("{:x?} {} ", thingy, n2);
|
||||||
}"#
|
}"#
|
||||||
.trim(),
|
.trim(),
|
||||||
expect_file!["./test_data/highlight_strings.html"],
|
expect_file!["./test_data/highlight_strings.html"],
|
||||||
|
|
|
@ -331,10 +331,22 @@ pub trait HasFormatSpecifier: AstToken {
|
||||||
}
|
}
|
||||||
c if c == '_' || c.is_alphabetic() => {
|
c if c == '_' || c.is_alphabetic() => {
|
||||||
read_identifier(&mut chars, &mut callback);
|
read_identifier(&mut chars, &mut callback);
|
||||||
|
|
||||||
|
if chars.peek().and_then(|next| next.1.as_ref().ok()).copied()
|
||||||
|
== Some('?')
|
||||||
|
{
|
||||||
|
skip_char_and_emit(
|
||||||
|
&mut chars,
|
||||||
|
FormatSpecifier::QuestionMark,
|
||||||
|
&mut callback,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// can be either width (indicated by dollar sign, or type in which case
|
// can be either width (indicated by dollar sign, or type in which case
|
||||||
// the next sign has to be `}`)
|
// the next sign has to be `}`)
|
||||||
let next =
|
let next =
|
||||||
chars.peek().and_then(|next| next.1.as_ref().ok()).copied();
|
chars.peek().and_then(|next| next.1.as_ref().ok()).copied();
|
||||||
|
|
||||||
match next {
|
match next {
|
||||||
Some('$') => skip_char_and_emit(
|
Some('$') => skip_char_and_emit(
|
||||||
&mut chars,
|
&mut chars,
|
||||||
|
@ -417,6 +429,16 @@ pub trait HasFormatSpecifier: AstToken {
|
||||||
}
|
}
|
||||||
c if c == '_' || c.is_alphabetic() => {
|
c if c == '_' || c.is_alphabetic() => {
|
||||||
read_identifier(&mut chars, &mut callback);
|
read_identifier(&mut chars, &mut callback);
|
||||||
|
|
||||||
|
if chars.peek().and_then(|next| next.1.as_ref().ok()).copied()
|
||||||
|
== Some('?')
|
||||||
|
{
|
||||||
|
skip_char_and_emit(
|
||||||
|
&mut chars,
|
||||||
|
FormatSpecifier::QuestionMark,
|
||||||
|
&mut callback,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue