Put layout comment to the top of hovers

This commit is contained in:
Lukas Wirth 2024-01-16 10:46:53 +01:00
parent 659d4f91e4
commit cf905cff76
2 changed files with 108 additions and 57 deletions

View file

@ -463,9 +463,9 @@ pub(super) fn definition(
};
let label = match (value, layout_info) {
(Some(value), Some(layout_info)) => format!("{label} = {value}{layout_info}"),
(Some(value), Some(layout_info)) => format!("{layout_info}\n{label} = {value}"),
(Some(value), None) => format!("{label} = {value}"),
(None, Some(layout_info)) => format!("{label}{layout_info}"),
(None, Some(layout_info)) => format!("{layout_info}\n{label}"),
(None, None) => label,
};
@ -617,8 +617,6 @@ fn render_memory_layout(
offset: impl FnOnce(&Layout) -> Option<u64>,
tag: impl FnOnce(&Layout) -> Option<usize>,
) -> Option<String> {
// field
let config = config?;
let layout = layout().ok()?;

View file

@ -157,7 +157,8 @@ fn foo() {
*local*
```rust
let local: i32 // size = 4, align = 4
// size = 4, align = 4
let local: i32
```
"#]],
);
@ -433,7 +434,8 @@ fn main() {
*iter*
```rust
let mut iter: Iter<Scan<OtherStruct<OtherStruct<i32>>, impl Fn(&mut u32, &u32, &mut u32) -> Option<u32>, u32>> // size = 8, align = 4
// size = 8, align = 4
let mut iter: Iter<Scan<OtherStruct<OtherStruct<i32>>, impl Fn(&mut u32, &u32, &mut u32) -> Option<u32>, u32>>
```
"#]],
);
@ -674,7 +676,8 @@ struct Foo { fiel$0d_a: u8, field_b: i32, field_c: i16 }
```
```rust
field_a: u8 // size = 1, align = 1, offset = 6
// size = 1, align = 1, offset = 6
field_a: u8
```
"#]],
);
@ -699,7 +702,8 @@ fn main() {
```
```rust
field_a: u32 // size = 4, align = 4, offset = 0
// size = 4, align = 4, offset = 0
field_a: u32
```
"#]],
);
@ -721,7 +725,8 @@ fn main() {
```
```rust
field_a: u32 // size = 4, align = 4, offset = 0
// size = 4, align = 4, offset = 0
field_a: u32
```
"#]],
);
@ -848,7 +853,8 @@ fn main() {
*zz*
```rust
let zz: Test<i32> // size = 8, align = 4
// size = 8, align = 4
let zz: Test<i32>
```
"#]],
);
@ -899,7 +905,8 @@ fn main() { let b$0ar = Some(12); }
*bar*
```rust
let bar: Option<i32> // size = 4, align = 4
// size = 4, align = 4
let bar: Option<i32>
```
"#]],
);
@ -968,7 +975,8 @@ fn hover_for_local_variable() {
*foo*
```rust
foo: i32 // size = 4, align = 4
// size = 4, align = 4
foo: i32
```
"#]],
)
@ -982,7 +990,8 @@ fn hover_for_local_variable_pat() {
*foo*
```rust
foo: i32 // size = 4, align = 4
// size = 4, align = 4
foo: i32
```
"#]],
)
@ -996,7 +1005,8 @@ fn hover_local_var_edge() {
*foo*
```rust
foo: i32 // size = 4, align = 4
// size = 4, align = 4
foo: i32
```
"#]],
)
@ -1010,7 +1020,8 @@ fn hover_for_param_edge() {
*foo*
```rust
foo: i32 // size = 4, align = 4
// size = 4, align = 4
foo: i32
```
"#]],
)
@ -1054,7 +1065,8 @@ fn main() { let foo_$0test = Thing::new(); }
*foo_test*
```rust
let foo_test: Thing // size = 4, align = 4
// size = 4, align = 4
let foo_test: Thing
```
"#]],
)
@ -1222,7 +1234,8 @@ fn y() {
*x*
```rust
let x: i32 // size = 4, align = 4
// size = 4, align = 4
let x: i32
```
"#]],
)
@ -1352,7 +1365,8 @@ fn foo(bar:u32) { let a = id!(ba$0r); }
*bar*
```rust
bar: u32 // size = 4, align = 4
// size = 4, align = 4
bar: u32
```
"#]],
);
@ -1370,7 +1384,8 @@ fn foo(bar:u32) { let a = id!(ba$0r); }
*bar*
```rust
bar: u32 // size = 4, align = 4
// size = 4, align = 4
bar: u32
```
"#]],
);
@ -1619,7 +1634,8 @@ fn test_hover_function_pointer_show_identifiers() {
```
```rust
type foo = fn(a: i32, b: i32) -> i32 // size = 8, align = 8, niches = 1
// size = 8, align = 8, niches = 1
type foo = fn(a: i32, b: i32) -> i32
```
"#]],
);
@ -1637,7 +1653,8 @@ fn test_hover_function_pointer_no_identifier() {
```
```rust
type foo = fn(i32, i32) -> i32 // size = 8, align = 8, niches = 1
// size = 8, align = 8, niches = 1
type foo = fn(i32, i32) -> i32
```
"#]],
);
@ -1783,7 +1800,8 @@ fn foo() { let bar = Ba$0r; }
```
```rust
struct Bar // size = 0, align = 1
// size = 0, align = 1
struct Bar
```
---
@ -1819,7 +1837,8 @@ fn foo() { let bar = Ba$0r; }
```
```rust
struct Bar // size = 0, align = 1
// size = 0, align = 1
struct Bar
```
---
@ -1848,7 +1867,8 @@ fn foo() { let bar = Ba$0r; }
```
```rust
struct Bar // size = 0, align = 1
// size = 0, align = 1
struct Bar
```
---
@ -1876,7 +1896,8 @@ pub struct B$0ar
```
```rust
pub struct Bar // size = 0, align = 1
// size = 0, align = 1
pub struct Bar
```
---
@ -1903,7 +1924,8 @@ pub struct B$0ar
```
```rust
pub struct Bar // size = 0, align = 1
// size = 0, align = 1
pub struct Bar
```
---
@ -1992,7 +2014,8 @@ fn test_hover_layout_of_variant() {
```
```rust
Variant1(u8, u16) // size = 4, align = 2
// size = 4, align = 2
Variant1(u8, u16)
```
"#]],
);
@ -2013,10 +2036,11 @@ fn test_hover_layout_of_enum() {
```
```rust
// size = 16 (0x10), align = 8, niches = 254
enum Foo {
Variant1(u8, u16),
Variant2(i32, u8, i64),
} // size = 16 (0x10), align = 8, niches = 254
}
```
"#]],
);
@ -3316,7 +3340,8 @@ fn main() {
*f*
```rust
f: &i32 // size = 8, align = 8, niches = 1
// size = 8, align = 8, niches = 1
f: &i32
```
---
@ -3325,7 +3350,8 @@ fn main() {
```
```rust
f: i32 // size = 4, align = 4, offset = 0
// size = 4, align = 4, offset = 0
f: i32
```
"#]],
);
@ -3409,7 +3435,8 @@ fn main() {
*value*
```rust
let value: Const<1> // size = 0, align = 1
// size = 0, align = 1
let value: Const<1>
```
"#]],
);
@ -3429,7 +3456,8 @@ fn main() {
*value*
```rust
let value: Const<0> // size = 0, align = 1
// size = 0, align = 1
let value: Const<0>
```
"#]],
);
@ -3449,7 +3477,8 @@ fn main() {
*value*
```rust
let value: Const<-1> // size = 0, align = 1
// size = 0, align = 1
let value: Const<-1>
```
"#]],
);
@ -3469,7 +3498,8 @@ fn main() {
*value*
```rust
let value: Const<true> // size = 0, align = 1
// size = 0, align = 1
let value: Const<true>
```
"#]],
);
@ -3489,7 +3519,8 @@ fn main() {
*value*
```rust
let value: Const<'🦀'> // size = 0, align = 1
// size = 0, align = 1
let value: Const<'🦀'>
```
"#]],
);
@ -3508,7 +3539,8 @@ impl Foo {
*self*
```rust
self: &Foo // size = 8, align = 8, niches = 1
// size = 8, align = 8, niches = 1
self: &Foo
```
"#]],
);
@ -3528,7 +3560,8 @@ impl Foo {
*self*
```rust
self: Arc<Foo> // size = 0, align = 1
// size = 0, align = 1
self: Arc<Foo>
```
"#]],
);
@ -3913,7 +3946,8 @@ type Fo$0o2 = Foo<2>;
```
```rust
type Foo2 = Foo<2> // size = 0, align = 1
// size = 0, align = 1
type Foo2 = Foo<2>
```
"#]],
);
@ -3955,7 +3989,8 @@ enum E {
```
```rust
A = 8 // size = 1, align = 1
// size = 1, align = 1
A = 8
```
---
@ -3980,7 +4015,8 @@ enum E {
```
```rust
A = 12 (0xC) // size = 1, align = 1
// size = 1, align = 1
A = 12 (0xC)
```
---
@ -4006,7 +4042,8 @@ enum E {
```
```rust
B = 2 // size = 1, align = 1
// size = 1, align = 1
B = 2
```
---
@ -4032,7 +4069,8 @@ enum E {
```
```rust
B = 5 // size = 1, align = 1
// size = 1, align = 1
B = 5
```
---
@ -4838,7 +4876,8 @@ fn foo(e: E) {
```
```rust
A = 3 // size = 0, align = 1
// size = 0, align = 1
A = 3
```
---
@ -4860,7 +4899,8 @@ fn main() {
*tile4*
```rust
let tile4: [u32; 8] // size = 32 (0x20), align = 4
// size = 32 (0x20), align = 4
let tile4: [u32; 8]
```
"#]],
);
@ -5096,7 +5136,8 @@ pub fn gimme() -> theitem::TheItem {
```
```rust
pub struct TheItem // size = 0, align = 1
// size = 0, align = 1
pub struct TheItem
```
---
@ -5244,7 +5285,8 @@ mod string {
```
```rust
struct String // size = 0, align = 1
// size = 0, align = 1
struct String
```
---
@ -5921,7 +5963,8 @@ foo_macro!(
```
```rust
pub struct Foo // size = 0, align = 1
// size = 0, align = 1
pub struct Foo
```
---
@ -5946,7 +5989,8 @@ pub struct Foo(i32);
```
```rust
pub struct Foo(i32); // size = 4, align = 4
// size = 4, align = 4
pub struct Foo(i32);
```
---
@ -6045,7 +6089,8 @@ enum Enum {
```
```rust
RecordV { field: u32 } // size = 4, align = 4
// size = 4, align = 4
RecordV { field: u32 }
```
"#]],
);
@ -6067,7 +6112,8 @@ enum Enum {
```
```rust
field: u32 // size = 4, align = 4
// size = 4, align = 4
field: u32
```
"#]],
);
@ -6569,7 +6615,8 @@ fn test() {
```
```rust
f: u32 // size = 4, align = 4, offset = 0
// size = 4, align = 4, offset = 0
f: u32
```
"#]],
);
@ -6588,7 +6635,8 @@ fn test() {
*s*
```rust
let s: S // size = 0, align = 1
// size = 0, align = 1
let s: S
```
"#]],
);
@ -6608,7 +6656,8 @@ fn test() {
*foo*
```rust
let foo: i32 // size = 4, align = 4
// size = 4, align = 4
let foo: i32
```
"#]],
);
@ -6628,7 +6677,8 @@ format_args!("{aaaaa$0}");
*aaaaa*
```rust
let aaaaa: &str // size = 16 (0x10), align = 8, niches = 1
// size = 16 (0x10), align = 8, niches = 1
let aaaaa: &str
```
"#]],
);
@ -6648,7 +6698,8 @@ format_args!("{$0aaaaa}");
*aaaaa*
```rust
let aaaaa: &str // size = 16 (0x10), align = 8, niches = 1
// size = 16 (0x10), align = 8, niches = 1
let aaaaa: &str
```
"#]],
);
@ -6668,7 +6719,8 @@ format_args!(r"{$0aaaaa}");
*aaaaa*
```rust
let aaaaa: &str // size = 16 (0x10), align = 8, niches = 1
// size = 16 (0x10), align = 8, niches = 1
let aaaaa: &str
```
"#]],
);
@ -6693,7 +6745,8 @@ foo!(r"{$0aaaaa}");
*aaaaa*
```rust
let aaaaa: &str // size = 16 (0x10), align = 8, niches = 1
// size = 16 (0x10), align = 8, niches = 1
let aaaaa: &str
```
"#]],
);