mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-27 20:35:09 +00:00
Fix text edits for discriminant hints
This commit is contained in:
parent
f43a37ad25
commit
0f595b07bd
1 changed files with 33 additions and 2 deletions
|
@ -90,7 +90,7 @@ fn variant_hints(
|
|||
kind: InlayKind::Discriminant,
|
||||
label,
|
||||
text_edit: d.ok().map(|val| {
|
||||
config.lazy_text_edit(|| TextEdit::insert(range.start(), format!("{eq_} {val}")))
|
||||
config.lazy_text_edit(|| TextEdit::insert(range.end(), format!("{eq_} {val}")))
|
||||
}),
|
||||
position: InlayHintPosition::After,
|
||||
pad_left: false,
|
||||
|
@ -102,8 +102,10 @@ fn variant_hints(
|
|||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use expect_test::expect;
|
||||
|
||||
use crate::inlay_hints::{
|
||||
tests::{check_with_config, DISABLED_CONFIG},
|
||||
tests::{check_edit, check_with_config, DISABLED_CONFIG},
|
||||
DiscriminantHints, InlayHintsConfig,
|
||||
};
|
||||
|
||||
|
@ -210,4 +212,33 @@ enum Enum {
|
|||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit() {
|
||||
check_edit(
|
||||
InlayHintsConfig { discriminant_hints: DiscriminantHints::Always, ..DISABLED_CONFIG },
|
||||
r#"
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Variant(),
|
||||
Variant1,
|
||||
Variant2 {},
|
||||
Variant3,
|
||||
Variant5,
|
||||
Variant6,
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
#[repr(u8)]
|
||||
enum Enum {
|
||||
Variant() = 0,
|
||||
Variant1 = 1,
|
||||
Variant2 {} = 2,
|
||||
Variant3 = 3,
|
||||
Variant5 = 4,
|
||||
Variant6 = 5,
|
||||
}
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue