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 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'crates/ra_analysis/src/completion/complete_dot.rs') 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)?; } -- cgit v1.2.3 From 2dfb5e6ac03e9cc6973dffe9ad69e858510604ee Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 7 Jan 2019 00:03:30 +0100 Subject: Improve types for node_expr / node_pat --- crates/ra_analysis/src/completion/complete_dot.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'crates/ra_analysis/src/completion/complete_dot.rs') diff --git a/crates/ra_analysis/src/completion/complete_dot.rs b/crates/ra_analysis/src/completion/complete_dot.rs index ef3f4271b..54ce1b638 100644 --- a/crates/ra_analysis/src/completion/complete_dot.rs +++ b/crates/ra_analysis/src/completion/complete_dot.rs @@ -1,5 +1,3 @@ -use ra_db::LocalSyntaxPtr; -use ra_syntax::ast::AstNode; use hir::{Ty, Def}; use crate::Cancelable; @@ -13,12 +11,10 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca }; let infer_result = function.infer(ctx.db)?; 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 expr = match syntax_mapping.node_expr(receiver) { + Some(expr) => expr, + None => return Ok(()), + }; let receiver_ty = infer_result[expr].clone(); if !ctx.is_method_call { complete_fields(acc, ctx, receiver_ty)?; -- cgit v1.2.3