From 6210e82041849bad6129331b9e45ac0bae6fe569 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 6 Jan 2019 16:47:59 +0100 Subject: Use HIR Expr for type inference Now we can reuse the type inference inside a function when typing whitespace etc. :) --- crates/ra_analysis/src/completion/complete_dot.rs | 14 +++++++++----- crates/ra_analysis/src/hover.rs | 9 ++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'crates/ra_analysis') diff --git a/crates/ra_analysis/src/completion/complete_dot.rs b/crates/ra_analysis/src/completion/complete_dot.rs index 031d8b98f..ef3f4271b 100644 --- a/crates/ra_analysis/src/completion/complete_dot.rs +++ b/crates/ra_analysis/src/completion/complete_dot.rs @@ -1,3 +1,4 @@ +use ra_db::LocalSyntaxPtr; use ra_syntax::ast::AstNode; use hir::{Ty, Def}; @@ -11,11 +12,14 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca _ => return Ok(()), }; let infer_result = function.infer(ctx.db)?; - let receiver_ty = if let Some(ty) = infer_result.type_of_node(receiver.syntax()) { - ty - } else { - return Ok(()); - }; + let syntax_mapping = function.body_syntax_mapping(ctx.db)?; + let expr = + if let Some(expr) = syntax_mapping.syntax_expr(LocalSyntaxPtr::new(receiver.syntax())) { + expr + } else { + return Ok(()); + }; + let receiver_ty = infer_result[expr].clone(); if !ctx.is_method_call { complete_fields(acc, ctx, receiver_ty)?; } diff --git a/crates/ra_analysis/src/hover.rs b/crates/ra_analysis/src/hover.rs index ba1fb9beb..067e5c12d 100644 --- a/crates/ra_analysis/src/hover.rs +++ b/crates/ra_analysis/src/hover.rs @@ -64,7 +64,14 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable