]> git.lizzy.rs Git - rust.git/commitdiff
Show const body in short_label
authorJmPotato <ghzpotato@gmail.com>
Mon, 10 Aug 2020 06:02:40 +0000 (14:02 +0800)
committerJmPotato <ghzpotato@gmail.com>
Mon, 10 Aug 2020 06:02:40 +0000 (14:02 +0800)
Signed-off-by: JmPotato <ghzpotato@gmail.com>
crates/ra_ide/src/display/short_label.rs
crates/ra_ide/src/hover.rs

index b5ff9fa2deb605261ccbb4a8d7f1a3fd04b64410..d8acb3be764b50ce49034025aac64ee1ff78acf9 100644 (file)
@@ -61,7 +61,15 @@ fn short_label(&self) -> Option<String> {
 
 impl ShortLabel for ast::Const {
     fn short_label(&self) -> Option<String> {
-        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,
+        }
     }
 }
 
index 9c7348898a14efc5d84addb566c03d3971414bbb..f66f62bfb5e97ec40527fa75208b301a092905a9 100644 (file)
@@ -590,16 +590,16 @@ fn main() {
     #[test]
     fn hover_const_static() {
         check(
-            r#"const foo<|>: u32 = 0;"#,
+            r#"const foo<|>: u32 = 123;"#,
             expect![[r#"
                 *foo*
                 ```rust
-                const foo: u32
+                const foo: u32 = 123
                 ```
             "#]],
         );
         check(
-            r#"static foo<|>: u32 = 0;"#,
+            r#"static foo<|>: u32 = 456;"#,
             expect![[r#"
                 *foo*
                 ```rust
@@ -834,7 +834,7 @@ fn main() {
             expect![[r#"
                 *C*
                 ```rust
-                const C: u32
+                const C: u32 = 1
                 ```
             "#]],
         )