mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
show values of constants in hover
This commit is contained in:
parent
4ea1f58bf6
commit
e6139cf47b
4 changed files with 406 additions and 7 deletions
|
@ -31,7 +31,7 @@ pub mod db;
|
|||
|
||||
mod display;
|
||||
|
||||
use std::{iter, ops::ControlFlow, sync::Arc};
|
||||
use std::{collections::HashMap, iter, ops::ControlFlow, sync::Arc};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId};
|
||||
|
@ -50,7 +50,7 @@ use hir_def::{
|
|||
use hir_expand::{name::name, MacroCallKind, MacroDefKind};
|
||||
use hir_ty::{
|
||||
autoderef,
|
||||
consteval::ConstExt,
|
||||
consteval::{eval_const, ComputedExpr, ConstEvalCtx, ConstEvalError, ConstExt},
|
||||
could_unify,
|
||||
diagnostics::BodyValidationDiagnostic,
|
||||
method_resolution::{self, TyFingerprint},
|
||||
|
@ -1532,6 +1532,23 @@ impl Const {
|
|||
let ty = ctx.lower_ty(&data.type_ref);
|
||||
Type::new_with_resolver_inner(db, krate.id, &resolver, ty)
|
||||
}
|
||||
|
||||
pub fn eval(self, db: &dyn HirDatabase) -> Result<ComputedExpr, ConstEvalError> {
|
||||
let body = db.body(self.id.into());
|
||||
let root = &body.exprs[body.body_expr];
|
||||
let infer = db.infer_query(self.id.into());
|
||||
let infer = infer.as_ref();
|
||||
let result = eval_const(
|
||||
root,
|
||||
ConstEvalCtx {
|
||||
exprs: &body.exprs,
|
||||
pats: &body.pats,
|
||||
local_data: HashMap::default(),
|
||||
infer,
|
||||
},
|
||||
);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl HasVisibility for Const {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue