From e884ab05c216fc4a4a35d6267d08519dc5dda41d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 10:15:10 +0300 Subject: write path resolution code only once --- crates/ra_hir/src/code_model_impl/module.rs | 63 ++--------------------------- 1 file changed, 3 insertions(+), 60 deletions(-) (limited to 'crates/ra_hir/src/code_model_impl/module.rs') diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 6419d3934..a5b190384 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -3,7 +3,7 @@ use ra_syntax::{ast, SyntaxNode, TreeArc}; use crate::{ Module, ModuleSource, Problem, ModuleDef, - Crate, Name, Path, PathKind, PerNs, + Crate, Name, Path, PerNs, module_tree::ModuleId, nameres::{ModuleScope, lower::ImportId}, db::HirDatabase, @@ -97,65 +97,8 @@ impl Module { } pub(crate) fn resolve_path_impl(&self, db: &impl HirDatabase, path: &Path) -> PerNs { - let mut curr_per_ns: PerNs = PerNs::types(match path.kind { - PathKind::Crate => self.crate_root(db).into(), - PathKind::Self_ | PathKind::Plain => self.clone().into(), - PathKind::Super => { - if let Some(p) = self.parent(db) { - p.into() - } else { - return PerNs::none(); - } - } - PathKind::Abs => { - // TODO: absolute use is not supported - return PerNs::none(); - } - }); - - for segment in path.segments.iter() { - let curr = match curr_per_ns.as_ref().take_types() { - Some(r) => r, - None => { - // we still have path segments left, but the path so far - // didn't resolve in the types namespace => no resolution - // (don't break here because curr_per_ns might contain - // something in the value namespace, and it would be wrong - // to return that) - return PerNs::none(); - } - }; - // resolve segment in curr - - curr_per_ns = match curr { - ModuleDef::Module(m) => { - let scope = m.scope(db); - match scope.get(&segment.name) { - Some(r) => r.def_id.clone(), - None => PerNs::none(), - } - } - ModuleDef::Enum(e) => { - // enum variant - let matching_variant = e - .variants(db) - .into_iter() - .find(|(n, _variant)| n == &segment.name); - - match matching_variant { - Some((_n, variant)) => PerNs::both(variant.into(), (*e).into()), - None => PerNs::none(), - } - } - _ => { - // could be an inherent method call in UFCS form - // (`Struct::method`), or some other kind of associated - // item... Which we currently don't handle (TODO) - PerNs::none() - } - }; - } - curr_per_ns + let item_map = db.item_map(self.krate); + item_map.resolve_path(db, *self, path) } pub(crate) fn problems_impl( -- cgit v1.2.3 From ed27bd8d776e7efd4394d6cdda02aa7f93c48273 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 10:20:35 +0300 Subject: remove useless wrapper --- crates/ra_hir/src/code_model_impl/module.rs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'crates/ra_hir/src/code_model_impl/module.rs') diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index a5b190384..bf0e212ca 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -96,11 +96,6 @@ impl Module { item_map.per_module[&self.module_id].clone() } - pub(crate) fn resolve_path_impl(&self, db: &impl HirDatabase, path: &Path) -> PerNs { - let item_map = db.item_map(self.krate); - item_map.resolve_path(db, *self, path) - } - pub(crate) fn problems_impl( &self, db: &impl HirDatabase, -- cgit v1.2.3 From 74beb5bfcbc33d6232a9b08b4df4bcfd781790e9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 10:29:00 +0300 Subject: simplify --- crates/ra_hir/src/code_model_impl/module.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir/src/code_model_impl/module.rs') diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index bf0e212ca..480ec27bf 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -2,10 +2,10 @@ use ra_db::FileId; use ra_syntax::{ast, SyntaxNode, TreeArc}; use crate::{ - Module, ModuleSource, Problem, ModuleDef, - Crate, Name, Path, PerNs, + Module, ModuleSource, Problem, + Crate, Name, module_tree::ModuleId, - nameres::{ModuleScope, lower::ImportId}, + nameres::{lower::ImportId}, db::HirDatabase, }; @@ -90,12 +90,6 @@ impl Module { Some(self.with_module_id(parent_id)) } - /// Returns a `ModuleScope`: a set of items, visible in this module. - pub(crate) fn scope_impl(&self, db: &impl HirDatabase) -> ModuleScope { - let item_map = db.item_map(self.krate); - item_map.per_module[&self.module_id].clone() - } - pub(crate) fn problems_impl( &self, db: &impl HirDatabase, -- cgit v1.2.3