diff options
author | Aleksey Kladov <[email protected]> | 2020-06-24 10:05:47 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-06-24 10:05:47 +0100 |
commit | e9cb818c2683e06153f013c3b8d03f7f2719eb02 (patch) | |
tree | 1eab8c2aaa60acc56d69e88d2eb888c1395fdbc2 /crates/ra_ide | |
parent | 08e2149eab4495bd816a30b3caf586bef2cd9649 (diff) |
Use fixtures more
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/diagnostics.rs | 40 | ||||
-rw-r--r-- | crates/ra_ide/src/extend_selection.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 178 | ||||
-rw-r--r-- | crates/ra_ide/src/mock_analysis.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tests.rs | 13 | ||||
-rw-r--r-- | crates/ra_ide/src/typing/on_enter.rs | 13 |
6 files changed, 135 insertions, 133 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 8cb0700b9..8a18bc18c 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs | |||
@@ -348,8 +348,10 @@ mod tests { | |||
348 | ); | 348 | ); |
349 | } | 349 | } |
350 | 350 | ||
351 | fn check_apply_diagnostic_fix(before: &str, after: &str) { | 351 | fn check_apply_diagnostic_fix(ra_fixture_before: &str, ra_fixture_after: &str) { |
352 | let (analysis, file_id) = single_file(before); | 352 | let ra_fixture_after = &trim_indent(ra_fixture_after); |
353 | let (analysis, file_id) = single_file(ra_fixture_before); | ||
354 | let before = analysis.file_text(file_id).unwrap(); | ||
353 | let diagnostic = analysis.diagnostics(file_id).unwrap().pop().unwrap(); | 355 | let diagnostic = analysis.diagnostics(file_id).unwrap().pop().unwrap(); |
354 | let mut fix = diagnostic.fix.unwrap(); | 356 | let mut fix = diagnostic.fix.unwrap(); |
355 | let edit = fix.source_change.source_file_edits.pop().unwrap().edit; | 357 | let edit = fix.source_change.source_file_edits.pop().unwrap().edit; |
@@ -358,7 +360,7 @@ mod tests { | |||
358 | edit.apply(&mut actual); | 360 | edit.apply(&mut actual); |
359 | actual | 361 | actual |
360 | }; | 362 | }; |
361 | assert_eq_text!(after, &actual); | 363 | assert_eq_text!(ra_fixture_after, &actual); |
362 | } | 364 | } |
363 | 365 | ||
364 | /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics | 366 | /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics |
@@ -709,7 +711,7 @@ mod tests { | |||
709 | [ | 711 | [ |
710 | Diagnostic { | 712 | Diagnostic { |
711 | message: "Missing structure fields:\n- b\n", | 713 | message: "Missing structure fields:\n- b\n", |
712 | range: 224..233, | 714 | range: 127..136, |
713 | severity: Error, | 715 | severity: Error, |
714 | fix: Some( | 716 | fix: Some( |
715 | Fix { | 717 | Fix { |
@@ -855,22 +857,22 @@ fn main() { | |||
855 | fn test_add_field_from_usage() { | 857 | fn test_add_field_from_usage() { |
856 | check_apply_diagnostic_fix( | 858 | check_apply_diagnostic_fix( |
857 | r" | 859 | r" |
858 | fn main() { | 860 | fn main() { |
859 | Foo { bar: 3, baz: false}; | 861 | Foo { bar: 3, baz: false}; |
860 | } | 862 | } |
861 | struct Foo { | 863 | struct Foo { |
862 | bar: i32 | 864 | bar: i32 |
863 | } | 865 | } |
864 | ", | 866 | ", |
865 | r" | 867 | r" |
866 | fn main() { | 868 | fn main() { |
867 | Foo { bar: 3, baz: false}; | 869 | Foo { bar: 3, baz: false}; |
868 | } | 870 | } |
869 | struct Foo { | 871 | struct Foo { |
870 | bar: i32, | 872 | bar: i32, |
871 | baz: bool | 873 | baz: bool |
872 | } | 874 | } |
873 | ", | 875 | ", |
874 | ) | 876 | ) |
875 | } | 877 | } |
876 | } | 878 | } |
diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index a4bc93cdb..cb6b1a40d 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs | |||
@@ -315,17 +315,15 @@ fn adj_comments(comment: &ast::Comment, dir: Direction) -> ast::Comment { | |||
315 | 315 | ||
316 | #[cfg(test)] | 316 | #[cfg(test)] |
317 | mod tests { | 317 | mod tests { |
318 | use test_utils::extract_offset; | 318 | use crate::mock_analysis::single_file_with_position; |
319 | |||
320 | use crate::mock_analysis::single_file; | ||
321 | 319 | ||
322 | use super::*; | 320 | use super::*; |
323 | 321 | ||
324 | fn do_check(before: &str, afters: &[&str]) { | 322 | fn do_check(before: &str, afters: &[&str]) { |
325 | let (cursor, before) = extract_offset(before); | 323 | let (analysis, position) = single_file_with_position(&before); |
326 | let (analysis, file_id) = single_file(&before); | 324 | let before = analysis.file_text(position.file_id).unwrap(); |
327 | let range = TextRange::empty(cursor); | 325 | let range = TextRange::empty(position.offset); |
328 | let mut frange = FileRange { file_id, range }; | 326 | let mut frange = FileRange { file_id: position.file_id, range }; |
329 | 327 | ||
330 | for &after in afters { | 328 | for &after in afters { |
331 | frange.range = analysis.extend_selection(frange).unwrap(); | 329 | frange.range = analysis.extend_selection(frange).unwrap(); |
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 7eb2cef73..3fd08b1e8 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -363,16 +363,17 @@ mod tests { | |||
363 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: true, type_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" | 363 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: true, type_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" |
364 | [ | 364 | [ |
365 | InlayHint { | 365 | InlayHint { |
366 | range: 106..107, | 366 | range: 69..70, |
367 | kind: ParameterHint, | 367 | kind: ParameterHint, |
368 | label: "a", | 368 | label: "a", |
369 | }, | 369 | }, |
370 | InlayHint { | 370 | InlayHint { |
371 | range: 109..110, | 371 | range: 72..73, |
372 | kind: ParameterHint, | 372 | kind: ParameterHint, |
373 | label: "b", | 373 | label: "b", |
374 | }, | 374 | }, |
375 | ]"###); | 375 | ] |
376 | "###); | ||
376 | } | 377 | } |
377 | 378 | ||
378 | #[test] | 379 | #[test] |
@@ -399,11 +400,12 @@ mod tests { | |||
399 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ type_hints: true, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" | 400 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ type_hints: true, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" |
400 | [ | 401 | [ |
401 | InlayHint { | 402 | InlayHint { |
402 | range: 97..99, | 403 | range: 60..62, |
403 | kind: TypeHint, | 404 | kind: TypeHint, |
404 | label: "i32", | 405 | label: "i32", |
405 | }, | 406 | }, |
406 | ]"###); | 407 | ] |
408 | "###); | ||
407 | } | 409 | } |
408 | #[test] | 410 | #[test] |
409 | fn default_generic_types_should_not_be_displayed() { | 411 | fn default_generic_types_should_not_be_displayed() { |
@@ -423,12 +425,12 @@ fn main() { | |||
423 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" | 425 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
424 | [ | 426 | [ |
425 | InlayHint { | 427 | InlayHint { |
426 | range: 69..71, | 428 | range: 68..70, |
427 | kind: TypeHint, | 429 | kind: TypeHint, |
428 | label: "Test<i32>", | 430 | label: "Test<i32>", |
429 | }, | 431 | }, |
430 | InlayHint { | 432 | InlayHint { |
431 | range: 107..113, | 433 | range: 106..112, |
432 | kind: TypeHint, | 434 | kind: TypeHint, |
433 | label: "&Test<i32>", | 435 | label: "&Test<i32>", |
434 | }, | 436 | }, |
@@ -480,57 +482,57 @@ fn main() { | |||
480 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" | 482 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
481 | [ | 483 | [ |
482 | InlayHint { | 484 | InlayHint { |
483 | range: 193..197, | 485 | range: 192..196, |
484 | kind: TypeHint, | 486 | kind: TypeHint, |
485 | label: "i32", | 487 | label: "i32", |
486 | }, | 488 | }, |
487 | InlayHint { | 489 | InlayHint { |
488 | range: 236..244, | 490 | range: 235..243, |
489 | kind: TypeHint, | 491 | kind: TypeHint, |
490 | label: "i32", | 492 | label: "i32", |
491 | }, | 493 | }, |
492 | InlayHint { | 494 | InlayHint { |
493 | range: 275..279, | 495 | range: 274..278, |
494 | kind: TypeHint, | 496 | kind: TypeHint, |
495 | label: "&str", | 497 | label: "&str", |
496 | }, | 498 | }, |
497 | InlayHint { | 499 | InlayHint { |
498 | range: 539..543, | 500 | range: 538..542, |
499 | kind: TypeHint, | 501 | kind: TypeHint, |
500 | label: "(i32, char)", | 502 | label: "(i32, char)", |
501 | }, | 503 | }, |
502 | InlayHint { | 504 | InlayHint { |
503 | range: 566..567, | 505 | range: 565..566, |
504 | kind: TypeHint, | 506 | kind: TypeHint, |
505 | label: "i32", | 507 | label: "i32", |
506 | }, | 508 | }, |
507 | InlayHint { | 509 | InlayHint { |
508 | range: 570..571, | 510 | range: 569..570, |
509 | kind: TypeHint, | 511 | kind: TypeHint, |
510 | label: "i32", | 512 | label: "i32", |
511 | }, | 513 | }, |
512 | InlayHint { | 514 | InlayHint { |
513 | range: 573..574, | 515 | range: 572..573, |
514 | kind: TypeHint, | 516 | kind: TypeHint, |
515 | label: "i32", | 517 | label: "i32", |
516 | }, | 518 | }, |
517 | InlayHint { | 519 | InlayHint { |
518 | range: 577..578, | 520 | range: 576..577, |
519 | kind: TypeHint, | 521 | kind: TypeHint, |
520 | label: "f64", | 522 | label: "f64", |
521 | }, | 523 | }, |
522 | InlayHint { | 524 | InlayHint { |
523 | range: 580..581, | 525 | range: 579..580, |
524 | kind: TypeHint, | 526 | kind: TypeHint, |
525 | label: "f64", | 527 | label: "f64", |
526 | }, | 528 | }, |
527 | InlayHint { | 529 | InlayHint { |
528 | range: 584..585, | 530 | range: 583..584, |
529 | kind: TypeHint, | 531 | kind: TypeHint, |
530 | label: "i32", | 532 | label: "i32", |
531 | }, | 533 | }, |
532 | InlayHint { | 534 | InlayHint { |
533 | range: 627..628, | 535 | range: 626..627, |
534 | kind: TypeHint, | 536 | kind: TypeHint, |
535 | label: "i32", | 537 | label: "i32", |
536 | }, | 538 | }, |
@@ -560,47 +562,47 @@ fn main() { | |||
560 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" | 562 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
561 | [ | 563 | [ |
562 | InlayHint { | 564 | InlayHint { |
563 | range: 21..30, | 565 | range: 20..29, |
564 | kind: TypeHint, | 566 | kind: TypeHint, |
565 | label: "i32", | 567 | label: "i32", |
566 | }, | 568 | }, |
567 | InlayHint { | 569 | InlayHint { |
568 | range: 57..66, | 570 | range: 56..65, |
569 | kind: TypeHint, | 571 | kind: TypeHint, |
570 | label: "i32", | 572 | label: "i32", |
571 | }, | 573 | }, |
572 | InlayHint { | 574 | InlayHint { |
573 | range: 115..123, | 575 | range: 114..122, |
574 | kind: TypeHint, | 576 | kind: TypeHint, |
575 | label: "|…| -> i32", | 577 | label: "|…| -> i32", |
576 | }, | 578 | }, |
577 | InlayHint { | 579 | InlayHint { |
578 | range: 127..128, | 580 | range: 126..127, |
579 | kind: TypeHint, | 581 | kind: TypeHint, |
580 | label: "i32", | 582 | label: "i32", |
581 | }, | 583 | }, |
582 | InlayHint { | 584 | InlayHint { |
583 | range: 130..131, | 585 | range: 129..130, |
584 | kind: TypeHint, | 586 | kind: TypeHint, |
585 | label: "i32", | 587 | label: "i32", |
586 | }, | 588 | }, |
587 | InlayHint { | 589 | InlayHint { |
588 | range: 133..134, | 590 | range: 132..133, |
589 | kind: TypeHint, | 591 | kind: TypeHint, |
590 | label: "i32", | 592 | label: "i32", |
591 | }, | 593 | }, |
592 | InlayHint { | 594 | InlayHint { |
593 | range: 136..137, | 595 | range: 135..136, |
594 | kind: TypeHint, | 596 | kind: TypeHint, |
595 | label: "i32", | 597 | label: "i32", |
596 | }, | 598 | }, |
597 | InlayHint { | 599 | InlayHint { |
598 | range: 201..213, | 600 | range: 200..212, |
599 | kind: TypeHint, | 601 | kind: TypeHint, |
600 | label: "&|…| -> i32", | 602 | label: "&|…| -> i32", |
601 | }, | 603 | }, |
602 | InlayHint { | 604 | InlayHint { |
603 | range: 236..245, | 605 | range: 235..244, |
604 | kind: TypeHint, | 606 | kind: TypeHint, |
605 | label: "|| -> i32", | 607 | label: "|| -> i32", |
606 | }, | 608 | }, |
@@ -624,12 +626,12 @@ fn main() { | |||
624 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" | 626 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
625 | [ | 627 | [ |
626 | InlayHint { | 628 | InlayHint { |
627 | range: 21..30, | 629 | range: 20..29, |
628 | kind: TypeHint, | 630 | kind: TypeHint, |
629 | label: "i32", | 631 | label: "i32", |
630 | }, | 632 | }, |
631 | InlayHint { | 633 | InlayHint { |
632 | range: 44..53, | 634 | range: 43..52, |
633 | kind: TypeHint, | 635 | kind: TypeHint, |
634 | label: "i32", | 636 | label: "i32", |
635 | }, | 637 | }, |
@@ -674,57 +676,57 @@ fn main() { | |||
674 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" | 676 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
675 | [ | 677 | [ |
676 | InlayHint { | 678 | InlayHint { |
677 | range: 188..192, | 679 | range: 187..191, |
678 | kind: TypeHint, | 680 | kind: TypeHint, |
679 | label: "CustomOption<Test>", | 681 | label: "CustomOption<Test>", |
680 | }, | 682 | }, |
681 | InlayHint { | 683 | InlayHint { |
682 | range: 267..271, | 684 | range: 266..270, |
683 | kind: TypeHint, | 685 | kind: TypeHint, |
684 | label: "&CustomOption<Test>", | 686 | label: "&CustomOption<Test>", |
685 | }, | 687 | }, |
686 | InlayHint { | 688 | InlayHint { |
687 | range: 300..304, | 689 | range: 299..303, |
688 | kind: TypeHint, | 690 | kind: TypeHint, |
689 | label: "&Test", | 691 | label: "&Test", |
690 | }, | 692 | }, |
691 | InlayHint { | 693 | InlayHint { |
692 | range: 341..342, | 694 | range: 340..341, |
693 | kind: TypeHint, | 695 | kind: TypeHint, |
694 | label: "&CustomOption<u32>", | 696 | label: "&CustomOption<u32>", |
695 | }, | 697 | }, |
696 | InlayHint { | 698 | InlayHint { |
697 | range: 344..345, | 699 | range: 343..344, |
698 | kind: TypeHint, | 700 | kind: TypeHint, |
699 | label: "&u8", | 701 | label: "&u8", |
700 | }, | 702 | }, |
701 | InlayHint { | 703 | InlayHint { |
702 | range: 387..388, | 704 | range: 386..387, |
703 | kind: TypeHint, | 705 | kind: TypeHint, |
704 | label: "&CustomOption<u32>", | 706 | label: "&CustomOption<u32>", |
705 | }, | 707 | }, |
706 | InlayHint { | 708 | InlayHint { |
707 | range: 393..394, | 709 | range: 392..393, |
708 | kind: TypeHint, | 710 | kind: TypeHint, |
709 | label: "&u8", | 711 | label: "&u8", |
710 | }, | 712 | }, |
711 | InlayHint { | 713 | InlayHint { |
712 | range: 441..442, | 714 | range: 440..441, |
713 | kind: TypeHint, | 715 | kind: TypeHint, |
714 | label: "&u32", | 716 | label: "&u32", |
715 | }, | 717 | }, |
716 | InlayHint { | 718 | InlayHint { |
717 | range: 448..449, | 719 | range: 447..448, |
718 | kind: TypeHint, | 720 | kind: TypeHint, |
719 | label: "&u8", | 721 | label: "&u8", |
720 | }, | 722 | }, |
721 | InlayHint { | 723 | InlayHint { |
722 | range: 500..501, | 724 | range: 499..500, |
723 | kind: TypeHint, | 725 | kind: TypeHint, |
724 | label: "&u8", | 726 | label: "&u8", |
725 | }, | 727 | }, |
726 | InlayHint { | 728 | InlayHint { |
727 | range: 543..544, | 729 | range: 542..543, |
728 | kind: TypeHint, | 730 | kind: TypeHint, |
729 | label: "&u8", | 731 | label: "&u8", |
730 | }, | 732 | }, |
@@ -769,57 +771,57 @@ fn main() { | |||
769 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" | 771 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
770 | [ | 772 | [ |
771 | InlayHint { | 773 | InlayHint { |
772 | range: 188..192, | 774 | range: 187..191, |
773 | kind: TypeHint, | 775 | kind: TypeHint, |
774 | label: "CustomOption<Test>", | 776 | label: "CustomOption<Test>", |
775 | }, | 777 | }, |
776 | InlayHint { | 778 | InlayHint { |
777 | range: 273..277, | 779 | range: 272..276, |
778 | kind: TypeHint, | 780 | kind: TypeHint, |
779 | label: "&CustomOption<Test>", | 781 | label: "&CustomOption<Test>", |
780 | }, | 782 | }, |
781 | InlayHint { | 783 | InlayHint { |
782 | range: 309..313, | 784 | range: 308..312, |
783 | kind: TypeHint, | 785 | kind: TypeHint, |
784 | label: "&Test", | 786 | label: "&Test", |
785 | }, | 787 | }, |
786 | InlayHint { | 788 | InlayHint { |
787 | range: 353..354, | 789 | range: 352..353, |
788 | kind: TypeHint, | 790 | kind: TypeHint, |
789 | label: "&CustomOption<u32>", | 791 | label: "&CustomOption<u32>", |
790 | }, | 792 | }, |
791 | InlayHint { | 793 | InlayHint { |
792 | range: 356..357, | 794 | range: 355..356, |
793 | kind: TypeHint, | 795 | kind: TypeHint, |
794 | label: "&u8", | 796 | label: "&u8", |
795 | }, | 797 | }, |
796 | InlayHint { | 798 | InlayHint { |
797 | range: 402..403, | 799 | range: 401..402, |
798 | kind: TypeHint, | 800 | kind: TypeHint, |
799 | label: "&CustomOption<u32>", | 801 | label: "&CustomOption<u32>", |
800 | }, | 802 | }, |
801 | InlayHint { | 803 | InlayHint { |
802 | range: 408..409, | 804 | range: 407..408, |
803 | kind: TypeHint, | 805 | kind: TypeHint, |
804 | label: "&u8", | 806 | label: "&u8", |
805 | }, | 807 | }, |
806 | InlayHint { | 808 | InlayHint { |
807 | range: 459..460, | 809 | range: 458..459, |
808 | kind: TypeHint, | 810 | kind: TypeHint, |
809 | label: "&u32", | 811 | label: "&u32", |
810 | }, | 812 | }, |
811 | InlayHint { | 813 | InlayHint { |
812 | range: 466..467, | 814 | range: 465..466, |
813 | kind: TypeHint, | 815 | kind: TypeHint, |
814 | label: "&u8", | 816 | label: "&u8", |
815 | }, | 817 | }, |
816 | InlayHint { | 818 | InlayHint { |
817 | range: 521..522, | 819 | range: 520..521, |
818 | kind: TypeHint, | 820 | kind: TypeHint, |
819 | label: "&u8", | 821 | label: "&u8", |
820 | }, | 822 | }, |
821 | InlayHint { | 823 | InlayHint { |
822 | range: 567..568, | 824 | range: 566..567, |
823 | kind: TypeHint, | 825 | kind: TypeHint, |
824 | label: "&u8", | 826 | label: "&u8", |
825 | }, | 827 | }, |
@@ -864,52 +866,52 @@ fn main() { | |||
864 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" | 866 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
865 | [ | 867 | [ |
866 | InlayHint { | 868 | InlayHint { |
867 | range: 252..256, | 869 | range: 251..255, |
868 | kind: TypeHint, | 870 | kind: TypeHint, |
869 | label: "CustomOption<Test>", | 871 | label: "CustomOption<Test>", |
870 | }, | 872 | }, |
871 | InlayHint { | 873 | InlayHint { |
872 | range: 277..281, | 874 | range: 276..280, |
873 | kind: TypeHint, | 875 | kind: TypeHint, |
874 | label: "Test", | 876 | label: "Test", |
875 | }, | 877 | }, |
876 | InlayHint { | 878 | InlayHint { |
877 | range: 310..311, | 879 | range: 309..310, |
878 | kind: TypeHint, | 880 | kind: TypeHint, |
879 | label: "CustomOption<u32>", | 881 | label: "CustomOption<u32>", |
880 | }, | 882 | }, |
881 | InlayHint { | 883 | InlayHint { |
882 | range: 313..314, | 884 | range: 312..313, |
883 | kind: TypeHint, | 885 | kind: TypeHint, |
884 | label: "u8", | 886 | label: "u8", |
885 | }, | 887 | }, |
886 | InlayHint { | 888 | InlayHint { |
887 | range: 348..349, | 889 | range: 347..348, |
888 | kind: TypeHint, | 890 | kind: TypeHint, |
889 | label: "CustomOption<u32>", | 891 | label: "CustomOption<u32>", |
890 | }, | 892 | }, |
891 | InlayHint { | 893 | InlayHint { |
892 | range: 354..355, | 894 | range: 353..354, |
893 | kind: TypeHint, | 895 | kind: TypeHint, |
894 | label: "u8", | 896 | label: "u8", |
895 | }, | 897 | }, |
896 | InlayHint { | 898 | InlayHint { |
897 | range: 394..395, | 899 | range: 393..394, |
898 | kind: TypeHint, | 900 | kind: TypeHint, |
899 | label: "u32", | 901 | label: "u32", |
900 | }, | 902 | }, |
901 | InlayHint { | 903 | InlayHint { |
902 | range: 401..402, | 904 | range: 400..401, |
903 | kind: TypeHint, | 905 | kind: TypeHint, |
904 | label: "u8", | 906 | label: "u8", |
905 | }, | 907 | }, |
906 | InlayHint { | 908 | InlayHint { |
907 | range: 445..446, | 909 | range: 444..445, |
908 | kind: TypeHint, | 910 | kind: TypeHint, |
909 | label: "u8", | 911 | label: "u8", |
910 | }, | 912 | }, |
911 | InlayHint { | 913 | InlayHint { |
912 | range: 480..481, | 914 | range: 479..480, |
913 | kind: TypeHint, | 915 | kind: TypeHint, |
914 | label: "u8", | 916 | label: "u8", |
915 | }, | 917 | }, |
@@ -936,17 +938,17 @@ fn main() { | |||
936 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" | 938 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" |
937 | [ | 939 | [ |
938 | InlayHint { | 940 | InlayHint { |
939 | range: 74..75, | 941 | range: 73..74, |
940 | kind: TypeHint, | 942 | kind: TypeHint, |
941 | label: "Smol<u32>", | 943 | label: "Smol<u32>", |
942 | }, | 944 | }, |
943 | InlayHint { | 945 | InlayHint { |
944 | range: 98..99, | 946 | range: 97..98, |
945 | kind: TypeHint, | 947 | kind: TypeHint, |
946 | label: "VeryLongOuterName<…>", | 948 | label: "VeryLongOuterName<…>", |
947 | }, | 949 | }, |
948 | InlayHint { | 950 | InlayHint { |
949 | range: 137..138, | 951 | range: 136..137, |
950 | kind: TypeHint, | 952 | kind: TypeHint, |
951 | label: "Smol<Smol<…>>", | 953 | label: "Smol<Smol<…>>", |
952 | }, | 954 | }, |
@@ -1024,77 +1026,77 @@ fn main() { | |||
1024 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" | 1026 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" |
1025 | [ | 1027 | [ |
1026 | InlayHint { | 1028 | InlayHint { |
1027 | range: 798..809, | 1029 | range: 797..808, |
1028 | kind: TypeHint, | 1030 | kind: TypeHint, |
1029 | label: "i32", | 1031 | label: "i32", |
1030 | }, | 1032 | }, |
1031 | InlayHint { | 1033 | InlayHint { |
1032 | range: 842..843, | 1034 | range: 841..842, |
1033 | kind: ParameterHint, | 1035 | kind: ParameterHint, |
1034 | label: "foo", | 1036 | label: "foo", |
1035 | }, | 1037 | }, |
1036 | InlayHint { | 1038 | InlayHint { |
1037 | range: 845..846, | 1039 | range: 844..845, |
1038 | kind: ParameterHint, | 1040 | kind: ParameterHint, |
1039 | label: "bar", | 1041 | label: "bar", |
1040 | }, | 1042 | }, |
1041 | InlayHint { | 1043 | InlayHint { |
1042 | range: 848..855, | 1044 | range: 847..854, |
1043 | kind: ParameterHint, | 1045 | kind: ParameterHint, |
1044 | label: "msg", | 1046 | label: "msg", |
1045 | }, | 1047 | }, |
1046 | InlayHint { | 1048 | InlayHint { |
1047 | range: 860..871, | 1049 | range: 859..870, |
1048 | kind: ParameterHint, | 1050 | kind: ParameterHint, |
1049 | label: "last", | 1051 | label: "last", |
1050 | }, | 1052 | }, |
1051 | InlayHint { | 1053 | InlayHint { |
1052 | range: 914..917, | 1054 | range: 913..916, |
1053 | kind: ParameterHint, | 1055 | kind: ParameterHint, |
1054 | label: "param", | 1056 | label: "param", |
1055 | }, | 1057 | }, |
1056 | InlayHint { | 1058 | InlayHint { |
1057 | range: 937..939, | 1059 | range: 936..938, |
1058 | kind: ParameterHint, | 1060 | kind: ParameterHint, |
1059 | label: "&self", | 1061 | label: "&self", |
1060 | }, | 1062 | }, |
1061 | InlayHint { | 1063 | InlayHint { |
1062 | range: 941..945, | 1064 | range: 940..944, |
1063 | kind: ParameterHint, | 1065 | kind: ParameterHint, |
1064 | label: "param", | 1066 | label: "param", |
1065 | }, | 1067 | }, |
1066 | InlayHint { | 1068 | InlayHint { |
1067 | range: 980..989, | 1069 | range: 979..988, |
1068 | kind: ParameterHint, | 1070 | kind: ParameterHint, |
1069 | label: "file_id", | 1071 | label: "file_id", |
1070 | }, | 1072 | }, |
1071 | InlayHint { | 1073 | InlayHint { |
1072 | range: 999..1012, | 1074 | range: 998..1011, |
1073 | kind: ParameterHint, | 1075 | kind: ParameterHint, |
1074 | label: "name", | 1076 | label: "name", |
1075 | }, | 1077 | }, |
1076 | InlayHint { | 1078 | InlayHint { |
1077 | range: 1022..1026, | 1079 | range: 1021..1025, |
1078 | kind: ParameterHint, | 1080 | kind: ParameterHint, |
1079 | label: "focus_range", | 1081 | label: "focus_range", |
1080 | }, | 1082 | }, |
1081 | InlayHint { | 1083 | InlayHint { |
1082 | range: 1036..1048, | 1084 | range: 1035..1047, |
1083 | kind: ParameterHint, | 1085 | kind: ParameterHint, |
1084 | label: "full_range", | 1086 | label: "full_range", |
1085 | }, | 1087 | }, |
1086 | InlayHint { | 1088 | InlayHint { |
1087 | range: 1058..1071, | 1089 | range: 1057..1070, |
1088 | kind: ParameterHint, | 1090 | kind: ParameterHint, |
1089 | label: "kind", | 1091 | label: "kind", |
1090 | }, | 1092 | }, |
1091 | InlayHint { | 1093 | InlayHint { |
1092 | range: 1081..1085, | 1094 | range: 1080..1084, |
1093 | kind: ParameterHint, | 1095 | kind: ParameterHint, |
1094 | label: "docs", | 1096 | label: "docs", |
1095 | }, | 1097 | }, |
1096 | InlayHint { | 1098 | InlayHint { |
1097 | range: 1095..1099, | 1099 | range: 1094..1098, |
1098 | kind: ParameterHint, | 1100 | kind: ParameterHint, |
1099 | label: "description", | 1101 | label: "description", |
1100 | }, | 1102 | }, |
@@ -1239,16 +1241,17 @@ fn main() { | |||
1239 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" | 1241 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" |
1240 | [ | 1242 | [ |
1241 | InlayHint { | 1243 | InlayHint { |
1242 | range: 232..269, | 1244 | range: 147..172, |
1243 | kind: ChainingHint, | 1245 | kind: ChainingHint, |
1244 | label: "B", | 1246 | label: "B", |
1245 | }, | 1247 | }, |
1246 | InlayHint { | 1248 | InlayHint { |
1247 | range: 232..239, | 1249 | range: 147..154, |
1248 | kind: ChainingHint, | 1250 | kind: ChainingHint, |
1249 | label: "A", | 1251 | label: "A", |
1250 | }, | 1252 | }, |
1251 | ]"###); | 1253 | ] |
1254 | "###); | ||
1252 | } | 1255 | } |
1253 | 1256 | ||
1254 | #[test] | 1257 | #[test] |
@@ -1293,12 +1296,12 @@ fn main() { | |||
1293 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" | 1296 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" |
1294 | [ | 1297 | [ |
1295 | InlayHint { | 1298 | InlayHint { |
1296 | range: 252..323, | 1299 | range: 143..190, |
1297 | kind: ChainingHint, | 1300 | kind: ChainingHint, |
1298 | label: "C", | 1301 | label: "C", |
1299 | }, | 1302 | }, |
1300 | InlayHint { | 1303 | InlayHint { |
1301 | range: 252..300, | 1304 | range: 143..179, |
1302 | kind: ChainingHint, | 1305 | kind: ChainingHint, |
1303 | label: "B", | 1306 | label: "B", |
1304 | }, | 1307 | }, |
@@ -1331,15 +1334,16 @@ fn main() { | |||
1331 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" | 1334 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" |
1332 | [ | 1335 | [ |
1333 | InlayHint { | 1336 | InlayHint { |
1334 | range: 403..452, | 1337 | range: 246..283, |
1335 | kind: ChainingHint, | 1338 | kind: ChainingHint, |
1336 | label: "B<X<i32, bool>>", | 1339 | label: "B<X<i32, bool>>", |
1337 | }, | 1340 | }, |
1338 | InlayHint { | 1341 | InlayHint { |
1339 | range: 403..422, | 1342 | range: 246..265, |
1340 | kind: ChainingHint, | 1343 | kind: ChainingHint, |
1341 | label: "A<X<i32, bool>>", | 1344 | label: "A<X<i32, bool>>", |
1342 | }, | 1345 | }, |
1343 | ]"###); | 1346 | ] |
1347 | "###); | ||
1344 | } | 1348 | } |
1345 | } | 1349 | } |
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index 981bdf924..4e3986604 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs | |||
@@ -117,13 +117,13 @@ impl MockAnalysis { | |||
117 | (res, position) | 117 | (res, position) |
118 | } | 118 | } |
119 | 119 | ||
120 | pub fn add_file_fixture(&mut self, fixture: Fixture) -> FileId { | 120 | fn add_file_fixture(&mut self, fixture: Fixture) -> FileId { |
121 | let file_id = self.next_id(); | 121 | let file_id = self.next_id(); |
122 | self.files.push(MockFileData::from(fixture)); | 122 | self.files.push(MockFileData::from(fixture)); |
123 | file_id | 123 | file_id |
124 | } | 124 | } |
125 | 125 | ||
126 | pub fn add_file_fixture_with_position(&mut self, mut fixture: Fixture) -> FilePosition { | 126 | fn add_file_fixture_with_position(&mut self, mut fixture: Fixture) -> FilePosition { |
127 | let (offset, text) = extract_offset(&fixture.text); | 127 | let (offset, text) = extract_offset(&fixture.text); |
128 | fixture.text = text; | 128 | fixture.text = text; |
129 | let file_id = self.next_id(); | 129 | let file_id = self.next_id(); |
@@ -136,13 +136,13 @@ impl MockAnalysis { | |||
136 | self.files.push(MockFileData::new(path.to_string(), text.to_string())); | 136 | self.files.push(MockFileData::new(path.to_string(), text.to_string())); |
137 | file_id | 137 | file_id |
138 | } | 138 | } |
139 | pub fn add_file_with_position(&mut self, path: &str, text: &str) -> FilePosition { | 139 | fn add_file_with_position(&mut self, path: &str, text: &str) -> FilePosition { |
140 | let (offset, text) = extract_offset(text); | 140 | let (offset, text) = extract_offset(text); |
141 | let file_id = self.next_id(); | 141 | let file_id = self.next_id(); |
142 | self.files.push(MockFileData::new(path.to_string(), text)); | 142 | self.files.push(MockFileData::new(path.to_string(), text)); |
143 | FilePosition { file_id, offset } | 143 | FilePosition { file_id, offset } |
144 | } | 144 | } |
145 | pub fn add_file_with_range(&mut self, path: &str, text: &str) -> FileRange { | 145 | fn add_file_with_range(&mut self, path: &str, text: &str) -> FileRange { |
146 | let (range, text) = extract_range(text); | 146 | let (range, text) = extract_range(text); |
147 | let file_id = self.next_id(); | 147 | let file_id = self.next_id(); |
148 | self.files.push(MockFileData::new(path.to_string(), text)); | 148 | self.files.push(MockFileData::new(path.to_string(), text)); |
@@ -222,8 +222,8 @@ pub fn analysis_and_position(ra_fixture: &str) -> (Analysis, FilePosition) { | |||
222 | 222 | ||
223 | /// Creates analysis for a single file. | 223 | /// Creates analysis for a single file. |
224 | pub fn single_file(ra_fixture: &str) -> (Analysis, FileId) { | 224 | pub fn single_file(ra_fixture: &str) -> (Analysis, FileId) { |
225 | let mut mock = MockAnalysis::new(); | 225 | let mock = MockAnalysis::with_files(ra_fixture); |
226 | let file_id = mock.add_file("/main.rs", ra_fixture); | 226 | let file_id = mock.id_of("/main.rs"); |
227 | (mock.analysis(), file_id) | 227 | (mock.analysis(), file_id) |
228 | } | 228 | } |
229 | 229 | ||
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index b1f48f03b..c8943816f 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs | |||
@@ -140,16 +140,17 @@ fn accidentally_quadratic() { | |||
140 | fn test_ranges() { | 140 | fn test_ranges() { |
141 | let (analysis, file_id) = single_file( | 141 | let (analysis, file_id) = single_file( |
142 | r#" | 142 | r#" |
143 | #[derive(Clone, Debug)] | 143 | #[derive(Clone, Debug)] |
144 | struct Foo { | 144 | struct Foo { |
145 | pub x: i32, | 145 | pub x: i32, |
146 | pub y: i32, | 146 | pub y: i32, |
147 | }"#, | 147 | } |
148 | "#, | ||
148 | ); | 149 | ); |
149 | 150 | ||
150 | // The "x" | 151 | // The "x" |
151 | let highlights = &analysis | 152 | let highlights = &analysis |
152 | .highlight_range(FileRange { file_id, range: TextRange::at(82.into(), 1.into()) }) | 153 | .highlight_range(FileRange { file_id, range: TextRange::at(45.into(), 1.into()) }) |
153 | .unwrap(); | 154 | .unwrap(); |
154 | 155 | ||
155 | assert_eq!(&highlights[0].highlight.to_string(), "field.declaration"); | 156 | assert_eq!(&highlights[0].highlight.to_string(), "field.declaration"); |
diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs index a40d8af9c..787e85ffd 100644 --- a/crates/ra_ide/src/typing/on_enter.rs +++ b/crates/ra_ide/src/typing/on_enter.rs | |||
@@ -75,18 +75,15 @@ fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> { | |||
75 | 75 | ||
76 | #[cfg(test)] | 76 | #[cfg(test)] |
77 | mod tests { | 77 | mod tests { |
78 | use test_utils::{assert_eq_text, extract_offset}; | 78 | use test_utils::assert_eq_text; |
79 | 79 | ||
80 | use crate::mock_analysis::single_file; | 80 | use crate::mock_analysis::single_file_with_position; |
81 | |||
82 | use super::*; | ||
83 | 81 | ||
84 | fn apply_on_enter(before: &str) -> Option<String> { | 82 | fn apply_on_enter(before: &str) -> Option<String> { |
85 | let (offset, before) = extract_offset(before); | 83 | let (analysis, position) = single_file_with_position(&before); |
86 | let (analysis, file_id) = single_file(&before); | 84 | let result = analysis.on_enter(position).unwrap()?; |
87 | let result = analysis.on_enter(FilePosition { offset, file_id }).unwrap()?; | ||
88 | 85 | ||
89 | let mut actual = before.to_string(); | 86 | let mut actual = analysis.file_text(position.file_id).unwrap().to_string(); |
90 | result.apply(&mut actual); | 87 | result.apply(&mut actual); |
91 | Some(actual) | 88 | Some(actual) |
92 | } | 89 | } |