diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_ty/src/display.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/lib.rs | 31 | ||||
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 37 |
3 files changed, 62 insertions, 18 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 { |
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index c5e406977..977aafc51 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -293,7 +293,7 @@ fn main() { | |||
293 | } | 293 | } |
294 | 294 | ||
295 | #[test] | 295 | #[test] |
296 | fn closure_parameter() { | 296 | fn closure_parameters() { |
297 | let (analysis, file_id) = single_file( | 297 | let (analysis, file_id) = single_file( |
298 | r#" | 298 | r#" |
299 | fn main() { | 299 | fn main() { |
@@ -301,6 +301,11 @@ fn main() { | |||
301 | (0..2).for_each(|increment| { | 301 | (0..2).for_each(|increment| { |
302 | start += increment; | 302 | start += increment; |
303 | }) | 303 | }) |
304 | |||
305 | let multiply = |a, b, c, d| a * b * c * d; | ||
306 | let _: i32 = multiply(1, 2, 3, 4); | ||
307 | |||
308 | let return_42 = || 42; | ||
304 | }"#, | 309 | }"#, |
305 | ); | 310 | ); |
306 | 311 | ||
@@ -316,6 +321,36 @@ fn main() { | |||
316 | kind: TypeHint, | 321 | kind: TypeHint, |
317 | label: "i32", | 322 | label: "i32", |
318 | }, | 323 | }, |
324 | InlayHint { | ||
325 | range: [114; 122), | ||
326 | kind: TypeHint, | ||
327 | label: "|…| -> i32", | ||
328 | }, | ||
329 | InlayHint { | ||
330 | range: [126; 127), | ||
331 | kind: TypeHint, | ||
332 | label: "i32", | ||
333 | }, | ||
334 | InlayHint { | ||
335 | range: [129; 130), | ||
336 | kind: TypeHint, | ||
337 | label: "i32", | ||
338 | }, | ||
339 | InlayHint { | ||
340 | range: [132; 133), | ||
341 | kind: TypeHint, | ||
342 | label: "i32", | ||
343 | }, | ||
344 | InlayHint { | ||
345 | range: [135; 136), | ||
346 | kind: TypeHint, | ||
347 | label: "i32", | ||
348 | }, | ||
349 | InlayHint { | ||
350 | range: [201; 210), | ||
351 | kind: TypeHint, | ||
352 | label: "|| -> i32", | ||
353 | }, | ||
319 | ] | 354 | ] |
320 | "### | 355 | "### |
321 | ); | 356 | ); |