mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Bring back the hex in const hover
This commit is contained in:
parent
e6ba791dce
commit
ae8ce99d97
4 changed files with 66 additions and 12 deletions
|
@ -5,7 +5,7 @@
|
|||
use std::fmt::{self, Debug};
|
||||
|
||||
use base_db::CrateId;
|
||||
use chalk_ir::BoundVar;
|
||||
use chalk_ir::{BoundVar, TyKind};
|
||||
use hir_def::{
|
||||
adt::VariantData,
|
||||
body,
|
||||
|
@ -36,7 +36,7 @@ use crate::{
|
|||
AdtId, AliasEq, AliasTy, Binders, CallableDefId, CallableSig, Const, ConstScalar, ConstValue,
|
||||
DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives,
|
||||
MemoryMap, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, QuantifiedWhereClause, Scalar,
|
||||
Substitution, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause,
|
||||
Substitution, TraitRef, TraitRefExt, Ty, TyExt, WhereClause,
|
||||
};
|
||||
|
||||
pub trait HirWrite: fmt::Write {
|
||||
|
@ -383,6 +383,28 @@ impl HirDisplay for Const {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct HexifiedConst(pub Const);
|
||||
|
||||
impl HirDisplay for HexifiedConst {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
||||
let data = &self.0.data(Interner);
|
||||
if let TyKind::Scalar(s) = data.ty.kind(Interner) {
|
||||
if matches!(s, Scalar::Int(_) | Scalar::Uint(_)) {
|
||||
if let ConstValue::Concrete(c) = &data.value {
|
||||
if let ConstScalar::Bytes(b, m) = &c.interned {
|
||||
let value = u128::from_le_bytes(pad16(b, false));
|
||||
if value >= 10 {
|
||||
render_const_scalar(f, &b, m, &data.ty)?;
|
||||
return write!(f, " ({:#X})", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.0.hir_fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
fn render_const_scalar(
|
||||
f: &mut HirFormatter<'_>,
|
||||
b: &[u8],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue