mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Merge #5698
5698: Display the value of a const on the hover r=jonas-schievink a=JmPotato Signed-off-by: JmPotato <ghzpotato@gmail.com> Close #4051 To display the value of a const, I modified the implementation of `ShortLabel` for `ast::Const`. Co-authored-by: JmPotato <ghzpotato@gmail.com>
This commit is contained in:
commit
f3336509e5
2 changed files with 9 additions and 5 deletions
|
@ -61,7 +61,11 @@ impl ShortLabel for ast::TypeAlias {
|
||||||
|
|
||||||
impl ShortLabel for ast::Const {
|
impl ShortLabel for ast::Const {
|
||||||
fn short_label(&self) -> Option<String> {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -590,16 +590,16 @@ fn main() {
|
||||||
#[test]
|
#[test]
|
||||||
fn hover_const_static() {
|
fn hover_const_static() {
|
||||||
check(
|
check(
|
||||||
r#"const foo<|>: u32 = 0;"#,
|
r#"const foo<|>: u32 = 123;"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
*foo*
|
*foo*
|
||||||
```rust
|
```rust
|
||||||
const foo: u32
|
const foo: u32 = 123
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
check(
|
check(
|
||||||
r#"static foo<|>: u32 = 0;"#,
|
r#"static foo<|>: u32 = 456;"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
*foo*
|
*foo*
|
||||||
```rust
|
```rust
|
||||||
|
@ -834,7 +834,7 @@ fn main() {
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
*C*
|
*C*
|
||||||
```rust
|
```rust
|
||||||
const C: u32
|
const C: u32 = 1
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue