aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-07 00:11:13 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-07 00:11:13 +0000
commitc69bb8a7e737e09c667f9e343d0f1d3e4c13b8f7 (patch)
treed3d006919d15d6a26ff1a8091cf1e5341842c1aa /crates/ra_analysis/src
parent3c945ceb5e0dc287139de0589cc9a4b285911f17 (diff)
parentd618b1f2ce25db8817d1649d7ec7720594789067 (diff)
Merge #446
446: Use HIR Expr for type inference r=flodiebold a=flodiebold Now we can reuse the type inference inside a function when typing whitespace etc. :) The order of the lines in the type tests changed a bit, which I'm not sure why, but there are no actual changes in the inference results. Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/completion/complete_dot.rs10
-rw-r--r--crates/ra_analysis/src/hover.rs9
2 files changed, 13 insertions, 6 deletions
diff --git a/crates/ra_analysis/src/completion/complete_dot.rs b/crates/ra_analysis/src/completion/complete_dot.rs
index 031d8b98f..54ce1b638 100644
--- a/crates/ra_analysis/src/completion/complete_dot.rs
+++ b/crates/ra_analysis/src/completion/complete_dot.rs
@@ -1,4 +1,3 @@
1use ra_syntax::ast::AstNode;
2use hir::{Ty, Def}; 1use hir::{Ty, Def};
3 2
4use crate::Cancelable; 3use crate::Cancelable;
@@ -11,11 +10,12 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca
11 _ => return Ok(()), 10 _ => return Ok(()),
12 }; 11 };
13 let infer_result = function.infer(ctx.db)?; 12 let infer_result = function.infer(ctx.db)?;
14 let receiver_ty = if let Some(ty) = infer_result.type_of_node(receiver.syntax()) { 13 let syntax_mapping = function.body_syntax_mapping(ctx.db)?;
15 ty 14 let expr = match syntax_mapping.node_expr(receiver) {
16 } else { 15 Some(expr) => expr,
17 return Ok(()); 16 None => return Ok(()),
18 }; 17 };
18 let receiver_ty = infer_result[expr].clone();
19 if !ctx.is_method_call { 19 if !ctx.is_method_call {
20 complete_fields(acc, ctx, receiver_ty)?; 20 complete_fields(acc, ctx, receiver_ty)?;
21 } 21 }
diff --git a/crates/ra_analysis/src/hover.rs b/crates/ra_analysis/src/hover.rs
index ba1fb9beb..06632df4f 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<Option
64 parent_fn 64 parent_fn
65 )?); 65 )?);
66 let infer = function.infer(db)?; 66 let infer = function.infer(db)?;
67 Ok(infer.type_of_node(node).map(|t| t.to_string())) 67 let syntax_mapping = function.body_syntax_mapping(db)?;
68 if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) {
69 Ok(Some(infer[expr].to_string()))
70 } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) {
71 Ok(Some(infer[pat].to_string()))
72 } else {
73 Ok(None)
74 }
68} 75}
69 76
70// FIXME: this should not really use navigation target. Rather, approximatelly 77// FIXME: this should not really use navigation target. Rather, approximatelly