diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 7 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/tokens.rs | 59 |
2 files changed, 32 insertions, 34 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index e342ca9df..8ee3a78c6 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -194,7 +194,7 @@ pub(crate) fn highlight( | |||
194 | let token = sema.descend_into_macros(token.clone()); | 194 | let token = sema.descend_into_macros(token.clone()); |
195 | let parent = token.parent(); | 195 | let parent = token.parent(); |
196 | 196 | ||
197 | // Check if macro takes a format string and remeber it for highlighting later. | 197 | // Check if macro takes a format string and remember it for highlighting later. |
198 | // The macros that accept a format string expand to a compiler builtin macros | 198 | // The macros that accept a format string expand to a compiler builtin macros |
199 | // `format_args` and `format_args_nl`. | 199 | // `format_args` and `format_args_nl`. |
200 | if let Some(fmt_macro_call) = parent.parent().and_then(ast::MacroCall::cast) { | 200 | if let Some(fmt_macro_call) = parent.parent().and_then(ast::MacroCall::cast) { |
@@ -233,8 +233,7 @@ pub(crate) fn highlight( | |||
233 | } | 233 | } |
234 | } | 234 | } |
235 | 235 | ||
236 | let is_format_string = | 236 | let is_format_string = format_string.as_ref() == Some(&element_to_highlight); |
237 | format_string.as_ref().map(|fs| fs == &element_to_highlight).unwrap_or_default(); | ||
238 | 237 | ||
239 | if let Some((highlight, binding_hash)) = | 238 | if let Some((highlight, binding_hash)) = |
240 | highlight_element(&sema, &mut bindings_shadow_count, element_to_highlight.clone()) | 239 | highlight_element(&sema, &mut bindings_shadow_count, element_to_highlight.clone()) |
@@ -245,7 +244,7 @@ pub(crate) fn highlight( | |||
245 | { | 244 | { |
246 | stack.push(); | 245 | stack.push(); |
247 | if is_format_string { | 246 | if is_format_string { |
248 | string.lex_format_specifier(&mut |piece_range, kind| { | 247 | string.lex_format_specifier(|piece_range, kind| { |
249 | let highlight = match kind { | 248 | let highlight = match kind { |
250 | FormatSpecifier::Open | 249 | FormatSpecifier::Open |
251 | | FormatSpecifier::Close | 250 | | FormatSpecifier::Close |
diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index ec3b4e553..3e5c56b19 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs | |||
@@ -192,7 +192,7 @@ pub enum FormatSpecifier { | |||
192 | } | 192 | } |
193 | 193 | ||
194 | pub trait HasFormatSpecifier: AstToken { | 194 | pub trait HasFormatSpecifier: AstToken { |
195 | fn lex_format_specifier<F>(&self, callback: &mut F) | 195 | fn lex_format_specifier<F>(&self, mut callback: F) |
196 | where | 196 | where |
197 | F: FnMut(TextRange, FormatSpecifier), | 197 | F: FnMut(TextRange, FormatSpecifier), |
198 | { | 198 | { |
@@ -217,21 +217,15 @@ pub trait HasFormatSpecifier: AstToken { | |||
217 | FormatSpecifier::Open, | 217 | FormatSpecifier::Open, |
218 | ); | 218 | ); |
219 | 219 | ||
220 | let next_char = if let Some(c) = chars.clone().next() { | ||
221 | c | ||
222 | } else { | ||
223 | break; | ||
224 | }; | ||
225 | |||
226 | // check for integer/identifier | 220 | // check for integer/identifier |
227 | match next_char { | 221 | match chars.clone().next().unwrap_or_default() { |
228 | '0'..='9' => { | 222 | '0'..='9' => { |
229 | // integer | 223 | // integer |
230 | read_integer(&mut chars, initial_len, callback); | 224 | read_integer(&mut chars, initial_len, &mut callback); |
231 | } | 225 | } |
232 | 'a'..='z' | 'A'..='Z' | '_' => { | 226 | 'a'..='z' | 'A'..='Z' | '_' => { |
233 | // identifier | 227 | // identifier |
234 | read_identifier(&mut chars, initial_len, callback); | 228 | read_identifier(&mut chars, initial_len, &mut callback); |
235 | } | 229 | } |
236 | _ => {} | 230 | _ => {} |
237 | } | 231 | } |
@@ -241,7 +235,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
241 | &mut chars, | 235 | &mut chars, |
242 | initial_len, | 236 | initial_len, |
243 | FormatSpecifier::Colon, | 237 | FormatSpecifier::Colon, |
244 | callback, | 238 | &mut callback, |
245 | ); | 239 | ); |
246 | 240 | ||
247 | // check for fill/align | 241 | // check for fill/align |
@@ -255,13 +249,13 @@ pub trait HasFormatSpecifier: AstToken { | |||
255 | &mut chars, | 249 | &mut chars, |
256 | initial_len, | 250 | initial_len, |
257 | FormatSpecifier::Fill, | 251 | FormatSpecifier::Fill, |
258 | callback, | 252 | &mut callback, |
259 | ); | 253 | ); |
260 | skip_char_and_emit( | 254 | skip_char_and_emit( |
261 | &mut chars, | 255 | &mut chars, |
262 | initial_len, | 256 | initial_len, |
263 | FormatSpecifier::Align, | 257 | FormatSpecifier::Align, |
264 | callback, | 258 | &mut callback, |
265 | ); | 259 | ); |
266 | } | 260 | } |
267 | _ => match first { | 261 | _ => match first { |
@@ -270,7 +264,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
270 | &mut chars, | 264 | &mut chars, |
271 | initial_len, | 265 | initial_len, |
272 | FormatSpecifier::Align, | 266 | FormatSpecifier::Align, |
273 | callback, | 267 | &mut callback, |
274 | ); | 268 | ); |
275 | } | 269 | } |
276 | _ => {} | 270 | _ => {} |
@@ -284,7 +278,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
284 | &mut chars, | 278 | &mut chars, |
285 | initial_len, | 279 | initial_len, |
286 | FormatSpecifier::Sign, | 280 | FormatSpecifier::Sign, |
287 | callback, | 281 | &mut callback, |
288 | ); | 282 | ); |
289 | } | 283 | } |
290 | _ => {} | 284 | _ => {} |
@@ -296,7 +290,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
296 | &mut chars, | 290 | &mut chars, |
297 | initial_len, | 291 | initial_len, |
298 | FormatSpecifier::NumberSign, | 292 | FormatSpecifier::NumberSign, |
299 | callback, | 293 | &mut callback, |
300 | ); | 294 | ); |
301 | } | 295 | } |
302 | 296 | ||
@@ -310,25 +304,25 @@ pub trait HasFormatSpecifier: AstToken { | |||
310 | &mut chars, | 304 | &mut chars, |
311 | initial_len, | 305 | initial_len, |
312 | FormatSpecifier::Zero, | 306 | FormatSpecifier::Zero, |
313 | callback, | 307 | &mut callback, |
314 | ); | 308 | ); |
315 | } | 309 | } |
316 | 310 | ||
317 | // width | 311 | // width |
318 | match chars.clone().next().unwrap_or_default() { | 312 | match chars.clone().next().unwrap_or_default() { |
319 | '0'..='9' => { | 313 | '0'..='9' => { |
320 | read_integer(&mut chars, initial_len, callback); | 314 | read_integer(&mut chars, initial_len, &mut callback); |
321 | if chars.clone().next() == Some('$') { | 315 | if chars.clone().next() == Some('$') { |
322 | skip_char_and_emit( | 316 | skip_char_and_emit( |
323 | &mut chars, | 317 | &mut chars, |
324 | initial_len, | 318 | initial_len, |
325 | FormatSpecifier::DollarSign, | 319 | FormatSpecifier::DollarSign, |
326 | callback, | 320 | &mut callback, |
327 | ); | 321 | ); |
328 | } | 322 | } |
329 | } | 323 | } |
330 | 'a'..='z' | 'A'..='Z' | '_' => { | 324 | 'a'..='z' | 'A'..='Z' | '_' => { |
331 | read_identifier(&mut chars, initial_len, callback); | 325 | read_identifier(&mut chars, initial_len, &mut callback); |
332 | if chars.clone().next() != Some('$') { | 326 | if chars.clone().next() != Some('$') { |
333 | continue; | 327 | continue; |
334 | } | 328 | } |
@@ -336,7 +330,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
336 | &mut chars, | 330 | &mut chars, |
337 | initial_len, | 331 | initial_len, |
338 | FormatSpecifier::DollarSign, | 332 | FormatSpecifier::DollarSign, |
339 | callback, | 333 | &mut callback, |
340 | ); | 334 | ); |
341 | } | 335 | } |
342 | _ => {} | 336 | _ => {} |
@@ -348,7 +342,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
348 | &mut chars, | 342 | &mut chars, |
349 | initial_len, | 343 | initial_len, |
350 | FormatSpecifier::Dot, | 344 | FormatSpecifier::Dot, |
351 | callback, | 345 | &mut callback, |
352 | ); | 346 | ); |
353 | 347 | ||
354 | match chars.clone().next().unwrap_or_default() { | 348 | match chars.clone().next().unwrap_or_default() { |
@@ -357,22 +351,22 @@ pub trait HasFormatSpecifier: AstToken { | |||
357 | &mut chars, | 351 | &mut chars, |
358 | initial_len, | 352 | initial_len, |
359 | FormatSpecifier::Asterisk, | 353 | FormatSpecifier::Asterisk, |
360 | callback, | 354 | &mut callback, |
361 | ); | 355 | ); |
362 | } | 356 | } |
363 | '0'..='9' => { | 357 | '0'..='9' => { |
364 | read_integer(&mut chars, initial_len, callback); | 358 | read_integer(&mut chars, initial_len, &mut callback); |
365 | if chars.clone().next() == Some('$') { | 359 | if chars.clone().next() == Some('$') { |
366 | skip_char_and_emit( | 360 | skip_char_and_emit( |
367 | &mut chars, | 361 | &mut chars, |
368 | initial_len, | 362 | initial_len, |
369 | FormatSpecifier::DollarSign, | 363 | FormatSpecifier::DollarSign, |
370 | callback, | 364 | &mut callback, |
371 | ); | 365 | ); |
372 | } | 366 | } |
373 | } | 367 | } |
374 | 'a'..='z' | 'A'..='Z' | '_' => { | 368 | 'a'..='z' | 'A'..='Z' | '_' => { |
375 | read_identifier(&mut chars, initial_len, callback); | 369 | read_identifier(&mut chars, initial_len, &mut callback); |
376 | if chars.clone().next() != Some('$') { | 370 | if chars.clone().next() != Some('$') { |
377 | continue; | 371 | continue; |
378 | } | 372 | } |
@@ -380,7 +374,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
380 | &mut chars, | 374 | &mut chars, |
381 | initial_len, | 375 | initial_len, |
382 | FormatSpecifier::DollarSign, | 376 | FormatSpecifier::DollarSign, |
383 | callback, | 377 | &mut callback, |
384 | ); | 378 | ); |
385 | } | 379 | } |
386 | _ => { | 380 | _ => { |
@@ -396,11 +390,11 @@ pub trait HasFormatSpecifier: AstToken { | |||
396 | &mut chars, | 390 | &mut chars, |
397 | initial_len, | 391 | initial_len, |
398 | FormatSpecifier::QuestionMark, | 392 | FormatSpecifier::QuestionMark, |
399 | callback, | 393 | &mut callback, |
400 | ); | 394 | ); |
401 | } | 395 | } |
402 | 'a'..='z' | 'A'..='Z' | '_' => { | 396 | 'a'..='z' | 'A'..='Z' | '_' => { |
403 | read_identifier(&mut chars, initial_len, callback); | 397 | read_identifier(&mut chars, initial_len, &mut callback); |
404 | } | 398 | } |
405 | _ => {} | 399 | _ => {} |
406 | } | 400 | } |
@@ -416,7 +410,12 @@ pub trait HasFormatSpecifier: AstToken { | |||
416 | // Escaped format end specifier, `}}` | 410 | // Escaped format end specifier, `}}` |
417 | continue; | 411 | continue; |
418 | } | 412 | } |
419 | skip_char_and_emit(&mut chars, initial_len, FormatSpecifier::Close, callback); | 413 | skip_char_and_emit( |
414 | &mut chars, | ||
415 | initial_len, | ||
416 | FormatSpecifier::Close, | ||
417 | &mut callback, | ||
418 | ); | ||
420 | } | 419 | } |
421 | _ => { | 420 | _ => { |
422 | while let Some(next_char) = chars.clone().next() { | 421 | while let Some(next_char) = chars.clone().next() { |