mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-15 06:33:58 +00:00
Use Local more
This commit is contained in:
parent
31d01efb06
commit
b80fa14a85
4 changed files with 17 additions and 24 deletions
|
@ -38,7 +38,7 @@ pub(crate) fn resolver_for_scope(
|
||||||
let scopes = owner.expr_scopes(db);
|
let scopes = owner.expr_scopes(db);
|
||||||
let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>();
|
let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>();
|
||||||
for scope in scope_chain.into_iter().rev() {
|
for scope in scope_chain.into_iter().rev() {
|
||||||
r = r.push_expr_scope(Arc::clone(&scopes), scope);
|
r = r.push_expr_scope(owner, Arc::clone(&scopes), scope);
|
||||||
}
|
}
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ use crate::{
|
||||||
expr::{ExprScopes, PatId, ScopeId},
|
expr::{ExprScopes, PatId, ScopeId},
|
||||||
generics::GenericParams,
|
generics::GenericParams,
|
||||||
impl_block::ImplBlock,
|
impl_block::ImplBlock,
|
||||||
Adt, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, PerNs, Static, Struct, Trait,
|
Adt, Const, DefWithBody, Enum, EnumVariant, Function, Local, MacroDef, ModuleDef, PerNs,
|
||||||
TypeAlias,
|
Static, Struct, Trait, TypeAlias,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
|
@ -34,6 +34,7 @@ pub(crate) struct ModuleItemMap {
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct ExprScope {
|
pub(crate) struct ExprScope {
|
||||||
|
owner: DefWithBody,
|
||||||
expr_scopes: Arc<ExprScopes>,
|
expr_scopes: Arc<ExprScopes>,
|
||||||
scope_id: ScopeId,
|
scope_id: ScopeId,
|
||||||
}
|
}
|
||||||
|
@ -399,10 +400,11 @@ impl Resolver {
|
||||||
|
|
||||||
pub(crate) fn push_expr_scope(
|
pub(crate) fn push_expr_scope(
|
||||||
self,
|
self,
|
||||||
|
owner: DefWithBody,
|
||||||
expr_scopes: Arc<ExprScopes>,
|
expr_scopes: Arc<ExprScopes>,
|
||||||
scope_id: ScopeId,
|
scope_id: ScopeId,
|
||||||
) -> Resolver {
|
) -> Resolver {
|
||||||
self.push_scope(Scope::ExprScope(ExprScope { expr_scopes, scope_id }))
|
self.push_scope(Scope::ExprScope(ExprScope { owner, expr_scopes, scope_id }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +415,7 @@ pub enum ScopeDef {
|
||||||
GenericParam(u32),
|
GenericParam(u32),
|
||||||
ImplSelfType(ImplBlock),
|
ImplSelfType(ImplBlock),
|
||||||
AdtSelfType(Adt),
|
AdtSelfType(Adt),
|
||||||
LocalBinding(PatId),
|
Local(Local),
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,9 +469,10 @@ impl Scope {
|
||||||
Scope::AdtScope(i) => {
|
Scope::AdtScope(i) => {
|
||||||
f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i));
|
f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i));
|
||||||
}
|
}
|
||||||
Scope::ExprScope(e) => {
|
Scope::ExprScope(scope) => {
|
||||||
e.expr_scopes.entries(e.scope_id).iter().for_each(|e| {
|
scope.expr_scopes.entries(scope.scope_id).iter().for_each(|e| {
|
||||||
f(e.name().clone(), ScopeDef::LocalBinding(e.pat()));
|
let local = Local { parent: scope.owner, pat_id: e.pat() };
|
||||||
|
f(e.name().clone(), ScopeDef::Local(local));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,14 +195,6 @@ impl SourceAnalyzer {
|
||||||
Some(self.infer.as_ref()?[pat_id].clone())
|
Some(self.infer.as_ref()?[pat_id].clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn type_of_pat_by_id(
|
|
||||||
&self,
|
|
||||||
_db: &impl HirDatabase,
|
|
||||||
pat_id: expr::PatId,
|
|
||||||
) -> Option<crate::Ty> {
|
|
||||||
Some(self.infer.as_ref()?[pat_id].clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
|
pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
|
||||||
let expr_id = self.expr_id(&call.clone().into())?;
|
let expr_id = self.expr_id(&call.clone().into())?;
|
||||||
self.infer.as_ref()?.method_resolution(expr_id)
|
self.infer.as_ref()?.method_resolution(expr_id)
|
||||||
|
|
|
@ -68,7 +68,7 @@ impl Completions {
|
||||||
ScopeDef::ModuleDef(TypeAlias(..)) => CompletionItemKind::TypeAlias,
|
ScopeDef::ModuleDef(TypeAlias(..)) => CompletionItemKind::TypeAlias,
|
||||||
ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType,
|
ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType,
|
||||||
ScopeDef::GenericParam(..) => CompletionItemKind::TypeParam,
|
ScopeDef::GenericParam(..) => CompletionItemKind::TypeParam,
|
||||||
ScopeDef::LocalBinding(..) => CompletionItemKind::Binding,
|
ScopeDef::Local(..) => CompletionItemKind::Binding,
|
||||||
// (does this need its own kind?)
|
// (does this need its own kind?)
|
||||||
ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => CompletionItemKind::TypeParam,
|
ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => CompletionItemKind::TypeParam,
|
||||||
ScopeDef::MacroDef(mac) => {
|
ScopeDef::MacroDef(mac) => {
|
||||||
|
@ -96,13 +96,11 @@ impl Completions {
|
||||||
|
|
||||||
let mut completion_item =
|
let mut completion_item =
|
||||||
CompletionItem::new(completion_kind, ctx.source_range(), local_name.clone());
|
CompletionItem::new(completion_kind, ctx.source_range(), local_name.clone());
|
||||||
if let ScopeDef::LocalBinding(pat_id) = resolution {
|
if let ScopeDef::Local(local) = resolution {
|
||||||
let ty = ctx
|
let ty = local.ty(ctx.db);
|
||||||
.analyzer
|
if ty != Ty::Unknown {
|
||||||
.type_of_pat_by_id(ctx.db, pat_id.clone())
|
completion_item = completion_item.detail(ty.display(ctx.db).to_string());
|
||||||
.filter(|t| t != &Ty::Unknown)
|
}
|
||||||
.map(|t| t.display(ctx.db).to_string());
|
|
||||||
completion_item = completion_item.set_detail(ty);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// If not an import, add parenthesis automatically.
|
// If not an import, add parenthesis automatically.
|
||||||
|
|
Loading…
Reference in a new issue