Improve types for node_expr / node_pat
This commit is contained in:
@@ -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)?;
|
||||
|
||||
@@ -65,9 +65,9 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable<Option
|
||||
)?);
|
||||
let infer = function.infer(db)?;
|
||||
let syntax_mapping = function.body_syntax_mapping(db)?;
|
||||
if let Some(expr) = syntax_mapping.node_expr(node) {
|
||||
if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) {
|
||||
Ok(Some(infer[expr].to_string()))
|
||||
} else if let Some(pat) = syntax_mapping.node_pat(node) {
|
||||
} else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) {
|
||||
Ok(Some(infer[pat].to_string()))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
||||
Reference in New Issue
Block a user