diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_dot.rs | 12 | ||||
-rw-r--r-- | crates/ra_analysis/src/hover.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/expr.rs | 10 |
3 files changed, 11 insertions, 15 deletions
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 @@ | |||
1 | use ra_db::LocalSyntaxPtr; | ||
2 | use ra_syntax::ast::AstNode; | ||
3 | use hir::{Ty, Def}; | 1 | use hir::{Ty, Def}; |
4 | 2 | ||
5 | use crate::Cancelable; | 3 | use crate::Cancelable; |
@@ -13,12 +11,10 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca | |||
13 | }; | 11 | }; |
14 | let infer_result = function.infer(ctx.db)?; | 12 | let infer_result = function.infer(ctx.db)?; |
15 | let syntax_mapping = function.body_syntax_mapping(ctx.db)?; | 13 | let syntax_mapping = function.body_syntax_mapping(ctx.db)?; |
16 | let expr = | 14 | let expr = match syntax_mapping.node_expr(receiver) { |
17 | if let Some(expr) = syntax_mapping.syntax_expr(LocalSyntaxPtr::new(receiver.syntax())) { | 15 | Some(expr) => expr, |
18 | expr | 16 | None => return Ok(()), |
19 | } else { | 17 | }; |
20 | return Ok(()); | ||
21 | }; | ||
22 | let receiver_ty = infer_result[expr].clone(); | 18 | let receiver_ty = infer_result[expr].clone(); |
23 | if !ctx.is_method_call { | 19 | if !ctx.is_method_call { |
24 | complete_fields(acc, ctx, receiver_ty)?; | 20 | complete_fields(acc, ctx, receiver_ty)?; |
diff --git a/crates/ra_analysis/src/hover.rs b/crates/ra_analysis/src/hover.rs index 067e5c12d..06632df4f 100644 --- a/crates/ra_analysis/src/hover.rs +++ b/crates/ra_analysis/src/hover.rs | |||
@@ -65,9 +65,9 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable<Option | |||
65 | )?); | 65 | )?); |
66 | let infer = function.infer(db)?; | 66 | let infer = function.infer(db)?; |
67 | let syntax_mapping = function.body_syntax_mapping(db)?; | 67 | let syntax_mapping = function.body_syntax_mapping(db)?; |
68 | if let Some(expr) = syntax_mapping.node_expr(node) { | 68 | if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) { |
69 | Ok(Some(infer[expr].to_string())) | 69 | Ok(Some(infer[expr].to_string())) |
70 | } else if let Some(pat) = syntax_mapping.node_pat(node) { | 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())) | 71 | Ok(Some(infer[pat].to_string())) |
72 | } else { | 72 | } else { |
73 | Ok(None) | 73 | Ok(None) |
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 69144e94f..b0063cad2 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -5,7 +5,7 @@ use rustc_hash::FxHashMap; | |||
5 | 5 | ||
6 | use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; | 6 | use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; |
7 | use ra_db::{LocalSyntaxPtr, Cancelable}; | 7 | use ra_db::{LocalSyntaxPtr, Cancelable}; |
8 | use ra_syntax::{SyntaxNodeRef, ast::{self, AstNode, LoopBodyOwner, ArgListOwner, NameOwner}}; | 8 | use ra_syntax::ast::{self, AstNode, LoopBodyOwner, ArgListOwner, NameOwner}; |
9 | 9 | ||
10 | use crate::{Path, type_ref::{Mutability, TypeRef}, Name, HirDatabase, DefId, Def, name::AsName}; | 10 | use crate::{Path, type_ref::{Mutability, TypeRef}, Name, HirDatabase, DefId, Def, name::AsName}; |
11 | 11 | ||
@@ -77,9 +77,9 @@ impl BodySyntaxMapping { | |||
77 | pub fn syntax_expr(&self, ptr: LocalSyntaxPtr) -> Option<ExprId> { | 77 | pub fn syntax_expr(&self, ptr: LocalSyntaxPtr) -> Option<ExprId> { |
78 | self.expr_syntax_mapping.get(&ptr).cloned() | 78 | self.expr_syntax_mapping.get(&ptr).cloned() |
79 | } | 79 | } |
80 | pub fn node_expr(&self, node: SyntaxNodeRef) -> Option<ExprId> { | 80 | pub fn node_expr(&self, node: ast::Expr) -> Option<ExprId> { |
81 | self.expr_syntax_mapping | 81 | self.expr_syntax_mapping |
82 | .get(&LocalSyntaxPtr::new(node)) | 82 | .get(&LocalSyntaxPtr::new(node.syntax())) |
83 | .cloned() | 83 | .cloned() |
84 | } | 84 | } |
85 | pub fn pat_syntax(&self, pat: PatId) -> Option<LocalSyntaxPtr> { | 85 | pub fn pat_syntax(&self, pat: PatId) -> Option<LocalSyntaxPtr> { |
@@ -88,9 +88,9 @@ impl BodySyntaxMapping { | |||
88 | pub fn syntax_pat(&self, ptr: LocalSyntaxPtr) -> Option<PatId> { | 88 | pub fn syntax_pat(&self, ptr: LocalSyntaxPtr) -> Option<PatId> { |
89 | self.pat_syntax_mapping.get(&ptr).cloned() | 89 | self.pat_syntax_mapping.get(&ptr).cloned() |
90 | } | 90 | } |
91 | pub fn node_pat(&self, node: SyntaxNodeRef) -> Option<PatId> { | 91 | pub fn node_pat(&self, node: ast::Pat) -> Option<PatId> { |
92 | self.pat_syntax_mapping | 92 | self.pat_syntax_mapping |
93 | .get(&LocalSyntaxPtr::new(node)) | 93 | .get(&LocalSyntaxPtr::new(node.syntax())) |
94 | .cloned() | 94 | .cloned() |
95 | } | 95 | } |
96 | 96 | ||