diff options
Diffstat (limited to 'crates/ra_ide/src/inlay_hints.rs')
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 62d364bfa..35ab741d8 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -351,10 +351,10 @@ mod tests { | |||
351 | use crate::{inlay_hints::InlayHintsConfig, mock_analysis::single_file}; | 351 | use crate::{inlay_hints::InlayHintsConfig, mock_analysis::single_file}; |
352 | 352 | ||
353 | fn check(ra_fixture: &str) { | 353 | fn check(ra_fixture: &str) { |
354 | check_with_config(ra_fixture, InlayHintsConfig::default()); | 354 | check_with_config(InlayHintsConfig::default(), ra_fixture); |
355 | } | 355 | } |
356 | 356 | ||
357 | fn check_with_config(ra_fixture: &str, config: InlayHintsConfig) { | 357 | fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) { |
358 | let (analysis, file_id) = single_file(ra_fixture); | 358 | let (analysis, file_id) = single_file(ra_fixture); |
359 | let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); | 359 | let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); |
360 | let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); | 360 | let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); |
@@ -363,7 +363,7 @@ mod tests { | |||
363 | assert_eq!(expected, actual); | 363 | assert_eq!(expected, actual); |
364 | } | 364 | } |
365 | 365 | ||
366 | fn check_expect(ra_fixture: &str, config: InlayHintsConfig, expect: Expect) { | 366 | fn check_expect(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) { |
367 | let (analysis, file_id) = single_file(ra_fixture); | 367 | let (analysis, file_id) = single_file(ra_fixture); |
368 | let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); | 368 | let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); |
369 | expect.assert_debug_eq(&inlay_hints) | 369 | expect.assert_debug_eq(&inlay_hints) |
@@ -372,6 +372,12 @@ mod tests { | |||
372 | #[test] | 372 | #[test] |
373 | fn param_hints_only() { | 373 | fn param_hints_only() { |
374 | check_with_config( | 374 | check_with_config( |
375 | InlayHintsConfig { | ||
376 | parameter_hints: true, | ||
377 | type_hints: false, | ||
378 | chaining_hints: false, | ||
379 | max_length: None, | ||
380 | }, | ||
375 | r#" | 381 | r#" |
376 | fn foo(a: i32, b: i32) -> i32 { a + b } | 382 | fn foo(a: i32, b: i32) -> i32 { a + b } |
377 | fn main() { | 383 | fn main() { |
@@ -382,47 +388,41 @@ fn main() { | |||
382 | //^ b | 388 | //^ b |
383 | ); | 389 | ); |
384 | }"#, | 390 | }"#, |
385 | InlayHintsConfig { | ||
386 | parameter_hints: true, | ||
387 | type_hints: false, | ||
388 | chaining_hints: false, | ||
389 | max_length: None, | ||
390 | }, | ||
391 | ); | 391 | ); |
392 | } | 392 | } |
393 | 393 | ||
394 | #[test] | 394 | #[test] |
395 | fn hints_disabled() { | 395 | fn hints_disabled() { |
396 | check_with_config( | 396 | check_with_config( |
397 | r#" | ||
398 | fn foo(a: i32, b: i32) -> i32 { a + b } | ||
399 | fn main() { | ||
400 | let _x = foo(4, 4); | ||
401 | }"#, | ||
402 | InlayHintsConfig { | 397 | InlayHintsConfig { |
403 | type_hints: false, | 398 | type_hints: false, |
404 | parameter_hints: false, | 399 | parameter_hints: false, |
405 | chaining_hints: false, | 400 | chaining_hints: false, |
406 | max_length: None, | 401 | max_length: None, |
407 | }, | 402 | }, |
403 | r#" | ||
404 | fn foo(a: i32, b: i32) -> i32 { a + b } | ||
405 | fn main() { | ||
406 | let _x = foo(4, 4); | ||
407 | }"#, | ||
408 | ); | 408 | ); |
409 | } | 409 | } |
410 | 410 | ||
411 | #[test] | 411 | #[test] |
412 | fn type_hints_only() { | 412 | fn type_hints_only() { |
413 | check_with_config( | 413 | check_with_config( |
414 | r#" | ||
415 | fn foo(a: i32, b: i32) -> i32 { a + b } | ||
416 | fn main() { | ||
417 | let _x = foo(4, 4); | ||
418 | //^^ i32 | ||
419 | }"#, | ||
420 | InlayHintsConfig { | 414 | InlayHintsConfig { |
421 | type_hints: true, | 415 | type_hints: true, |
422 | parameter_hints: false, | 416 | parameter_hints: false, |
423 | chaining_hints: false, | 417 | chaining_hints: false, |
424 | max_length: None, | 418 | max_length: None, |
425 | }, | 419 | }, |
420 | r#" | ||
421 | fn foo(a: i32, b: i32) -> i32 { a + b } | ||
422 | fn main() { | ||
423 | let _x = foo(4, 4); | ||
424 | //^^ i32 | ||
425 | }"#, | ||
426 | ); | 426 | ); |
427 | } | 427 | } |
428 | 428 | ||
@@ -590,6 +590,7 @@ fn main() { | |||
590 | #[test] | 590 | #[test] |
591 | fn hint_truncation() { | 591 | fn hint_truncation() { |
592 | check_with_config( | 592 | check_with_config( |
593 | InlayHintsConfig { max_length: Some(8), ..Default::default() }, | ||
593 | r#" | 594 | r#" |
594 | struct Smol<T>(T); | 595 | struct Smol<T>(T); |
595 | 596 | ||
@@ -603,7 +604,6 @@ fn main() { | |||
603 | let c = Smol(Smol(0u32)) | 604 | let c = Smol(Smol(0u32)) |
604 | //^ Smol<Smol<…>> | 605 | //^ Smol<Smol<…>> |
605 | }"#, | 606 | }"#, |
606 | InlayHintsConfig { max_length: Some(8), ..Default::default() }, | ||
607 | ); | 607 | ); |
608 | } | 608 | } |
609 | 609 | ||
@@ -673,6 +673,7 @@ fn main() { | |||
673 | #[test] | 673 | #[test] |
674 | fn omitted_parameters_hints_heuristics() { | 674 | fn omitted_parameters_hints_heuristics() { |
675 | check_with_config( | 675 | check_with_config( |
676 | InlayHintsConfig { max_length: Some(8), ..Default::default() }, | ||
676 | r#" | 677 | r#" |
677 | fn map(f: i32) {} | 678 | fn map(f: i32) {} |
678 | fn filter(predicate: i32) {} | 679 | fn filter(predicate: i32) {} |
@@ -753,13 +754,13 @@ fn main() { | |||
753 | let _: f64 = a.div_euclid(b); | 754 | let _: f64 = a.div_euclid(b); |
754 | let _: f64 = a.abs_sub(b); | 755 | let _: f64 = a.abs_sub(b); |
755 | }"#, | 756 | }"#, |
756 | InlayHintsConfig { max_length: Some(8), ..Default::default() }, | ||
757 | ); | 757 | ); |
758 | } | 758 | } |
759 | 759 | ||
760 | #[test] | 760 | #[test] |
761 | fn unit_structs_have_no_type_hints() { | 761 | fn unit_structs_have_no_type_hints() { |
762 | check_with_config( | 762 | check_with_config( |
763 | InlayHintsConfig { max_length: Some(8), ..Default::default() }, | ||
763 | r#" | 764 | r#" |
764 | enum Result<T, E> { Ok(T), Err(E) } | 765 | enum Result<T, E> { Ok(T), Err(E) } |
765 | use Result::*; | 766 | use Result::*; |
@@ -772,13 +773,18 @@ fn main() { | |||
772 | Err(SyntheticSyntax) => (), | 773 | Err(SyntheticSyntax) => (), |
773 | } | 774 | } |
774 | }"#, | 775 | }"#, |
775 | InlayHintsConfig { max_length: Some(8), ..Default::default() }, | ||
776 | ); | 776 | ); |
777 | } | 777 | } |
778 | 778 | ||
779 | #[test] | 779 | #[test] |
780 | fn chaining_hints_ignore_comments() { | 780 | fn chaining_hints_ignore_comments() { |
781 | check_expect( | 781 | check_expect( |
782 | InlayHintsConfig { | ||
783 | parameter_hints: false, | ||
784 | type_hints: false, | ||
785 | chaining_hints: true, | ||
786 | max_length: None, | ||
787 | }, | ||
782 | r#" | 788 | r#" |
783 | struct A(B); | 789 | struct A(B); |
784 | impl A { fn into_b(self) -> B { self.0 } } | 790 | impl A { fn into_b(self) -> B { self.0 } } |
@@ -792,12 +798,6 @@ fn main() { | |||
792 | .into_c(); | 798 | .into_c(); |
793 | } | 799 | } |
794 | "#, | 800 | "#, |
795 | InlayHintsConfig { | ||
796 | parameter_hints: false, | ||
797 | type_hints: false, | ||
798 | chaining_hints: true, | ||
799 | max_length: None, | ||
800 | }, | ||
801 | expect![[r#" | 801 | expect![[r#" |
802 | [ | 802 | [ |
803 | InlayHint { | 803 | InlayHint { |
@@ -818,6 +818,12 @@ fn main() { | |||
818 | #[test] | 818 | #[test] |
819 | fn chaining_hints_without_newlines() { | 819 | fn chaining_hints_without_newlines() { |
820 | check_with_config( | 820 | check_with_config( |
821 | InlayHintsConfig { | ||
822 | parameter_hints: false, | ||
823 | type_hints: false, | ||
824 | chaining_hints: true, | ||
825 | max_length: None, | ||
826 | }, | ||
821 | r#" | 827 | r#" |
822 | struct A(B); | 828 | struct A(B); |
823 | impl A { fn into_b(self) -> B { self.0 } } | 829 | impl A { fn into_b(self) -> B { self.0 } } |
@@ -828,18 +834,18 @@ struct C; | |||
828 | fn main() { | 834 | fn main() { |
829 | let c = A(B(C)).into_b().into_c(); | 835 | let c = A(B(C)).into_b().into_c(); |
830 | }"#, | 836 | }"#, |
831 | InlayHintsConfig { | ||
832 | parameter_hints: false, | ||
833 | type_hints: false, | ||
834 | chaining_hints: true, | ||
835 | max_length: None, | ||
836 | }, | ||
837 | ); | 837 | ); |
838 | } | 838 | } |
839 | 839 | ||
840 | #[test] | 840 | #[test] |
841 | fn struct_access_chaining_hints() { | 841 | fn struct_access_chaining_hints() { |
842 | check_expect( | 842 | check_expect( |
843 | InlayHintsConfig { | ||
844 | parameter_hints: false, | ||
845 | type_hints: false, | ||
846 | chaining_hints: true, | ||
847 | max_length: None, | ||
848 | }, | ||
843 | r#" | 849 | r#" |
844 | struct A { pub b: B } | 850 | struct A { pub b: B } |
845 | struct B { pub c: C } | 851 | struct B { pub c: C } |
@@ -858,12 +864,6 @@ fn main() { | |||
858 | let x = D | 864 | let x = D |
859 | .foo(); | 865 | .foo(); |
860 | }"#, | 866 | }"#, |
861 | InlayHintsConfig { | ||
862 | parameter_hints: false, | ||
863 | type_hints: false, | ||
864 | chaining_hints: true, | ||
865 | max_length: None, | ||
866 | }, | ||
867 | expect![[r#" | 867 | expect![[r#" |
868 | [ | 868 | [ |
869 | InlayHint { | 869 | InlayHint { |
@@ -884,6 +884,12 @@ fn main() { | |||
884 | #[test] | 884 | #[test] |
885 | fn generic_chaining_hints() { | 885 | fn generic_chaining_hints() { |
886 | check_expect( | 886 | check_expect( |
887 | InlayHintsConfig { | ||
888 | parameter_hints: false, | ||
889 | type_hints: false, | ||
890 | chaining_hints: true, | ||
891 | max_length: None, | ||
892 | }, | ||
887 | r#" | 893 | r#" |
888 | struct A<T>(T); | 894 | struct A<T>(T); |
889 | struct B<T>(T); | 895 | struct B<T>(T); |
@@ -903,12 +909,6 @@ fn main() { | |||
903 | .into_c(); | 909 | .into_c(); |
904 | } | 910 | } |
905 | "#, | 911 | "#, |
906 | InlayHintsConfig { | ||
907 | parameter_hints: false, | ||
908 | type_hints: false, | ||
909 | chaining_hints: true, | ||
910 | max_length: None, | ||
911 | }, | ||
912 | expect![[r#" | 912 | expect![[r#" |
913 | [ | 913 | [ |
914 | InlayHint { | 914 | InlayHint { |