diff options
author | Aleksey Kladov <[email protected]> | 2020-03-03 16:03:46 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-03-03 16:03:46 +0000 |
commit | cf0ececb7aa93d5538a7688d825201327335132e (patch) | |
tree | 605a9e4e9b3f9bde6f3b8229f7a01c4fb7735748 | |
parent | 1cca6b2a3d4e1981577616d854bca498f4891289 (diff) |
Highlight assist tests
-rw-r--r-- | crates/ra_assists/src/handlers/inline_local_variable.rs | 92 | ||||
-rw-r--r-- | crates/ra_assists/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 2 |
3 files changed, 53 insertions, 49 deletions
diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs index 98e5112df..eb5112343 100644 --- a/crates/ra_assists/src/handlers/inline_local_variable.rs +++ b/crates/ra_assists/src/handlers/inline_local_variable.rs | |||
@@ -126,7 +126,7 @@ mod tests { | |||
126 | fn test_inline_let_bind_literal_expr() { | 126 | fn test_inline_let_bind_literal_expr() { |
127 | check_assist( | 127 | check_assist( |
128 | inline_local_variable, | 128 | inline_local_variable, |
129 | " | 129 | r" |
130 | fn bar(a: usize) {} | 130 | fn bar(a: usize) {} |
131 | fn foo() { | 131 | fn foo() { |
132 | let a<|> = 1; | 132 | let a<|> = 1; |
@@ -140,7 +140,7 @@ fn foo() { | |||
140 | let b = a * 10; | 140 | let b = a * 10; |
141 | bar(a); | 141 | bar(a); |
142 | }", | 142 | }", |
143 | " | 143 | r" |
144 | fn bar(a: usize) {} | 144 | fn bar(a: usize) {} |
145 | fn foo() { | 145 | fn foo() { |
146 | <|>1 + 1; | 146 | <|>1 + 1; |
@@ -160,7 +160,7 @@ fn foo() { | |||
160 | fn test_inline_let_bind_bin_expr() { | 160 | fn test_inline_let_bind_bin_expr() { |
161 | check_assist( | 161 | check_assist( |
162 | inline_local_variable, | 162 | inline_local_variable, |
163 | " | 163 | r" |
164 | fn bar(a: usize) {} | 164 | fn bar(a: usize) {} |
165 | fn foo() { | 165 | fn foo() { |
166 | let a<|> = 1 + 1; | 166 | let a<|> = 1 + 1; |
@@ -174,7 +174,7 @@ fn foo() { | |||
174 | let b = a * 10; | 174 | let b = a * 10; |
175 | bar(a); | 175 | bar(a); |
176 | }", | 176 | }", |
177 | " | 177 | r" |
178 | fn bar(a: usize) {} | 178 | fn bar(a: usize) {} |
179 | fn foo() { | 179 | fn foo() { |
180 | <|>(1 + 1) + 1; | 180 | <|>(1 + 1) + 1; |
@@ -194,7 +194,7 @@ fn foo() { | |||
194 | fn test_inline_let_bind_function_call_expr() { | 194 | fn test_inline_let_bind_function_call_expr() { |
195 | check_assist( | 195 | check_assist( |
196 | inline_local_variable, | 196 | inline_local_variable, |
197 | " | 197 | r" |
198 | fn bar(a: usize) {} | 198 | fn bar(a: usize) {} |
199 | fn foo() { | 199 | fn foo() { |
200 | let a<|> = bar(1); | 200 | let a<|> = bar(1); |
@@ -208,7 +208,7 @@ fn foo() { | |||
208 | let b = a * 10; | 208 | let b = a * 10; |
209 | bar(a); | 209 | bar(a); |
210 | }", | 210 | }", |
211 | " | 211 | r" |
212 | fn bar(a: usize) {} | 212 | fn bar(a: usize) {} |
213 | fn foo() { | 213 | fn foo() { |
214 | <|>bar(1) + 1; | 214 | <|>bar(1) + 1; |
@@ -228,7 +228,7 @@ fn foo() { | |||
228 | fn test_inline_let_bind_cast_expr() { | 228 | fn test_inline_let_bind_cast_expr() { |
229 | check_assist( | 229 | check_assist( |
230 | inline_local_variable, | 230 | inline_local_variable, |
231 | " | 231 | r" |
232 | fn bar(a: usize): usize { a } | 232 | fn bar(a: usize): usize { a } |
233 | fn foo() { | 233 | fn foo() { |
234 | let a<|> = bar(1) as u64; | 234 | let a<|> = bar(1) as u64; |
@@ -242,7 +242,7 @@ fn foo() { | |||
242 | let b = a * 10; | 242 | let b = a * 10; |
243 | bar(a); | 243 | bar(a); |
244 | }", | 244 | }", |
245 | " | 245 | r" |
246 | fn bar(a: usize): usize { a } | 246 | fn bar(a: usize): usize { a } |
247 | fn foo() { | 247 | fn foo() { |
248 | <|>(bar(1) as u64) + 1; | 248 | <|>(bar(1) as u64) + 1; |
@@ -262,7 +262,7 @@ fn foo() { | |||
262 | fn test_inline_let_bind_block_expr() { | 262 | fn test_inline_let_bind_block_expr() { |
263 | check_assist( | 263 | check_assist( |
264 | inline_local_variable, | 264 | inline_local_variable, |
265 | " | 265 | r" |
266 | fn foo() { | 266 | fn foo() { |
267 | let a<|> = { 10 + 1 }; | 267 | let a<|> = { 10 + 1 }; |
268 | a + 1; | 268 | a + 1; |
@@ -275,7 +275,7 @@ fn foo() { | |||
275 | let b = a * 10; | 275 | let b = a * 10; |
276 | bar(a); | 276 | bar(a); |
277 | }", | 277 | }", |
278 | " | 278 | r" |
279 | fn foo() { | 279 | fn foo() { |
280 | <|>{ 10 + 1 } + 1; | 280 | <|>{ 10 + 1 } + 1; |
281 | if { 10 + 1 } > 10 { | 281 | if { 10 + 1 } > 10 { |
@@ -294,7 +294,7 @@ fn foo() { | |||
294 | fn test_inline_let_bind_paren_expr() { | 294 | fn test_inline_let_bind_paren_expr() { |
295 | check_assist( | 295 | check_assist( |
296 | inline_local_variable, | 296 | inline_local_variable, |
297 | " | 297 | r" |
298 | fn foo() { | 298 | fn foo() { |
299 | let a<|> = ( 10 + 1 ); | 299 | let a<|> = ( 10 + 1 ); |
300 | a + 1; | 300 | a + 1; |
@@ -307,7 +307,7 @@ fn foo() { | |||
307 | let b = a * 10; | 307 | let b = a * 10; |
308 | bar(a); | 308 | bar(a); |
309 | }", | 309 | }", |
310 | " | 310 | r" |
311 | fn foo() { | 311 | fn foo() { |
312 | <|>( 10 + 1 ) + 1; | 312 | <|>( 10 + 1 ) + 1; |
313 | if ( 10 + 1 ) > 10 { | 313 | if ( 10 + 1 ) > 10 { |
@@ -339,13 +339,13 @@ fn foo() { | |||
339 | fn test_call_expr() { | 339 | fn test_call_expr() { |
340 | check_assist( | 340 | check_assist( |
341 | inline_local_variable, | 341 | inline_local_variable, |
342 | " | 342 | r" |
343 | fn foo() { | 343 | fn foo() { |
344 | let a<|> = bar(10 + 1); | 344 | let a<|> = bar(10 + 1); |
345 | let b = a * 10; | 345 | let b = a * 10; |
346 | let c = a as usize; | 346 | let c = a as usize; |
347 | }", | 347 | }", |
348 | " | 348 | r" |
349 | fn foo() { | 349 | fn foo() { |
350 | <|>let b = bar(10 + 1) * 10; | 350 | <|>let b = bar(10 + 1) * 10; |
351 | let c = bar(10 + 1) as usize; | 351 | let c = bar(10 + 1) as usize; |
@@ -357,14 +357,14 @@ fn foo() { | |||
357 | fn test_index_expr() { | 357 | fn test_index_expr() { |
358 | check_assist( | 358 | check_assist( |
359 | inline_local_variable, | 359 | inline_local_variable, |
360 | " | 360 | r" |
361 | fn foo() { | 361 | fn foo() { |
362 | let x = vec![1, 2, 3]; | 362 | let x = vec![1, 2, 3]; |
363 | let a<|> = x[0]; | 363 | let a<|> = x[0]; |
364 | let b = a * 10; | 364 | let b = a * 10; |
365 | let c = a as usize; | 365 | let c = a as usize; |
366 | }", | 366 | }", |
367 | " | 367 | r" |
368 | fn foo() { | 368 | fn foo() { |
369 | let x = vec![1, 2, 3]; | 369 | let x = vec![1, 2, 3]; |
370 | <|>let b = x[0] * 10; | 370 | <|>let b = x[0] * 10; |
@@ -377,14 +377,14 @@ fn foo() { | |||
377 | fn test_method_call_expr() { | 377 | fn test_method_call_expr() { |
378 | check_assist( | 378 | check_assist( |
379 | inline_local_variable, | 379 | inline_local_variable, |
380 | " | 380 | r" |
381 | fn foo() { | 381 | fn foo() { |
382 | let bar = vec![1]; | 382 | let bar = vec![1]; |
383 | let a<|> = bar.len(); | 383 | let a<|> = bar.len(); |
384 | let b = a * 10; | 384 | let b = a * 10; |
385 | let c = a as usize; | 385 | let c = a as usize; |
386 | }", | 386 | }", |
387 | " | 387 | r" |
388 | fn foo() { | 388 | fn foo() { |
389 | let bar = vec![1]; | 389 | let bar = vec![1]; |
390 | <|>let b = bar.len() * 10; | 390 | <|>let b = bar.len() * 10; |
@@ -397,7 +397,7 @@ fn foo() { | |||
397 | fn test_field_expr() { | 397 | fn test_field_expr() { |
398 | check_assist( | 398 | check_assist( |
399 | inline_local_variable, | 399 | inline_local_variable, |
400 | " | 400 | r" |
401 | struct Bar { | 401 | struct Bar { |
402 | foo: usize | 402 | foo: usize |
403 | } | 403 | } |
@@ -408,7 +408,7 @@ fn foo() { | |||
408 | let b = a * 10; | 408 | let b = a * 10; |
409 | let c = a as usize; | 409 | let c = a as usize; |
410 | }", | 410 | }", |
411 | " | 411 | r" |
412 | struct Bar { | 412 | struct Bar { |
413 | foo: usize | 413 | foo: usize |
414 | } | 414 | } |
@@ -425,7 +425,7 @@ fn foo() { | |||
425 | fn test_try_expr() { | 425 | fn test_try_expr() { |
426 | check_assist( | 426 | check_assist( |
427 | inline_local_variable, | 427 | inline_local_variable, |
428 | " | 428 | r" |
429 | fn foo() -> Option<usize> { | 429 | fn foo() -> Option<usize> { |
430 | let bar = Some(1); | 430 | let bar = Some(1); |
431 | let a<|> = bar?; | 431 | let a<|> = bar?; |
@@ -433,7 +433,7 @@ fn foo() -> Option<usize> { | |||
433 | let c = a as usize; | 433 | let c = a as usize; |
434 | None | 434 | None |
435 | }", | 435 | }", |
436 | " | 436 | r" |
437 | fn foo() -> Option<usize> { | 437 | fn foo() -> Option<usize> { |
438 | let bar = Some(1); | 438 | let bar = Some(1); |
439 | <|>let b = bar? * 10; | 439 | <|>let b = bar? * 10; |
@@ -447,13 +447,13 @@ fn foo() -> Option<usize> { | |||
447 | fn test_ref_expr() { | 447 | fn test_ref_expr() { |
448 | check_assist( | 448 | check_assist( |
449 | inline_local_variable, | 449 | inline_local_variable, |
450 | " | 450 | r" |
451 | fn foo() { | 451 | fn foo() { |
452 | let bar = 10; | 452 | let bar = 10; |
453 | let a<|> = &bar; | 453 | let a<|> = &bar; |
454 | let b = a * 10; | 454 | let b = a * 10; |
455 | }", | 455 | }", |
456 | " | 456 | r" |
457 | fn foo() { | 457 | fn foo() { |
458 | let bar = 10; | 458 | let bar = 10; |
459 | <|>let b = &bar * 10; | 459 | <|>let b = &bar * 10; |
@@ -465,12 +465,12 @@ fn foo() { | |||
465 | fn test_tuple_expr() { | 465 | fn test_tuple_expr() { |
466 | check_assist( | 466 | check_assist( |
467 | inline_local_variable, | 467 | inline_local_variable, |
468 | " | 468 | r" |
469 | fn foo() { | 469 | fn foo() { |
470 | let a<|> = (10, 20); | 470 | let a<|> = (10, 20); |
471 | let b = a[0]; | 471 | let b = a[0]; |
472 | }", | 472 | }", |
473 | " | 473 | r" |
474 | fn foo() { | 474 | fn foo() { |
475 | <|>let b = (10, 20)[0]; | 475 | <|>let b = (10, 20)[0]; |
476 | }", | 476 | }", |
@@ -481,12 +481,12 @@ fn foo() { | |||
481 | fn test_array_expr() { | 481 | fn test_array_expr() { |
482 | check_assist( | 482 | check_assist( |
483 | inline_local_variable, | 483 | inline_local_variable, |
484 | " | 484 | r" |
485 | fn foo() { | 485 | fn foo() { |
486 | let a<|> = [1, 2, 3]; | 486 | let a<|> = [1, 2, 3]; |
487 | let b = a.len(); | 487 | let b = a.len(); |
488 | }", | 488 | }", |
489 | " | 489 | r" |
490 | fn foo() { | 490 | fn foo() { |
491 | <|>let b = [1, 2, 3].len(); | 491 | <|>let b = [1, 2, 3].len(); |
492 | }", | 492 | }", |
@@ -497,13 +497,13 @@ fn foo() { | |||
497 | fn test_paren() { | 497 | fn test_paren() { |
498 | check_assist( | 498 | check_assist( |
499 | inline_local_variable, | 499 | inline_local_variable, |
500 | " | 500 | r" |
501 | fn foo() { | 501 | fn foo() { |
502 | let a<|> = (10 + 20); | 502 | let a<|> = (10 + 20); |
503 | let b = a * 10; | 503 | let b = a * 10; |
504 | let c = a as usize; | 504 | let c = a as usize; |
505 | }", | 505 | }", |
506 | " | 506 | r" |
507 | fn foo() { | 507 | fn foo() { |
508 | <|>let b = (10 + 20) * 10; | 508 | <|>let b = (10 + 20) * 10; |
509 | let c = (10 + 20) as usize; | 509 | let c = (10 + 20) as usize; |
@@ -515,14 +515,14 @@ fn foo() { | |||
515 | fn test_path_expr() { | 515 | fn test_path_expr() { |
516 | check_assist( | 516 | check_assist( |
517 | inline_local_variable, | 517 | inline_local_variable, |
518 | " | 518 | r" |
519 | fn foo() { | 519 | fn foo() { |
520 | let d = 10; | 520 | let d = 10; |
521 | let a<|> = d; | 521 | let a<|> = d; |
522 | let b = a * 10; | 522 | let b = a * 10; |
523 | let c = a as usize; | 523 | let c = a as usize; |
524 | }", | 524 | }", |
525 | " | 525 | r" |
526 | fn foo() { | 526 | fn foo() { |
527 | let d = 10; | 527 | let d = 10; |
528 | <|>let b = d * 10; | 528 | <|>let b = d * 10; |
@@ -535,13 +535,13 @@ fn foo() { | |||
535 | fn test_block_expr() { | 535 | fn test_block_expr() { |
536 | check_assist( | 536 | check_assist( |
537 | inline_local_variable, | 537 | inline_local_variable, |
538 | " | 538 | r" |
539 | fn foo() { | 539 | fn foo() { |
540 | let a<|> = { 10 }; | 540 | let a<|> = { 10 }; |
541 | let b = a * 10; | 541 | let b = a * 10; |
542 | let c = a as usize; | 542 | let c = a as usize; |
543 | }", | 543 | }", |
544 | " | 544 | r" |
545 | fn foo() { | 545 | fn foo() { |
546 | <|>let b = { 10 } * 10; | 546 | <|>let b = { 10 } * 10; |
547 | let c = { 10 } as usize; | 547 | let c = { 10 } as usize; |
@@ -553,7 +553,7 @@ fn foo() { | |||
553 | fn test_used_in_different_expr1() { | 553 | fn test_used_in_different_expr1() { |
554 | check_assist( | 554 | check_assist( |
555 | inline_local_variable, | 555 | inline_local_variable, |
556 | " | 556 | r" |
557 | fn foo() { | 557 | fn foo() { |
558 | let a<|> = 10 + 20; | 558 | let a<|> = 10 + 20; |
559 | let b = a * 10; | 559 | let b = a * 10; |
@@ -561,7 +561,7 @@ fn foo() { | |||
561 | let d = [a, 10]; | 561 | let d = [a, 10]; |
562 | let e = (a); | 562 | let e = (a); |
563 | }", | 563 | }", |
564 | " | 564 | r" |
565 | fn foo() { | 565 | fn foo() { |
566 | <|>let b = (10 + 20) * 10; | 566 | <|>let b = (10 + 20) * 10; |
567 | let c = (10 + 20, 20); | 567 | let c = (10 + 20, 20); |
@@ -575,12 +575,12 @@ fn foo() { | |||
575 | fn test_used_in_for_expr() { | 575 | fn test_used_in_for_expr() { |
576 | check_assist( | 576 | check_assist( |
577 | inline_local_variable, | 577 | inline_local_variable, |
578 | " | 578 | r" |
579 | fn foo() { | 579 | fn foo() { |
580 | let a<|> = vec![10, 20]; | 580 | let a<|> = vec![10, 20]; |
581 | for i in a {} | 581 | for i in a {} |
582 | }", | 582 | }", |
583 | " | 583 | r" |
584 | fn foo() { | 584 | fn foo() { |
585 | <|>for i in vec![10, 20] {} | 585 | <|>for i in vec![10, 20] {} |
586 | }", | 586 | }", |
@@ -591,12 +591,12 @@ fn foo() { | |||
591 | fn test_used_in_while_expr() { | 591 | fn test_used_in_while_expr() { |
592 | check_assist( | 592 | check_assist( |
593 | inline_local_variable, | 593 | inline_local_variable, |
594 | " | 594 | r" |
595 | fn foo() { | 595 | fn foo() { |
596 | let a<|> = 1 > 0; | 596 | let a<|> = 1 > 0; |
597 | while a {} | 597 | while a {} |
598 | }", | 598 | }", |
599 | " | 599 | r" |
600 | fn foo() { | 600 | fn foo() { |
601 | <|>while 1 > 0 {} | 601 | <|>while 1 > 0 {} |
602 | }", | 602 | }", |
@@ -607,14 +607,14 @@ fn foo() { | |||
607 | fn test_used_in_break_expr() { | 607 | fn test_used_in_break_expr() { |
608 | check_assist( | 608 | check_assist( |
609 | inline_local_variable, | 609 | inline_local_variable, |
610 | " | 610 | r" |
611 | fn foo() { | 611 | fn foo() { |
612 | let a<|> = 1 + 1; | 612 | let a<|> = 1 + 1; |
613 | loop { | 613 | loop { |
614 | break a; | 614 | break a; |
615 | } | 615 | } |
616 | }", | 616 | }", |
617 | " | 617 | r" |
618 | fn foo() { | 618 | fn foo() { |
619 | <|>loop { | 619 | <|>loop { |
620 | break 1 + 1; | 620 | break 1 + 1; |
@@ -627,12 +627,12 @@ fn foo() { | |||
627 | fn test_used_in_return_expr() { | 627 | fn test_used_in_return_expr() { |
628 | check_assist( | 628 | check_assist( |
629 | inline_local_variable, | 629 | inline_local_variable, |
630 | " | 630 | r" |
631 | fn foo() { | 631 | fn foo() { |
632 | let a<|> = 1 > 0; | 632 | let a<|> = 1 > 0; |
633 | return a; | 633 | return a; |
634 | }", | 634 | }", |
635 | " | 635 | r" |
636 | fn foo() { | 636 | fn foo() { |
637 | <|>return 1 > 0; | 637 | <|>return 1 > 0; |
638 | }", | 638 | }", |
@@ -643,12 +643,12 @@ fn foo() { | |||
643 | fn test_used_in_match_expr() { | 643 | fn test_used_in_match_expr() { |
644 | check_assist( | 644 | check_assist( |
645 | inline_local_variable, | 645 | inline_local_variable, |
646 | " | 646 | r" |
647 | fn foo() { | 647 | fn foo() { |
648 | let a<|> = 1 > 0; | 648 | let a<|> = 1 > 0; |
649 | match a {} | 649 | match a {} |
650 | }", | 650 | }", |
651 | " | 651 | r" |
652 | fn foo() { | 652 | fn foo() { |
653 | <|>match 1 > 0 {} | 653 | <|>match 1 > 0 {} |
654 | }", | 654 | }", |
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 6d81a6396..50a15f978 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs | |||
@@ -178,8 +178,12 @@ mod helpers { | |||
178 | (db, file_id) | 178 | (db, file_id) |
179 | } | 179 | } |
180 | 180 | ||
181 | pub(crate) fn check_assist(assist: AssistHandler, ra_fixture: &str, after: &str) { | 181 | pub(crate) fn check_assist( |
182 | check(assist, ra_fixture, ExpectedResult::After(after)); | 182 | assist: AssistHandler, |
183 | ra_fixture_before: &str, | ||
184 | ra_fixture_after: &str, | ||
185 | ) { | ||
186 | check(assist, ra_fixture_before, ExpectedResult::After(ra_fixture_after)); | ||
183 | } | 187 | } |
184 | 188 | ||
185 | // FIXME: instead of having a separate function here, maybe use | 189 | // FIXME: instead of having a separate function here, maybe use |
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 979a3f7a0..7e41db530 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -320,7 +320,7 @@ fn highlight_injection( | |||
320 | let call_info = call_info_for_token(&sema, expanded)?; | 320 | let call_info = call_info_for_token(&sema, expanded)?; |
321 | let idx = call_info.active_parameter?; | 321 | let idx = call_info.active_parameter?; |
322 | let name = call_info.signature.parameter_names.get(idx)?; | 322 | let name = call_info.signature.parameter_names.get(idx)?; |
323 | if name != "ra_fixture" { | 323 | if !name.starts_with("ra_fixture") { |
324 | return None; | 324 | return None; |
325 | } | 325 | } |
326 | let value = literal.value()?; | 326 | let value = literal.value()?; |