mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Introduce TypeInfo
This commit is contained in:
parent
29506b5a26
commit
25ff7171c4
32 changed files with 127 additions and 124 deletions
|
@ -1,7 +1,7 @@
|
|||
//! See `CompletionContext` structure.
|
||||
|
||||
use base_db::SourceDatabaseExt;
|
||||
use hir::{Local, Name, ScopeDef, Semantics, SemanticsScope, Type};
|
||||
use hir::{Local, Name, ScopeDef, Semantics, SemanticsScope, Type, TypeInfo};
|
||||
use ide_db::{
|
||||
base_db::{FilePosition, SourceDatabase},
|
||||
call_info::ActiveParameter,
|
||||
|
@ -453,7 +453,8 @@ impl<'a> CompletionContext<'a> {
|
|||
cov_mark::hit!(expected_type_let_without_leading_char);
|
||||
let ty = it.pat()
|
||||
.and_then(|pat| self.sema.type_of_pat(&pat))
|
||||
.or_else(|| it.initializer().and_then(|it| self.sema.type_of_expr(&it)));
|
||||
.or_else(|| it.initializer().and_then(|it| self.sema.type_of_expr(&it)))
|
||||
.map(TypeInfo::ty);
|
||||
let name = if let Some(ast::Pat::IdentPat(ident)) = it.pat() {
|
||||
ident.name().map(NameOrNameRef::Name)
|
||||
} else {
|
||||
|
@ -496,27 +497,27 @@ impl<'a> CompletionContext<'a> {
|
|||
ast::RecordExprField(it) => {
|
||||
cov_mark::hit!(expected_type_struct_field_with_leading_char);
|
||||
(
|
||||
it.expr().as_ref().and_then(|e| self.sema.type_of_expr(e)),
|
||||
it.expr().as_ref().and_then(|e| self.sema.type_of_expr(e)).map(TypeInfo::ty),
|
||||
it.field_name().map(NameOrNameRef::NameRef),
|
||||
)
|
||||
},
|
||||
ast::MatchExpr(it) => {
|
||||
cov_mark::hit!(expected_type_match_arm_without_leading_char);
|
||||
let ty = it.expr()
|
||||
.and_then(|e| self.sema.type_of_expr(&e));
|
||||
let ty = it.expr().and_then(|e| self.sema.type_of_expr(&e)).map(TypeInfo::ty);
|
||||
(ty, None)
|
||||
},
|
||||
ast::IfExpr(it) => {
|
||||
cov_mark::hit!(expected_type_if_let_without_leading_char);
|
||||
let ty = it.condition()
|
||||
.and_then(|cond| cond.expr())
|
||||
.and_then(|e| self.sema.type_of_expr(&e));
|
||||
.and_then(|e| self.sema.type_of_expr(&e))
|
||||
.map(TypeInfo::ty);
|
||||
(ty, None)
|
||||
},
|
||||
ast::IdentPat(it) => {
|
||||
cov_mark::hit!(expected_type_if_let_with_leading_char);
|
||||
cov_mark::hit!(expected_type_match_arm_with_leading_char);
|
||||
let ty = self.sema.type_of_pat(&ast::Pat::from(it));
|
||||
let ty = self.sema.type_of_pat(&ast::Pat::from(it)).map(TypeInfo::ty);
|
||||
(ty, None)
|
||||
},
|
||||
ast::Fn(it) => {
|
||||
|
@ -527,7 +528,7 @@ impl<'a> CompletionContext<'a> {
|
|||
},
|
||||
ast::ClosureExpr(it) => {
|
||||
let ty = self.sema.type_of_expr(&it.into());
|
||||
ty.and_then(|ty| ty.as_callable(self.db))
|
||||
ty.and_then(|ty| ty.ty.as_callable(self.db))
|
||||
.map(|c| (Some(c.return_type()), None))
|
||||
.unwrap_or((None, None))
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue