aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/expr.rs2
-rw-r--r--crates/ra_hir/src/resolve.rs23
-rw-r--r--crates/ra_hir/src/source_binder.rs8
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs14
4 files changed, 20 insertions, 27 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 9262325f2..899e0fa04 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -38,7 +38,7 @@ pub(crate) fn resolver_for_scope(
38 let scopes = owner.expr_scopes(db); 38 let scopes = owner.expr_scopes(db);
39 let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>(); 39 let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>();
40 for scope in scope_chain.into_iter().rev() { 40 for scope in scope_chain.into_iter().rev() {
41 r = r.push_expr_scope(Arc::clone(&scopes), scope); 41 r = r.push_expr_scope(owner, Arc::clone(&scopes), scope);
42 } 42 }
43 r 43 r
44} 44}
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 2f3e12eb8..2fb913108 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -16,8 +16,8 @@ use crate::{
16 expr::{ExprScopes, PatId, ScopeId}, 16 expr::{ExprScopes, PatId, ScopeId},
17 generics::GenericParams, 17 generics::GenericParams,
18 impl_block::ImplBlock, 18 impl_block::ImplBlock,
19 Adt, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, PerNs, Static, Struct, Trait, 19 Adt, Const, DefWithBody, Enum, EnumVariant, Function, Local, MacroDef, ModuleDef, PerNs,
20 TypeAlias, 20 Static, Struct, Trait, TypeAlias,
21}; 21};
22 22
23#[derive(Debug, Clone, Default)] 23#[derive(Debug, Clone, Default)]
@@ -34,6 +34,7 @@ pub(crate) struct ModuleItemMap {
34 34
35#[derive(Debug, Clone)] 35#[derive(Debug, Clone)]
36pub(crate) struct ExprScope { 36pub(crate) struct ExprScope {
37 owner: DefWithBody,
37 expr_scopes: Arc<ExprScopes>, 38 expr_scopes: Arc<ExprScopes>,
38 scope_id: ScopeId, 39 scope_id: ScopeId,
39} 40}
@@ -53,7 +54,7 @@ pub(crate) enum Scope {
53} 54}
54 55
55#[derive(Debug, Clone, PartialEq, Eq, Hash)] 56#[derive(Debug, Clone, PartialEq, Eq, Hash)]
56pub enum TypeNs { 57pub(crate) enum TypeNs {
57 SelfType(ImplBlock), 58 SelfType(ImplBlock),
58 GenericParam(u32), 59 GenericParam(u32),
59 Adt(Adt), 60 Adt(Adt),
@@ -68,13 +69,13 @@ pub enum TypeNs {
68} 69}
69 70
70#[derive(Debug, Clone, PartialEq, Eq, Hash)] 71#[derive(Debug, Clone, PartialEq, Eq, Hash)]
71pub enum ResolveValueResult { 72pub(crate) enum ResolveValueResult {
72 ValueNs(ValueNs), 73 ValueNs(ValueNs),
73 Partial(TypeNs, usize), 74 Partial(TypeNs, usize),
74} 75}
75 76
76#[derive(Debug, Clone, PartialEq, Eq, Hash)] 77#[derive(Debug, Clone, PartialEq, Eq, Hash)]
77pub enum ValueNs { 78pub(crate) enum ValueNs {
78 LocalBinding(PatId), 79 LocalBinding(PatId),
79 Function(Function), 80 Function(Function),
80 Const(Const), 81 Const(Const),
@@ -399,10 +400,11 @@ impl Resolver {
399 400
400 pub(crate) fn push_expr_scope( 401 pub(crate) fn push_expr_scope(
401 self, 402 self,
403 owner: DefWithBody,
402 expr_scopes: Arc<ExprScopes>, 404 expr_scopes: Arc<ExprScopes>,
403 scope_id: ScopeId, 405 scope_id: ScopeId,
404 ) -> Resolver { 406 ) -> Resolver {
405 self.push_scope(Scope::ExprScope(ExprScope { expr_scopes, scope_id })) 407 self.push_scope(Scope::ExprScope(ExprScope { owner, expr_scopes, scope_id }))
406 } 408 }
407} 409}
408 410
@@ -413,7 +415,7 @@ pub enum ScopeDef {
413 GenericParam(u32), 415 GenericParam(u32),
414 ImplSelfType(ImplBlock), 416 ImplSelfType(ImplBlock),
415 AdtSelfType(Adt), 417 AdtSelfType(Adt),
416 LocalBinding(PatId), 418 Local(Local),
417 Unknown, 419 Unknown,
418} 420}
419 421
@@ -467,9 +469,10 @@ impl Scope {
467 Scope::AdtScope(i) => { 469 Scope::AdtScope(i) => {
468 f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i)); 470 f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i));
469 } 471 }
470 Scope::ExprScope(e) => { 472 Scope::ExprScope(scope) => {
471 e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { 473 scope.expr_scopes.entries(scope.scope_id).iter().for_each(|e| {
472 f(e.name().clone(), ScopeDef::LocalBinding(e.pat())); 474 let local = Local { parent: scope.owner, pat_id: e.pat() };
475 f(e.name().clone(), ScopeDef::Local(local));
473 }); 476 });
474 } 477 }
475 } 478 }
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index ca40e3b54..59046edcc 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -195,14 +195,6 @@ impl SourceAnalyzer {
195 Some(self.infer.as_ref()?[pat_id].clone()) 195 Some(self.infer.as_ref()?[pat_id].clone())
196 } 196 }
197 197
198 pub fn type_of_pat_by_id(
199 &self,
200 _db: &impl HirDatabase,
201 pat_id: expr::PatId,
202 ) -> Option<crate::Ty> {
203 Some(self.infer.as_ref()?[pat_id].clone())
204 }
205
206 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { 198 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
207 let expr_id = self.expr_id(&call.clone().into())?; 199 let expr_id = self.expr_id(&call.clone().into())?;
208 self.infer.as_ref()?.method_resolution(expr_id) 200 self.infer.as_ref()?.method_resolution(expr_id)
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index d861303b7..c343cece6 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -68,7 +68,7 @@ impl Completions {
68 ScopeDef::ModuleDef(TypeAlias(..)) => CompletionItemKind::TypeAlias, 68 ScopeDef::ModuleDef(TypeAlias(..)) => CompletionItemKind::TypeAlias,
69 ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType, 69 ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType,
70 ScopeDef::GenericParam(..) => CompletionItemKind::TypeParam, 70 ScopeDef::GenericParam(..) => CompletionItemKind::TypeParam,
71 ScopeDef::LocalBinding(..) => CompletionItemKind::Binding, 71 ScopeDef::Local(..) => CompletionItemKind::Binding,
72 // (does this need its own kind?) 72 // (does this need its own kind?)
73 ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => CompletionItemKind::TypeParam, 73 ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => CompletionItemKind::TypeParam,
74 ScopeDef::MacroDef(mac) => { 74 ScopeDef::MacroDef(mac) => {
@@ -96,13 +96,11 @@ impl Completions {
96 96
97 let mut completion_item = 97 let mut completion_item =
98 CompletionItem::new(completion_kind, ctx.source_range(), local_name.clone()); 98 CompletionItem::new(completion_kind, ctx.source_range(), local_name.clone());
99 if let ScopeDef::LocalBinding(pat_id) = resolution { 99 if let ScopeDef::Local(local) = resolution {
100 let ty = ctx 100 let ty = local.ty(ctx.db);
101 .analyzer 101 if ty != Ty::Unknown {
102 .type_of_pat_by_id(ctx.db, pat_id.clone()) 102 completion_item = completion_item.detail(ty.display(ctx.db).to_string());
103 .filter(|t| t != &Ty::Unknown) 103 }
104 .map(|t| t.display(ctx.db).to_string());
105 completion_item = completion_item.set_detail(ty);
106 }; 104 };
107 105
108 // If not an import, add parenthesis automatically. 106 // If not an import, add parenthesis automatically.