aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/display.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/display.rs')
-rw-r--r--crates/ra_hir_ty/src/display.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs
index 9176c0629..dcca1bace 100644
--- a/crates/ra_hir_ty/src/display.rs
+++ b/crates/ra_hir_ty/src/display.rs
@@ -9,7 +9,8 @@ pub struct HirFormatter<'a, 'b, DB> {
9 fmt: &'a mut fmt::Formatter<'b>, 9 fmt: &'a mut fmt::Formatter<'b>,
10 buf: String, 10 buf: String,
11 curr_size: usize, 11 curr_size: usize,
12 truncate_options: Option<&'a TruncateOptions>, 12 max_size: Option<usize>,
13 should_display_default_types: bool,
13} 14}
14 15
15pub trait HirDisplay { 16pub trait HirDisplay {
@@ -19,18 +20,18 @@ pub trait HirDisplay {
19 where 20 where
20 Self: Sized, 21 Self: Sized,
21 { 22 {
22 HirDisplayWrapper(db, self, None) 23 HirDisplayWrapper(db, self, None, true)
23 } 24 }
24 25
25 fn display_truncated<'a, DB>( 26 fn display_truncated<'a, DB>(
26 &'a self, 27 &'a self,
27 db: &'a DB, 28 db: &'a DB,
28 truncate_options: &'a TruncateOptions, 29 max_size: Option<usize>,
29 ) -> HirDisplayWrapper<'a, DB, Self> 30 ) -> HirDisplayWrapper<'a, DB, Self>
30 where 31 where
31 Self: Sized, 32 Self: Sized,
32 { 33 {
33 HirDisplayWrapper(db, self, Some(truncate_options)) 34 HirDisplayWrapper(db, self, max_size, false)
34 } 35 }
35} 36}
36 37
@@ -66,7 +67,7 @@ where
66 } 67 }
67 68
68 pub fn should_truncate(&self) -> bool { 69 pub fn should_truncate(&self) -> bool {
69 if let Some(max_size) = self.truncate_options.and_then(|options| options.max_length) { 70 if let Some(max_size) = self.max_size {
70 self.curr_size >= max_size 71 self.curr_size >= max_size
71 } else { 72 } else {
72 false 73 false
@@ -74,16 +75,11 @@ where
74 } 75 }
75 76
76 pub fn should_display_default_types(&self) -> bool { 77 pub fn should_display_default_types(&self) -> bool {
77 self.truncate_options.map(|options| options.show_default_types).unwrap_or(true) 78 self.should_display_default_types
78 } 79 }
79} 80}
80 81
81pub struct TruncateOptions { 82pub struct HirDisplayWrapper<'a, DB, T>(&'a DB, &'a T, Option<usize>, bool);
82 pub max_length: Option<usize>,
83 pub show_default_types: bool,
84}
85
86pub struct HirDisplayWrapper<'a, DB, T>(&'a DB, &'a T, Option<&'a TruncateOptions>);
87 83
88impl<'a, DB, T> fmt::Display for HirDisplayWrapper<'a, DB, T> 84impl<'a, DB, T> fmt::Display for HirDisplayWrapper<'a, DB, T>
89where 85where
@@ -96,7 +92,8 @@ where
96 fmt: f, 92 fmt: f,
97 buf: String::with_capacity(20), 93 buf: String::with_capacity(20),
98 curr_size: 0, 94 curr_size: 0,
99 truncate_options: self.2, 95 max_size: self.2,
96 should_display_default_types: self.3,
100 }) 97 })
101 } 98 }
102} 99}