Skip to content

Commit

Permalink
Add text edit to discriminant hints
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Oct 23, 2024
1 parent c92f76d commit 49322a1
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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_} ?"),
Expand All @@ -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,
Expand Down

0 comments on commit 49322a1

Please sign in to comment.