Give TypeInfo fields and methods more appropriate names

This commit is contained in:
Lukas Wirth 2021-08-03 17:28:51 +02:00
parent 8afa2722b2
commit b96f1adf5c
30 changed files with 76 additions and 74 deletions

View file

@ -225,29 +225,29 @@ fn hover_type_info(
config: &HoverConfig,
expr_or_pat: &Either<ast::Expr, ast::Pat>,
) -> Option<HoverResult> {
let TypeInfo { ty, coerced } = match expr_or_pat {
let TypeInfo { original, adjusted } = match expr_or_pat {
Either::Left(expr) => sema.type_of_expr(expr)?,
Either::Right(pat) => sema.type_of_pat(pat)?,
};
let mut res = HoverResult::default();
res.markup = if let Some(coerced_ty) = coerced {
let uncoerced = ty.display(sema.db).to_string();
let coerced = coerced_ty.display(sema.db).to_string();
res.markup = if let Some(adjusted_ty) = adjusted {
let original = original.display(sema.db).to_string();
let adjusted = adjusted_ty.display(sema.db).to_string();
format!(
"```text\nType: {:>upad$}\nCoerced to: {:>cpad$}\n```\n",
uncoerced = uncoerced,
coerced = coerced,
"```text\nType: {:>apad$}\nCoerced to: {:>opad$}\n```\n",
uncoerced = original,
coerced = adjusted,
// 6 base padding for static text prefix of each line
upad = 6 + coerced.len().max(uncoerced.len()),
cpad = uncoerced.len(),
apad = 6 + adjusted.len().max(original.len()),
opad = original.len(),
)
.into()
} else {
if config.markdown() {
Markup::fenced_block(&ty.display(sema.db))
Markup::fenced_block(&original.display(sema.db))
} else {
ty.display(sema.db).to_string().into()
original.display(sema.db).to_string().into()
}
};
Some(res)