Skip to content

Commit 1f35e4d

Browse files
committed
Introduce invalidEscapeSequence semantic token type
1 parent 59a3e42 commit 1f35e4d

23 files changed

+52
-26
lines changed

crates/ide/src/syntax_highlighting/escape.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ pub(super) fn highlight_escape_string<T: IsString>(
1010
start: TextSize,
1111
) {
1212
string.escaped_char_ranges(&mut |piece_range, char| {
13-
if char.is_err() {
14-
return;
15-
}
16-
1713
if string.text()[piece_range.start().into()..].starts_with('\\') {
14+
let highlight = match char {
15+
Ok(_) => HlTag::EscapeSequence,
16+
Err(_) => HlTag::InvalidEscapeSequence,
17+
};
1818
stack.add(HlRange {
1919
range: piece_range + start,
20-
highlight: HlTag::EscapeSequence.into(),
20+
highlight: highlight.into(),
2121
binding_hash: None,
2222
});
2323
}

crates/ide/src/syntax_highlighting/html.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
109109
.control { font-style: italic; }
110110
.reference { font-style: italic; font-weight: bold; }
111111
112-
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
112+
.invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; }
113+
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
113114
</style>
114115
";

crates/ide/src/syntax_highlighting/tags.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub enum HlTag {
2929
Comment,
3030
EscapeSequence,
3131
FormatSpecifier,
32+
InvalidEscapeSequence,
3233
Keyword,
3334
NumericLiteral,
3435
Operator(HlOperator),
@@ -166,6 +167,7 @@ impl HlTag {
166167
HlTag::CharLiteral => "char_literal",
167168
HlTag::Comment => "comment",
168169
HlTag::EscapeSequence => "escape_sequence",
170+
HlTag::InvalidEscapeSequence => "invalid_escape_sequence",
169171
HlTag::FormatSpecifier => "format_specifier",
170172
HlTag::Keyword => "keyword",
171173
HlTag::Punctuation(punct) => match punct {

crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
.control { font-style: italic; }
4141
.reference { font-style: italic; font-weight: bold; }
4242

43-
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
43+
.invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; }
44+
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
4445
</style>
4546
<pre><code><span class="keyword">fn</span> <span class="function declaration">not_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
4647

crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
.control { font-style: italic; }
4141
.reference { font-style: italic; font-weight: bold; }
4242

43-
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
43+
.invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; }
44+
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
4445
</style>
4546
<pre><code><span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="builtin_attr attribute library">allow</span><span class="parenthesis attribute">(</span><span class="none attribute">dead_code</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
4647
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="tool_module attribute library">rustfmt</span><span class="operator attribute">::</span><span class="tool_module attribute library">skip</span><span class="attribute_bracket attribute">]</span>

crates/ide/src/syntax_highlighting/test_data/highlight_crate_root.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
.control { font-style: italic; }
4141
.reference { font-style: italic; font-weight: bold; }
4242

43-
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
43+
.invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; }
44+
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
4445
</style>
4546
<pre><code><span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module crate_root library">foo</span><span class="semicolon">;</span>
4647
<span class="keyword">use</span> <span class="module crate_root default_library library">core</span><span class="operator">::</span><span class="module default_library library">iter</span><span class="semicolon">;</span>

crates/ide/src/syntax_highlighting/test_data/highlight_default_library.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
.control { font-style: italic; }
4141
.reference { font-style: italic; font-weight: bold; }
4242

43-
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
43+
.invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; }
44+
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
4445
</style>
4546
<pre><code><span class="keyword">use</span> <span class="module crate_root default_library library">core</span><span class="operator">::</span><span class="module default_library library">iter</span><span class="semicolon">;</span>
4647

crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
.control { font-style: italic; }
4141
.reference { font-style: italic; font-weight: bold; }
4242

43-
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
43+
.invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; }
44+
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
4445
</style>
4546
<pre><code><span class="comment documentation">//! This is a module to test doc injection.</span>
4647
<span class="comment documentation">//! ```</span>

crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
.control { font-style: italic; }
4141
.reference { font-style: italic; font-weight: bold; }
4242

43-
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
43+
.invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; }
44+
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
4445
</style>
4546
<pre><code><span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module crate_root default_library library">std</span><span class="semicolon">;</span>
4647
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module crate_root default_library library">alloc</span> <span class="keyword">as</span> <span class="module crate_root default_library declaration library">abc</span><span class="semicolon">;</span>

crates/ide/src/syntax_highlighting/test_data/highlight_general.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
.control { font-style: italic; }
4141
.reference { font-style: italic; font-weight: bold; }
4242

43-
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
43+
.invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; }
44+
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
4445
</style>
4546
<pre><code><span class="keyword">use</span> <span class="module">inner</span><span class="operator">::</span><span class="brace">{</span><span class="self_keyword">self</span> <span class="keyword">as</span> <span class="module declaration">inner_mod</span><span class="brace">}</span><span class="semicolon">;</span>
4647
<span class="keyword">mod</span> <span class="module declaration">inner</span> <span class="brace">{</span><span class="brace">}</span>

0 commit comments

Comments
 (0)