aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/syntax_highlighting.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/syntax_highlighting.rs')
-rw-r--r--crates/ide/src/syntax_highlighting.rs40
1 files changed, 18 insertions, 22 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index b82e3775e..f2d4da78d 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -24,7 +24,7 @@ use syntax::{
24 24
25use crate::{ 25use crate::{
26 syntax_highlighting::{ 26 syntax_highlighting::{
27 format::FormatStringHighlighter, highlights::Highlights, 27 format::highlight_format_string, highlights::Highlights,
28 macro_rules::MacroRulesHighlighter, tags::Highlight, 28 macro_rules::MacroRulesHighlighter, tags::Highlight,
29 }, 29 },
30 FileId, HlMod, HlTag, SymbolKind, 30 FileId, HlMod, HlTag, SymbolKind,
@@ -88,7 +88,6 @@ fn traverse(
88 88
89 let mut current_macro_call: Option<ast::MacroCall> = None; 89 let mut current_macro_call: Option<ast::MacroCall> = None;
90 let mut current_macro_rules: Option<ast::MacroRules> = None; 90 let mut current_macro_rules: Option<ast::MacroRules> = None;
91 let mut format_string_highlighter = FormatStringHighlighter::default();
92 let mut macro_rules_highlighter = MacroRulesHighlighter::default(); 91 let mut macro_rules_highlighter = MacroRulesHighlighter::default();
93 let mut inside_attribute = false; 92 let mut inside_attribute = false;
94 93
@@ -120,7 +119,6 @@ fn traverse(
120 WalkEvent::Leave(Some(mc)) => { 119 WalkEvent::Leave(Some(mc)) => {
121 assert_eq!(current_macro_call, Some(mc)); 120 assert_eq!(current_macro_call, Some(mc));
122 current_macro_call = None; 121 current_macro_call = None;
123 format_string_highlighter = FormatStringHighlighter::default();
124 } 122 }
125 _ => (), 123 _ => (),
126 } 124 }
@@ -175,8 +173,6 @@ fn traverse(
175 let token = sema.descend_into_macros(token.clone()); 173 let token = sema.descend_into_macros(token.clone());
176 let parent = token.parent(); 174 let parent = token.parent();
177 175
178 format_string_highlighter.check_for_format_string(&parent);
179
180 // We only care Name and Name_ref 176 // We only care Name and Name_ref
181 match (token.kind(), parent.kind()) { 177 match (token.kind(), parent.kind()) {
182 (IDENT, NAME) | (IDENT, NAME_REF) => parent.into(), 178 (IDENT, NAME) | (IDENT, NAME_REF) => parent.into(),
@@ -195,6 +191,10 @@ fn traverse(
195 } 191 }
196 } 192 }
197 193
194 if let Some(_) = macro_rules_highlighter.highlight(element_to_highlight.clone()) {
195 continue;
196 }
197
198 if let Some((mut highlight, binding_hash)) = highlight::element( 198 if let Some((mut highlight, binding_hash)) = highlight::element(
199 &sema, 199 &sema,
200 &mut bindings_shadow_count, 200 &mut bindings_shadow_count,
@@ -205,24 +205,20 @@ fn traverse(
205 highlight = highlight | HlMod::Attribute; 205 highlight = highlight | HlMod::Attribute;
206 } 206 }
207 207
208 if macro_rules_highlighter.highlight(element_to_highlight.clone()).is_none() { 208 hl.add(HlRange { range, highlight, binding_hash });
209 hl.add(HlRange { range, highlight, binding_hash }); 209 }
210 }
211 210
212 if let Some(string) = 211 if let Some(string) = element_to_highlight.as_token().cloned().and_then(ast::String::cast) {
213 element_to_highlight.as_token().cloned().and_then(ast::String::cast) 212 highlight_format_string(hl, &string, range);
214 { 213 // Highlight escape sequences
215 format_string_highlighter.highlight_format_string(hl, &string, range); 214 if let Some(char_ranges) = string.char_ranges() {
216 // Highlight escape sequences 215 for (piece_range, _) in char_ranges.iter().filter(|(_, char)| char.is_ok()) {
217 if let Some(char_ranges) = string.char_ranges() { 216 if string.text()[piece_range.start().into()..].starts_with('\\') {
218 for (piece_range, _) in char_ranges.iter().filter(|(_, char)| char.is_ok()) { 217 hl.add(HlRange {
219 if string.text()[piece_range.start().into()..].starts_with('\\') { 218 range: piece_range + range.start(),
220 hl.add(HlRange { 219 highlight: HlTag::EscapeSequence.into(),
221 range: piece_range + range.start(), 220 binding_hash: None,
222 highlight: HlTag::EscapeSequence.into(), 221 });
223 binding_hash: None,
224 });
225 }
226 } 222 }
227 } 223 }
228 } 224 }