diff options
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 8ee3a78c6..b5fd3390f 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -245,28 +245,29 @@ pub(crate) fn highlight( | |||
245 | stack.push(); | 245 | stack.push(); |
246 | if is_format_string { | 246 | if is_format_string { |
247 | string.lex_format_specifier(|piece_range, kind| { | 247 | string.lex_format_specifier(|piece_range, kind| { |
248 | let highlight = match kind { | 248 | if let Some(highlight) = highlight_format_specifier(kind) { |
249 | FormatSpecifier::Open | 249 | stack.add(HighlightedRange { |
250 | | FormatSpecifier::Close | 250 | range: piece_range + range.start(), |
251 | | FormatSpecifier::Colon | 251 | highlight: highlight.into(), |
252 | | FormatSpecifier::Fill | 252 | binding_hash: None, |
253 | | FormatSpecifier::Align | 253 | }); |
254 | | FormatSpecifier::Sign | 254 | } |
255 | | FormatSpecifier::NumberSign | 255 | }); |
256 | | FormatSpecifier::DollarSign | 256 | } |
257 | | FormatSpecifier::Dot | 257 | stack.pop(); |
258 | | FormatSpecifier::Asterisk | 258 | } else if let Some(string) = |
259 | | FormatSpecifier::QuestionMark => HighlightTag::Attribute, | 259 | element_to_highlight.as_token().cloned().and_then(ast::RawString::cast) |
260 | FormatSpecifier::Integer | FormatSpecifier::Zero => { | 260 | { |
261 | HighlightTag::NumericLiteral | 261 | stack.push(); |
262 | } | 262 | if is_format_string { |
263 | FormatSpecifier::Identifier => HighlightTag::Local, | 263 | string.lex_format_specifier(|piece_range, kind| { |
264 | }; | 264 | if let Some(highlight) = highlight_format_specifier(kind) { |
265 | stack.add(HighlightedRange { | 265 | stack.add(HighlightedRange { |
266 | range: piece_range + range.start(), | 266 | range: piece_range + range.start(), |
267 | highlight: highlight.into(), | 267 | highlight: highlight.into(), |
268 | binding_hash: None, | 268 | binding_hash: None, |
269 | }); | 269 | }); |
270 | } | ||
270 | }); | 271 | }); |
271 | } | 272 | } |
272 | stack.pop(); | 273 | stack.pop(); |
@@ -277,6 +278,24 @@ pub(crate) fn highlight( | |||
277 | stack.flattened() | 278 | stack.flattened() |
278 | } | 279 | } |
279 | 280 | ||
281 | fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> { | ||
282 | Some(match kind { | ||
283 | FormatSpecifier::Open | ||
284 | | FormatSpecifier::Close | ||
285 | | FormatSpecifier::Colon | ||
286 | | FormatSpecifier::Fill | ||
287 | | FormatSpecifier::Align | ||
288 | | FormatSpecifier::Sign | ||
289 | | FormatSpecifier::NumberSign | ||
290 | | FormatSpecifier::DollarSign | ||
291 | | FormatSpecifier::Dot | ||
292 | | FormatSpecifier::Asterisk | ||
293 | | FormatSpecifier::QuestionMark => HighlightTag::Attribute, | ||
294 | FormatSpecifier::Integer | FormatSpecifier::Zero => HighlightTag::NumericLiteral, | ||
295 | FormatSpecifier::Identifier => HighlightTag::Local, | ||
296 | }) | ||
297 | } | ||
298 | |||
280 | fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> { | 299 | fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> { |
281 | let path = macro_call.path()?; | 300 | let path = macro_call.path()?; |
282 | let name_ref = path.segment()?.name_ref()?; | 301 | let name_ref = path.segment()?.name_ref()?; |