diff options
author | Roland Ruckerbauer <[email protected]> | 2020-11-15 16:43:14 +0000 |
---|---|---|
committer | Roland Ruckerbauer <[email protected]> | 2020-11-15 16:43:14 +0000 |
commit | a15dda48c696cb14d490ee91f40949d5cd538aba (patch) | |
tree | dea06f18c2047a9616deabd347206e6bd3be03d0 /crates | |
parent | e8c803937ce23a6cf74583ad03f9868869c7eea1 (diff) |
format string highlighting: handle hex + debug type specifier
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/highlight_strings.html | 2 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tests.rs | 2 | ||||
-rw-r--r-- | crates/syntax/src/ast/token_ext.rs | 22 |
3 files changed, 26 insertions, 0 deletions
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html index 43f1b32fd..d398e1ec8 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html | |||
@@ -93,4 +93,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
93 | 93 | ||
94 | <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> | 94 | <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> |
95 | <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> | 95 | <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> |
96 | |||
97 | <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> | ||
96 | <span class="punctuation">}</span></code></pre> \ No newline at end of file | 98 | <span class="punctuation">}</span></code></pre> \ No newline at end of file |
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 5c22e2fce..1dc018a16 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs | |||
@@ -340,6 +340,8 @@ fn main() { | |||
340 | 340 | ||
341 | println!("{\x41}", A = 92); | 341 | println!("{\x41}", A = 92); |
342 | println!("{ничоси}", ничоси = 92); | 342 | println!("{ничоси}", ничоси = 92); |
343 | |||
344 | println!("{:x?} {} ", thingy, n2); | ||
343 | }"# | 345 | }"# |
344 | .trim(), | 346 | .trim(), |
345 | expect_file!["./test_data/highlight_strings.html"], | 347 | expect_file!["./test_data/highlight_strings.html"], |
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs index 2661c753e..ac0326420 100644 --- a/crates/syntax/src/ast/token_ext.rs +++ b/crates/syntax/src/ast/token_ext.rs | |||
@@ -331,10 +331,22 @@ pub trait HasFormatSpecifier: AstToken { | |||
331 | } | 331 | } |
332 | c if c == '_' || c.is_alphabetic() => { | 332 | c if c == '_' || c.is_alphabetic() => { |
333 | read_identifier(&mut chars, &mut callback); | 333 | read_identifier(&mut chars, &mut callback); |
334 | |||
335 | if chars.peek().and_then(|next| next.1.as_ref().ok()).copied() | ||
336 | == Some('?') | ||
337 | { | ||
338 | skip_char_and_emit( | ||
339 | &mut chars, | ||
340 | FormatSpecifier::QuestionMark, | ||
341 | &mut callback, | ||
342 | ); | ||
343 | } | ||
344 | |||
334 | // can be either width (indicated by dollar sign, or type in which case | 345 | // can be either width (indicated by dollar sign, or type in which case |
335 | // the next sign has to be `}`) | 346 | // the next sign has to be `}`) |
336 | let next = | 347 | let next = |
337 | chars.peek().and_then(|next| next.1.as_ref().ok()).copied(); | 348 | chars.peek().and_then(|next| next.1.as_ref().ok()).copied(); |
349 | |||
338 | match next { | 350 | match next { |
339 | Some('$') => skip_char_and_emit( | 351 | Some('$') => skip_char_and_emit( |
340 | &mut chars, | 352 | &mut chars, |
@@ -417,6 +429,16 @@ pub trait HasFormatSpecifier: AstToken { | |||
417 | } | 429 | } |
418 | c if c == '_' || c.is_alphabetic() => { | 430 | c if c == '_' || c.is_alphabetic() => { |
419 | read_identifier(&mut chars, &mut callback); | 431 | read_identifier(&mut chars, &mut callback); |
432 | |||
433 | if chars.peek().and_then(|next| next.1.as_ref().ok()).copied() | ||
434 | == Some('?') | ||
435 | { | ||
436 | skip_char_and_emit( | ||
437 | &mut chars, | ||
438 | FormatSpecifier::QuestionMark, | ||
439 | &mut callback, | ||
440 | ); | ||
441 | } | ||
420 | } | 442 | } |
421 | _ => {} | 443 | _ => {} |
422 | } | 444 | } |