diff options
author | Aleksey Kladov <[email protected]> | 2019-04-13 09:00:15 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-04-13 09:00:15 +0100 |
commit | 62d01dd4dfc8feb52c006b84f9d1a1a7142cc060 (patch) | |
tree | 82c6e8b1b51f5a0de63e038fd6d872cd39882015 /crates | |
parent | f4a94e74bcd6c8f9275a57a775e64314af1878da (diff) |
hide resolver
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 20 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_pattern.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_scope.rs | 2 |
4 files changed, 17 insertions, 9 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index d87f8ff34..b5e2f86be 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -7,7 +7,7 @@ | |||
7 | /// purely for "IDE needs". | 7 | /// purely for "IDE needs". |
8 | use std::sync::Arc; | 8 | use std::sync::Arc; |
9 | 9 | ||
10 | use rustc_hash::FxHashSet; | 10 | use rustc_hash::{FxHashSet, FxHashMap}; |
11 | use ra_db::{FileId, FilePosition}; | 11 | use ra_db::{FileId, FilePosition}; |
12 | use ra_syntax::{ | 12 | use ra_syntax::{ |
13 | SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, | 13 | SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, |
@@ -17,7 +17,7 @@ use ra_syntax::{ | |||
17 | }; | 17 | }; |
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, | 20 | HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name, |
21 | AsName, Module, HirFileId, Crate, Trait, Resolver, | 21 | AsName, Module, HirFileId, Crate, Trait, Resolver, |
22 | expr::{BodySourceMap, scope::{ReferenceDescriptor, ScopeEntryWithSyntax, ScopeId, ExprScopes}}, | 22 | expr::{BodySourceMap, scope::{ReferenceDescriptor, ScopeEntryWithSyntax, ScopeId, ExprScopes}}, |
23 | ids::LocationCtx, | 23 | ids::LocationCtx, |
@@ -222,10 +222,6 @@ impl SourceAnalyzer { | |||
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | pub fn resolver(&self) -> &Resolver { | ||
226 | &self.resolver | ||
227 | } | ||
228 | |||
229 | pub fn type_of(&self, _db: &impl HirDatabase, expr: &ast::Expr) -> Option<crate::Ty> { | 225 | pub fn type_of(&self, _db: &impl HirDatabase, expr: &ast::Expr) -> Option<crate::Ty> { |
230 | let expr_id = self.body_source_map.as_ref()?.node_expr(expr)?; | 226 | let expr_id = self.body_source_map.as_ref()?.node_expr(expr)?; |
231 | Some(self.infer.as_ref()?[expr_id].clone()) | 227 | Some(self.infer.as_ref()?[expr_id].clone()) |
@@ -246,6 +242,18 @@ impl SourceAnalyzer { | |||
246 | self.infer.as_ref()?.field_resolution(expr_id) | 242 | self.infer.as_ref()?.field_resolution(expr_id) |
247 | } | 243 | } |
248 | 244 | ||
245 | pub fn resolve_hir_path( | ||
246 | &self, | ||
247 | db: &impl HirDatabase, | ||
248 | path: &crate::Path, | ||
249 | ) -> PerNs<crate::Resolution> { | ||
250 | self.resolver.resolve_path(db, path) | ||
251 | } | ||
252 | |||
253 | pub fn all_names(&self, db: &impl HirDatabase) -> FxHashMap<Name, PerNs<crate::Resolution>> { | ||
254 | self.resolver.all_names(db) | ||
255 | } | ||
256 | |||
249 | pub fn resolve_path(&self, db: &impl HirDatabase, path: &ast::Path) -> Option<PathResolution> { | 257 | pub fn resolve_path(&self, db: &impl HirDatabase, path: &ast::Path) -> Option<PathResolution> { |
250 | if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) { | 258 | if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) { |
251 | let expr_id = self.body_source_map.as_ref()?.node_expr(path_expr.into())?; | 259 | let expr_id = self.body_source_map.as_ref()?.node_expr(path_expr.into())?; |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index e9bdf5af2..bc03a7095 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -9,7 +9,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
9 | Some(path) => path.clone(), | 9 | Some(path) => path.clone(), |
10 | _ => return, | 10 | _ => return, |
11 | }; | 11 | }; |
12 | let def = match ctx.analyzer.resolver().resolve_path(ctx.db, &path).take_types() { | 12 | let def = match ctx.analyzer.resolve_hir_path(ctx.db, &path).take_types() { |
13 | Some(Resolution::Def(def)) => def, | 13 | Some(Resolution::Def(def)) => def, |
14 | _ => return, | 14 | _ => return, |
15 | }; | 15 | }; |
diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs index abbb83518..0ef248687 100644 --- a/crates/ra_ide_api/src/completion/complete_pattern.rs +++ b/crates/ra_ide_api/src/completion/complete_pattern.rs | |||
@@ -7,7 +7,7 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { | |||
7 | } | 7 | } |
8 | // FIXME: ideally, we should look at the type we are matching against and | 8 | // FIXME: ideally, we should look at the type we are matching against and |
9 | // suggest variants + auto-imports | 9 | // suggest variants + auto-imports |
10 | let names = ctx.analyzer.resolver().all_names(ctx.db); | 10 | let names = ctx.analyzer.all_names(ctx.db); |
11 | for (name, res) in names.into_iter() { | 11 | for (name, res) in names.into_iter() { |
12 | let r = res.as_ref(); | 12 | let r = res.as_ref(); |
13 | let def = match r.take_types().or(r.take_values()) { | 13 | let def = match r.take_types().or(r.take_values()) { |
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 4c5d07ce5..fd256fc3b 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs | |||
@@ -4,7 +4,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { | |||
4 | if !ctx.is_trivial_path { | 4 | if !ctx.is_trivial_path { |
5 | return; | 5 | return; |
6 | } | 6 | } |
7 | let names = ctx.analyzer.resolver().all_names(ctx.db); | 7 | let names = ctx.analyzer.all_names(ctx.db); |
8 | 8 | ||
9 | names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res)); | 9 | names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res)); |
10 | } | 10 | } |