mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Improve types for node_expr / node_pat
This commit is contained in:
parent
71f7d82e45
commit
2dfb5e6ac0
3 changed files with 11 additions and 15 deletions
|
@ -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)
|
||||
|
|
|
@ -5,7 +5,7 @@ use rustc_hash::FxHashMap;
|
|||
|
||||
use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
|
||||
use ra_db::{LocalSyntaxPtr, Cancelable};
|
||||
use ra_syntax::{SyntaxNodeRef, ast::{self, AstNode, LoopBodyOwner, ArgListOwner, NameOwner}};
|
||||
use ra_syntax::ast::{self, AstNode, LoopBodyOwner, ArgListOwner, NameOwner};
|
||||
|
||||
use crate::{Path, type_ref::{Mutability, TypeRef}, Name, HirDatabase, DefId, Def, name::AsName};
|
||||
|
||||
|
@ -77,9 +77,9 @@ impl BodySyntaxMapping {
|
|||
pub fn syntax_expr(&self, ptr: LocalSyntaxPtr) -> Option<ExprId> {
|
||||
self.expr_syntax_mapping.get(&ptr).cloned()
|
||||
}
|
||||
pub fn node_expr(&self, node: SyntaxNodeRef) -> Option<ExprId> {
|
||||
pub fn node_expr(&self, node: ast::Expr) -> Option<ExprId> {
|
||||
self.expr_syntax_mapping
|
||||
.get(&LocalSyntaxPtr::new(node))
|
||||
.get(&LocalSyntaxPtr::new(node.syntax()))
|
||||
.cloned()
|
||||
}
|
||||
pub fn pat_syntax(&self, pat: PatId) -> Option<LocalSyntaxPtr> {
|
||||
|
@ -88,9 +88,9 @@ impl BodySyntaxMapping {
|
|||
pub fn syntax_pat(&self, ptr: LocalSyntaxPtr) -> Option<PatId> {
|
||||
self.pat_syntax_mapping.get(&ptr).cloned()
|
||||
}
|
||||
pub fn node_pat(&self, node: SyntaxNodeRef) -> Option<PatId> {
|
||||
pub fn node_pat(&self, node: ast::Pat) -> Option<PatId> {
|
||||
self.pat_syntax_mapping
|
||||
.get(&LocalSyntaxPtr::new(node))
|
||||
.get(&LocalSyntaxPtr::new(node.syntax()))
|
||||
.cloned()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue