Introduce TypeInfo

This commit is contained in:
Lukas Wirth 2021-08-02 20:42:25 +02:00
parent 29506b5a26
commit 25ff7171c4
32 changed files with 127 additions and 124 deletions

View file

@ -1,5 +1,5 @@
use either::Either;
use hir::{known, Callable, HasVisibility, HirDisplay, Semantics};
use hir::{known, Callable, HasVisibility, HirDisplay, Semantics, TypeInfo};
use ide_db::helpers::FamousDefs;
use ide_db::RootDatabase;
use stdx::to_lower_snake_case;
@ -117,7 +117,7 @@ fn get_chaining_hints(
next_next = tokens.next()?.kind();
}
if next_next == T![.] {
let ty = sema.type_of_expr(&expr)?;
let ty = sema.type_of_expr(&expr)?.ty;
if ty.is_unknown() {
return None;
}
@ -189,7 +189,7 @@ fn get_bind_pat_hints(
let krate = sema.scope(pat.syntax()).module().map(|it| it.krate());
let famous_defs = FamousDefs(sema, krate);
let ty = sema.type_of_pat(&pat.clone().into())?;
let ty = sema.type_of_pat(&pat.clone().into())?.ty;
if should_not_display_type_hint(sema, &pat, &ty) {
return None;
@ -308,6 +308,7 @@ fn should_not_display_type_hint(
return it.in_token().is_none() ||
it.iterable()
.and_then(|iterable_expr| sema.type_of_expr(&iterable_expr))
.map(TypeInfo::ty)
.map_or(true, |iterable_ty| iterable_ty.is_unknown() || iterable_ty.is_unit())
},
_ => (),
@ -393,7 +394,7 @@ fn is_enum_name_similar_to_param_name(
argument: &ast::Expr,
param_name: &str,
) -> bool {
match sema.type_of_expr(argument).and_then(|t| t.as_adt()) {
match sema.type_of_expr(argument).and_then(|t| t.ty.as_adt()) {
Some(hir::Adt::Enum(e)) => to_lower_snake_case(&e.name(sema.db).to_string()) == param_name,
_ => false,
}
@ -430,7 +431,7 @@ fn get_callable(
) -> Option<(hir::Callable, ast::ArgList)> {
match expr {
ast::Expr::CallExpr(expr) => {
sema.type_of_expr(&expr.expr()?)?.as_callable(sema.db).zip(expr.arg_list())
sema.type_of_expr(&expr.expr()?)?.ty.as_callable(sema.db).zip(expr.arg_list())
}
ast::Expr::MethodCallExpr(expr) => {
sema.resolve_method_call_as_callable(expr).zip(expr.arg_list())