diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-27 10:10:07 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-27 10:10:07 +0000 |
commit | 823e9193fed138c62a9d50695307c9e46ef890b2 (patch) | |
tree | feab99bf59e23b130194d7874e1eabb6e21d59ac /crates/ra_hir_ty/src | |
parent | 97f01396eda7eb3e6ec5056f3f72d98e5739f829 (diff) | |
parent | 242be3631e6f2c581614b362ff1a572c7ffb8ff6 (diff) |
Merge #2657
2657: Omit closure parameters in closure type display strings r=flodiebold a=SomeoneToIgnore
Part of https://github.com/rust-analyzer/rust-analyzer/issues/1946
I wonder, should we display the the closure trait (Fn/FnMut/FnOnce) in inlay hints instead of `|...|` at all?
Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/display.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/lib.rs | 31 |
2 files changed, 26 insertions, 17 deletions
diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs index dcca1bace..37def7c03 100644 --- a/crates/ra_hir_ty/src/display.rs +++ b/crates/ra_hir_ty/src/display.rs | |||
@@ -10,7 +10,7 @@ pub struct HirFormatter<'a, 'b, DB> { | |||
10 | buf: String, | 10 | buf: String, |
11 | curr_size: usize, | 11 | curr_size: usize, |
12 | max_size: Option<usize>, | 12 | max_size: Option<usize>, |
13 | should_display_default_types: bool, | 13 | omit_verbose_types: bool, |
14 | } | 14 | } |
15 | 15 | ||
16 | pub trait HirDisplay { | 16 | pub trait HirDisplay { |
@@ -20,7 +20,7 @@ pub trait HirDisplay { | |||
20 | where | 20 | where |
21 | Self: Sized, | 21 | Self: Sized, |
22 | { | 22 | { |
23 | HirDisplayWrapper(db, self, None, true) | 23 | HirDisplayWrapper(db, self, None, false) |
24 | } | 24 | } |
25 | 25 | ||
26 | fn display_truncated<'a, DB>( | 26 | fn display_truncated<'a, DB>( |
@@ -31,7 +31,7 @@ pub trait HirDisplay { | |||
31 | where | 31 | where |
32 | Self: Sized, | 32 | Self: Sized, |
33 | { | 33 | { |
34 | HirDisplayWrapper(db, self, max_size, false) | 34 | HirDisplayWrapper(db, self, max_size, true) |
35 | } | 35 | } |
36 | } | 36 | } |
37 | 37 | ||
@@ -74,8 +74,8 @@ where | |||
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | pub fn should_display_default_types(&self) -> bool { | 77 | pub fn omit_verbose_types(&self) -> bool { |
78 | self.should_display_default_types | 78 | self.omit_verbose_types |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
@@ -93,7 +93,7 @@ where | |||
93 | buf: String::with_capacity(20), | 93 | buf: String::with_capacity(20), |
94 | curr_size: 0, | 94 | curr_size: 0, |
95 | max_size: self.2, | 95 | max_size: self.2, |
96 | should_display_default_types: self.3, | 96 | omit_verbose_types: self.3, |
97 | }) | 97 | }) |
98 | } | 98 | } |
99 | } | 99 | } |
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 48abf97c9..55b6dd836 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs | |||
@@ -821,6 +821,8 @@ impl TypeWalk for Ty { | |||
821 | } | 821 | } |
822 | } | 822 | } |
823 | 823 | ||
824 | const TYPE_HINT_TRUNCATION: &str = "…"; | ||
825 | |||
824 | impl HirDisplay for &Ty { | 826 | impl HirDisplay for &Ty { |
825 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 827 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { |
826 | HirDisplay::hir_fmt(*self, f) | 828 | HirDisplay::hir_fmt(*self, f) |
@@ -830,7 +832,7 @@ impl HirDisplay for &Ty { | |||
830 | impl HirDisplay for ApplicationTy { | 832 | impl HirDisplay for ApplicationTy { |
831 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 833 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { |
832 | if f.should_truncate() { | 834 | if f.should_truncate() { |
833 | return write!(f, "…"); | 835 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
834 | } | 836 | } |
835 | 837 | ||
836 | match self.ctor { | 838 | match self.ctor { |
@@ -908,9 +910,7 @@ impl HirDisplay for ApplicationTy { | |||
908 | write!(f, "<")?; | 910 | write!(f, "<")?; |
909 | 911 | ||
910 | let mut non_default_parameters = Vec::with_capacity(self.parameters.len()); | 912 | let mut non_default_parameters = Vec::with_capacity(self.parameters.len()); |
911 | let parameters_to_write = if f.should_display_default_types() { | 913 | let parameters_to_write = if f.omit_verbose_types() { |
912 | self.parameters.0.as_ref() | ||
913 | } else { | ||
914 | match self | 914 | match self |
915 | .ctor | 915 | .ctor |
916 | .as_generic_def() | 916 | .as_generic_def() |
@@ -935,6 +935,8 @@ impl HirDisplay for ApplicationTy { | |||
935 | &non_default_parameters | 935 | &non_default_parameters |
936 | } | 936 | } |
937 | } | 937 | } |
938 | } else { | ||
939 | self.parameters.0.as_ref() | ||
938 | }; | 940 | }; |
939 | 941 | ||
940 | f.write_joined(parameters_to_write, ", ")?; | 942 | f.write_joined(parameters_to_write, ", ")?; |
@@ -959,9 +961,16 @@ impl HirDisplay for ApplicationTy { | |||
959 | let sig = self.parameters[0] | 961 | let sig = self.parameters[0] |
960 | .callable_sig(f.db) | 962 | .callable_sig(f.db) |
961 | .expect("first closure parameter should contain signature"); | 963 | .expect("first closure parameter should contain signature"); |
962 | write!(f, "|")?; | 964 | let return_type_hint = sig.ret().display(f.db); |
963 | f.write_joined(sig.params(), ", ")?; | 965 | if sig.params().is_empty() { |
964 | write!(f, "| -> {}", sig.ret().display(f.db))?; | 966 | write!(f, "|| -> {}", return_type_hint)?; |
967 | } else if f.omit_verbose_types() { | ||
968 | write!(f, "|{}| -> {}", TYPE_HINT_TRUNCATION, return_type_hint)?; | ||
969 | } else { | ||
970 | write!(f, "|")?; | ||
971 | f.write_joined(sig.params(), ", ")?; | ||
972 | write!(f, "| -> {}", return_type_hint)?; | ||
973 | }; | ||
965 | } | 974 | } |
966 | } | 975 | } |
967 | Ok(()) | 976 | Ok(()) |
@@ -971,7 +980,7 @@ impl HirDisplay for ApplicationTy { | |||
971 | impl HirDisplay for ProjectionTy { | 980 | impl HirDisplay for ProjectionTy { |
972 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 981 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { |
973 | if f.should_truncate() { | 982 | if f.should_truncate() { |
974 | return write!(f, "…"); | 983 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
975 | } | 984 | } |
976 | 985 | ||
977 | let trait_name = f.db.trait_data(self.trait_(f.db)).name.clone(); | 986 | let trait_name = f.db.trait_data(self.trait_(f.db)).name.clone(); |
@@ -989,7 +998,7 @@ impl HirDisplay for ProjectionTy { | |||
989 | impl HirDisplay for Ty { | 998 | impl HirDisplay for Ty { |
990 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 999 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { |
991 | if f.should_truncate() { | 1000 | if f.should_truncate() { |
992 | return write!(f, "…"); | 1001 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
993 | } | 1002 | } |
994 | 1003 | ||
995 | match self { | 1004 | match self { |
@@ -1074,7 +1083,7 @@ impl HirDisplay for Ty { | |||
1074 | impl TraitRef { | 1083 | impl TraitRef { |
1075 | fn hir_fmt_ext(&self, f: &mut HirFormatter<impl HirDatabase>, use_as: bool) -> fmt::Result { | 1084 | fn hir_fmt_ext(&self, f: &mut HirFormatter<impl HirDatabase>, use_as: bool) -> fmt::Result { |
1076 | if f.should_truncate() { | 1085 | if f.should_truncate() { |
1077 | return write!(f, "…"); | 1086 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
1078 | } | 1087 | } |
1079 | 1088 | ||
1080 | self.substs[0].hir_fmt(f)?; | 1089 | self.substs[0].hir_fmt(f)?; |
@@ -1108,7 +1117,7 @@ impl HirDisplay for &GenericPredicate { | |||
1108 | impl HirDisplay for GenericPredicate { | 1117 | impl HirDisplay for GenericPredicate { |
1109 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 1118 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { |
1110 | if f.should_truncate() { | 1119 | if f.should_truncate() { |
1111 | return write!(f, "…"); | 1120 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
1112 | } | 1121 | } |
1113 | 1122 | ||
1114 | match self { | 1123 | match self { |