diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/test_utils.rs | 22 | ||||
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 94 | ||||
-rw-r--r-- | crates/rust-analyzer/src/diagnostics/to_proto.rs | 1 |
4 files changed, 60 insertions, 61 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index e4c57e41a..48afee5fb 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -491,7 +491,7 @@ mod tests { | |||
491 | } | 491 | } |
492 | } | 492 | } |
493 | 493 | ||
494 | let mut completions = get_all_completion_items(ra_fixture, &CompletionConfig::default()); | 494 | let mut completions = get_all_completion_items(CompletionConfig::default(), ra_fixture); |
495 | completions.sort_by_key(|it| (Reverse(it.score()), it.label().to_string())); | 495 | completions.sort_by_key(|it| (Reverse(it.score()), it.label().to_string())); |
496 | let actual = completions | 496 | let actual = completions |
497 | .into_iter() | 497 | .into_iter() |
@@ -835,6 +835,7 @@ fn bar(s: &S) { | |||
835 | fn suppress_arg_snippets() { | 835 | fn suppress_arg_snippets() { |
836 | mark::check!(suppress_arg_snippets); | 836 | mark::check!(suppress_arg_snippets); |
837 | check_edit_with_config( | 837 | check_edit_with_config( |
838 | CompletionConfig { add_call_argument_snippets: false, ..CompletionConfig::default() }, | ||
838 | "with_args", | 839 | "with_args", |
839 | r#" | 840 | r#" |
840 | fn with_args(x: i32, y: String) {} | 841 | fn with_args(x: i32, y: String) {} |
@@ -844,7 +845,6 @@ fn main() { with_<|> } | |||
844 | fn with_args(x: i32, y: String) {} | 845 | fn with_args(x: i32, y: String) {} |
845 | fn main() { with_args($0) } | 846 | fn main() { with_args($0) } |
846 | "#, | 847 | "#, |
847 | &CompletionConfig { add_call_argument_snippets: false, ..CompletionConfig::default() }, | ||
848 | ); | 848 | ); |
849 | } | 849 | } |
850 | 850 | ||
diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs index c2be23697..919177745 100644 --- a/crates/ra_ide/src/completion/test_utils.rs +++ b/crates/ra_ide/src/completion/test_utils.rs | |||
@@ -13,15 +13,15 @@ use crate::{ | |||
13 | }; | 13 | }; |
14 | 14 | ||
15 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { | 15 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { |
16 | do_completion_with_config(code, kind, &CompletionConfig::default()) | 16 | do_completion_with_config(CompletionConfig::default(), code, kind) |
17 | } | 17 | } |
18 | 18 | ||
19 | pub(crate) fn do_completion_with_config( | 19 | pub(crate) fn do_completion_with_config( |
20 | config: CompletionConfig, | ||
20 | code: &str, | 21 | code: &str, |
21 | kind: CompletionKind, | 22 | kind: CompletionKind, |
22 | config: &CompletionConfig, | ||
23 | ) -> Vec<CompletionItem> { | 23 | ) -> Vec<CompletionItem> { |
24 | let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(code, config) | 24 | let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(config, code) |
25 | .into_iter() | 25 | .into_iter() |
26 | .filter(|c| c.completion_kind == kind) | 26 | .filter(|c| c.completion_kind == kind) |
27 | .collect(); | 27 | .collect(); |
@@ -30,15 +30,15 @@ pub(crate) fn do_completion_with_config( | |||
30 | } | 30 | } |
31 | 31 | ||
32 | pub(crate) fn completion_list(code: &str, kind: CompletionKind) -> String { | 32 | pub(crate) fn completion_list(code: &str, kind: CompletionKind) -> String { |
33 | completion_list_with_config(code, kind, &CompletionConfig::default()) | 33 | completion_list_with_config(CompletionConfig::default(), code, kind) |
34 | } | 34 | } |
35 | 35 | ||
36 | pub(crate) fn completion_list_with_config( | 36 | pub(crate) fn completion_list_with_config( |
37 | config: CompletionConfig, | ||
37 | code: &str, | 38 | code: &str, |
38 | kind: CompletionKind, | 39 | kind: CompletionKind, |
39 | config: &CompletionConfig, | ||
40 | ) -> String { | 40 | ) -> String { |
41 | let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(code, config) | 41 | let mut kind_completions: Vec<CompletionItem> = get_all_completion_items(config, code) |
42 | .into_iter() | 42 | .into_iter() |
43 | .filter(|c| c.completion_kind == kind) | 43 | .filter(|c| c.completion_kind == kind) |
44 | .collect(); | 44 | .collect(); |
@@ -70,19 +70,19 @@ fn monospace_width(s: &str) -> usize { | |||
70 | } | 70 | } |
71 | 71 | ||
72 | pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) { | 72 | pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) { |
73 | check_edit_with_config(what, ra_fixture_before, ra_fixture_after, &CompletionConfig::default()) | 73 | check_edit_with_config(CompletionConfig::default(), what, ra_fixture_before, ra_fixture_after) |
74 | } | 74 | } |
75 | 75 | ||
76 | pub(crate) fn check_edit_with_config( | 76 | pub(crate) fn check_edit_with_config( |
77 | config: CompletionConfig, | ||
77 | what: &str, | 78 | what: &str, |
78 | ra_fixture_before: &str, | 79 | ra_fixture_before: &str, |
79 | ra_fixture_after: &str, | 80 | ra_fixture_after: &str, |
80 | config: &CompletionConfig, | ||
81 | ) { | 81 | ) { |
82 | let ra_fixture_after = trim_indent(ra_fixture_after); | 82 | let ra_fixture_after = trim_indent(ra_fixture_after); |
83 | let (analysis, position) = analysis_and_position(ra_fixture_before); | 83 | let (analysis, position) = analysis_and_position(ra_fixture_before); |
84 | let completions: Vec<CompletionItem> = | 84 | let completions: Vec<CompletionItem> = |
85 | analysis.completions(config, position).unwrap().unwrap().into(); | 85 | analysis.completions(&config, position).unwrap().unwrap().into(); |
86 | let (completion,) = completions | 86 | let (completion,) = completions |
87 | .iter() | 87 | .iter() |
88 | .filter(|it| it.lookup() == what) | 88 | .filter(|it| it.lookup() == what) |
@@ -106,9 +106,9 @@ pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) - | |||
106 | } | 106 | } |
107 | 107 | ||
108 | pub(crate) fn get_all_completion_items( | 108 | pub(crate) fn get_all_completion_items( |
109 | config: CompletionConfig, | ||
109 | code: &str, | 110 | code: &str, |
110 | options: &CompletionConfig, | ||
111 | ) -> Vec<CompletionItem> { | 111 | ) -> Vec<CompletionItem> { |
112 | let (analysis, position) = analysis_and_position(code); | 112 | let (analysis, position) = analysis_and_position(code); |
113 | analysis.completions(options, position).unwrap().unwrap().into() | 113 | analysis.completions(&config, position).unwrap().unwrap().into() |
114 | } | 114 | } |
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 { |
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index 808a23b17..b1b222deb 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs | |||
@@ -258,7 +258,6 @@ mod tests { | |||
258 | 258 | ||
259 | use expect::{expect_file, ExpectFile}; | 259 | use expect::{expect_file, ExpectFile}; |
260 | 260 | ||
261 | // TODO: inlay hints config order | ||
262 | fn check(diagnostics_json: &str, expect: ExpectFile) { | 261 | fn check(diagnostics_json: &str, expect: ExpectFile) { |
263 | check_with_config(DiagnosticsConfig::default(), diagnostics_json, expect) | 262 | check_with_config(DiagnosticsConfig::default(), diagnostics_json, expect) |
264 | } | 263 | } |