From 4d9c8821e5c328f29b77667c86cabb3689947fd2 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Mon, 10 Aug 2020 14:02:40 +0800 Subject: Show const body in short_label Signed-off-by: JmPotato --- crates/ra_ide/src/display/short_label.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src/display/short_label.rs') diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index b5ff9fa2d..d8acb3be7 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -61,7 +61,15 @@ impl ShortLabel for ast::TypeAlias { impl ShortLabel for ast::Const { fn short_label(&self) -> Option { - short_label_from_ty(self, self.ty(), "const ") + match short_label_from_ty(self, self.ty(), "const ") { + Some(buf) => { + let mut new_buf = buf; + let body = self.body().unwrap(); + format_to!(new_buf, " = {}", body.syntax()); + Some(new_buf) + } + None => None, + } } } -- cgit v1.2.3 From 958b91c1e8394129216d1b8378d726f937592d3f Mon Sep 17 00:00:00 2001 From: JmPotato Date: Mon, 10 Aug 2020 17:51:45 +0800 Subject: Better codes Signed-off-by: JmPotato --- crates/ra_ide/src/display/short_label.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide/src/display/short_label.rs') diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index d8acb3be7..010c34705 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -61,15 +61,11 @@ impl ShortLabel for ast::TypeAlias { impl ShortLabel for ast::Const { fn short_label(&self) -> Option { - match short_label_from_ty(self, self.ty(), "const ") { - Some(buf) => { - let mut new_buf = buf; - let body = self.body().unwrap(); - format_to!(new_buf, " = {}", body.syntax()); - Some(new_buf) - } - None => None, + let mut new_buf = short_label_from_ty(self, self.ty(), "const ")?; + if let Some(expr) = self.body() { + format_to!(new_buf, " = {}", expr.syntax()); } + Some(new_buf) } } -- cgit v1.2.3