Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/syntax_highlighting/escape.rs')
| -rw-r--r-- | crates/ide/src/syntax_highlighting/escape.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/crates/ide/src/syntax_highlighting/escape.rs b/crates/ide/src/syntax_highlighting/escape.rs new file mode 100644 index 0000000000..6a1236c793 --- /dev/null +++ b/crates/ide/src/syntax_highlighting/escape.rs @@ -0,0 +1,25 @@ +//! Syntax highlighting for escape sequences +use crate::syntax_highlighting::highlights::Highlights; +use crate::{HlRange, HlTag}; +use syntax::ast::IsString; +use syntax::TextSize; + +pub(super) fn highlight_escape_string<T: IsString>( + stack: &mut Highlights, + string: &T, + start: TextSize, +) { + string.escaped_char_ranges(&mut |piece_range, char| { + if char.is_err() { + return; + } + + if string.text()[piece_range.start().into()..].starts_with('\\') { + stack.add(HlRange { + range: piece_range + start, + highlight: HlTag::EscapeSequence.into(), + binding_hash: None, + }); + } + }); +} |