diff options
author | Leander Tentrup <[email protected]> | 2020-06-17 14:27:13 +0100 |
---|---|---|
committer | Leander Tentrup <[email protected]> | 2020-06-17 14:27:13 +0100 |
commit | 2145e2d878fb3b8ffcaa4ab0858cab3a7a4324e0 (patch) | |
tree | 2b1931cadd7400a09e6d10f0cb9ae4cc6646e93d /crates/ra_ide/src/syntax_highlighting.rs | |
parent | 931f3173992df6ac6b728fa9fa9a94d15781027e (diff) |
Syntax highlighting for escape sequences in strings
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 5a4de450c..854b6cc6d 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -212,8 +212,8 @@ pub(crate) fn highlight( | |||
212 | if let Some(string) = | 212 | if let Some(string) = |
213 | element_to_highlight.as_token().cloned().and_then(ast::String::cast) | 213 | element_to_highlight.as_token().cloned().and_then(ast::String::cast) |
214 | { | 214 | { |
215 | stack.push(); | ||
216 | if is_format_string { | 215 | if is_format_string { |
216 | stack.push(); | ||
217 | string.lex_format_specifier(|piece_range, kind| { | 217 | string.lex_format_specifier(|piece_range, kind| { |
218 | if let Some(highlight) = highlight_format_specifier(kind) { | 218 | if let Some(highlight) = highlight_format_specifier(kind) { |
219 | stack.add(HighlightedRange { | 219 | stack.add(HighlightedRange { |
@@ -223,13 +223,27 @@ pub(crate) fn highlight( | |||
223 | }); | 223 | }); |
224 | } | 224 | } |
225 | }); | 225 | }); |
226 | stack.pop(); | ||
227 | } | ||
228 | // Highlight escape sequences | ||
229 | if let Some(char_ranges) = string.char_ranges() { | ||
230 | stack.push(); | ||
231 | for (piece_range, _) in char_ranges.iter().filter(|(_, char)| char.is_ok()) { | ||
232 | if string.text()[piece_range.start().into()..].starts_with('\\') { | ||
233 | stack.add(HighlightedRange { | ||
234 | range: piece_range + range.start(), | ||
235 | highlight: HighlightTag::EscapeSequence.into(), | ||
236 | binding_hash: None, | ||
237 | }); | ||
238 | } | ||
239 | } | ||
240 | stack.pop_and_inject(false); | ||
226 | } | 241 | } |
227 | stack.pop(); | ||
228 | } else if let Some(string) = | 242 | } else if let Some(string) = |
229 | element_to_highlight.as_token().cloned().and_then(ast::RawString::cast) | 243 | element_to_highlight.as_token().cloned().and_then(ast::RawString::cast) |
230 | { | 244 | { |
231 | stack.push(); | ||
232 | if is_format_string { | 245 | if is_format_string { |
246 | stack.push(); | ||
233 | string.lex_format_specifier(|piece_range, kind| { | 247 | string.lex_format_specifier(|piece_range, kind| { |
234 | if let Some(highlight) = highlight_format_specifier(kind) { | 248 | if let Some(highlight) = highlight_format_specifier(kind) { |
235 | stack.add(HighlightedRange { | 249 | stack.add(HighlightedRange { |
@@ -239,8 +253,8 @@ pub(crate) fn highlight( | |||
239 | }); | 253 | }); |
240 | } | 254 | } |
241 | }); | 255 | }); |
256 | stack.pop(); | ||
242 | } | 257 | } |
243 | stack.pop(); | ||
244 | } | 258 | } |
245 | } | 259 | } |
246 | } | 260 | } |