Skip to content

Commit

Permalink
Merge #5698
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and JmPotato authored Aug 10, 2020
2 parents 7a03f05 + 958b91c commit f333650
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion crates/ra_ide/src/display/short_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ impl ShortLabel for ast::TypeAlias {

impl ShortLabel for ast::Const {
fn short_label(&self) -> Option<String> {
short_label_from_ty(self, self.ty(), "const ")
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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/ra_ide/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -834,7 +834,7 @@ fn main() {
expect![[r#"
*C*
```rust
const C: u32
const C: u32 = 1
```
"#]],
)
Expand Down

0 comments on commit f333650

Please sign in to comment.