From 62d01dd4dfc8feb52c006b84f9d1a1a7142cc060 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 13 Apr 2019 11:00:15 +0300 Subject: hide resolver --- crates/ra_hir/src/source_binder.rs | 20 ++++++++++++++------ crates/ra_ide_api/src/completion/complete_path.rs | 2 +- crates/ra_ide_api/src/completion/complete_pattern.rs | 2 +- crates/ra_ide_api/src/completion/complete_scope.rs | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) (limited to 'crates') 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 @@ /// purely for "IDE needs". use std::sync::Arc; -use rustc_hash::FxHashSet; +use rustc_hash::{FxHashSet, FxHashMap}; use ra_db::{FileId, FilePosition}; use ra_syntax::{ SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, @@ -17,7 +17,7 @@ use ra_syntax::{ }; use crate::{ - HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, + HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name, AsName, Module, HirFileId, Crate, Trait, Resolver, expr::{BodySourceMap, scope::{ReferenceDescriptor, ScopeEntryWithSyntax, ScopeId, ExprScopes}}, ids::LocationCtx, @@ -222,10 +222,6 @@ impl SourceAnalyzer { } } - pub fn resolver(&self) -> &Resolver { - &self.resolver - } - pub fn type_of(&self, _db: &impl HirDatabase, expr: &ast::Expr) -> Option { let expr_id = self.body_source_map.as_ref()?.node_expr(expr)?; Some(self.infer.as_ref()?[expr_id].clone()) @@ -246,6 +242,18 @@ impl SourceAnalyzer { self.infer.as_ref()?.field_resolution(expr_id) } + pub fn resolve_hir_path( + &self, + db: &impl HirDatabase, + path: &crate::Path, + ) -> PerNs { + self.resolver.resolve_path(db, path) + } + + pub fn all_names(&self, db: &impl HirDatabase) -> FxHashMap> { + self.resolver.all_names(db) + } + pub fn resolve_path(&self, db: &impl HirDatabase, path: &ast::Path) -> Option { if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) { 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) { Some(path) => path.clone(), _ => return, }; - let def = match ctx.analyzer.resolver().resolve_path(ctx.db, &path).take_types() { + let def = match ctx.analyzer.resolve_hir_path(ctx.db, &path).take_types() { Some(Resolution::Def(def)) => def, _ => return, }; 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) { } // FIXME: ideally, we should look at the type we are matching against and // suggest variants + auto-imports - let names = ctx.analyzer.resolver().all_names(ctx.db); + let names = ctx.analyzer.all_names(ctx.db); for (name, res) in names.into_iter() { let r = res.as_ref(); 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) { if !ctx.is_trivial_path { return; } - let names = ctx.analyzer.resolver().all_names(ctx.db); + let names = ctx.analyzer.all_names(ctx.db); names.into_iter().for_each(|(name, res)| acc.add_resolution(ctx, name.to_string(), &res)); } -- cgit v1.2.3