mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Add text edit to discriminant hints
This commit is contained in:
parent
fd17fa10a2
commit
bfaad1431b
1 changed files with 6 additions and 5 deletions
|
@ -8,6 +8,7 @@ use hir::Semantics;
|
|||
use ide_db::{famous_defs::FamousDefs, RootDatabase};
|
||||
use span::EditionedFileId;
|
||||
use syntax::ast::{self, AstNode, HasName};
|
||||
use text_edit::TextEdit;
|
||||
|
||||
use crate::{
|
||||
DiscriminantHints, InlayHint, InlayHintLabel, InlayHintPosition, InlayHintsConfig, InlayKind,
|
||||
|
@ -65,11 +66,11 @@ fn variant_hints(
|
|||
let eq_ = if eq_token.is_none() { " =" } else { "" };
|
||||
let label = InlayHintLabel::simple(
|
||||
match d {
|
||||
Ok(x) => {
|
||||
if x >= 10 {
|
||||
format!("{eq_} {x} ({x:#X})")
|
||||
Ok(val) => {
|
||||
if val >= 10 {
|
||||
format!("{eq_} {val} ({val:#X})")
|
||||
} else {
|
||||
format!("{eq_} {x}")
|
||||
format!("{eq_} {val}")
|
||||
}
|
||||
}
|
||||
Err(_) => format!("{eq_} ?"),
|
||||
|
@ -87,7 +88,7 @@ fn variant_hints(
|
|||
},
|
||||
kind: InlayKind::Discriminant,
|
||||
label,
|
||||
text_edit: None,
|
||||
text_edit: d.ok().map(|val| TextEdit::insert(range.start(), format!("{eq_} {val}"))),
|
||||
position: InlayHintPosition::After,
|
||||
pad_left: false,
|
||||
pad_right: false,
|
||||
|
|
Loading…
Reference in a new issue