Skip to content

Commit f333650

Browse files
bors[bot]JmPotato
andauthored
Merge #5698
5698: Display the value of a const on the hover r=jonas-schievink a=JmPotato Signed-off-by: JmPotato <[email protected]> Close #4051 To display the value of a const, I modified the implementation of `ShortLabel` for `ast::Const`. Co-authored-by: JmPotato <[email protected]>
2 parents 7a03f05 + 958b91c commit f333650

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

crates/ra_ide/src/display/short_label.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ impl ShortLabel for ast::TypeAlias {
6161

6262
impl ShortLabel for ast::Const {
6363
fn short_label(&self) -> Option<String> {
64-
short_label_from_ty(self, self.ty(), "const ")
64+
let mut new_buf = short_label_from_ty(self, self.ty(), "const ")?;
65+
if let Some(expr) = self.body() {
66+
format_to!(new_buf, " = {}", expr.syntax());
67+
}
68+
Some(new_buf)
6569
}
6670
}
6771

crates/ra_ide/src/hover.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,16 +590,16 @@ fn main() {
590590
#[test]
591591
fn hover_const_static() {
592592
check(
593-
r#"const foo<|>: u32 = 0;"#,
593+
r#"const foo<|>: u32 = 123;"#,
594594
expect![[r#"
595595
*foo*
596596
```rust
597-
const foo: u32
597+
const foo: u32 = 123
598598
```
599599
"#]],
600600
);
601601
check(
602-
r#"static foo<|>: u32 = 0;"#,
602+
r#"static foo<|>: u32 = 456;"#,
603603
expect![[r#"
604604
*foo*
605605
```rust
@@ -834,7 +834,7 @@ fn main() {
834834
expect![[r#"
835835
*C*
836836
```rust
837-
const C: u32
837+
const C: u32 = 1
838838
```
839839
"#]],
840840
)

0 commit comments

Comments
 (0)