From 88a15d10d543c09ef66a9f105c3dcdb5011abbee Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 4 Nov 2018 20:21:20 +0300 Subject: use module_for_source --- crates/ra_analysis/src/completion.rs | 4 ++-- crates/ra_analysis/src/descriptors/module/mod.rs | 8 ++------ crates/ra_analysis/src/imp.rs | 8 ++++---- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index 6667c06e7..766df1d96 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs @@ -11,7 +11,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ db::{self, SyntaxDatabase}, descriptors::function::FnScopes, - descriptors::module::{ModuleId, ModuleScope, ModuleTree}, + descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource}, descriptors::DescriptorDatabase, input::FilesDatabase, Cancelable, FileId, @@ -35,7 +35,7 @@ pub(crate) fn resolve_based_completion( let source_root_id = db.file_source_root(file_id); let file = db.file_syntax(file_id); let module_tree = db.module_tree(source_root_id)?; - let module_id = match module_tree.any_module_for_file(file_id) { + let module_id = match module_tree.any_module_for_source(ModuleSource::File(file_id)) { None => return Ok(None), Some(it) => it, }; diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 4e871d16d..13bab0087 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs @@ -34,12 +34,8 @@ impl ModuleTree { .collect() } - pub(crate) fn modules_for_file(&self, file_id: FileId) -> Vec { - self.modules_for_source(ModuleSource::File(file_id)) - } - - pub(crate) fn any_module_for_file(&self, file_id: FileId) -> Option { - self.modules_for_file(file_id).pop() + pub(crate) fn any_module_for_source(&self, source: ModuleSource) -> Option { + self.modules_for_source(source).pop() } } diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 4f337d163..823ac9bdd 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -224,7 +224,7 @@ impl AnalysisImpl { let module_tree = self.module_tree(file_id)?; let res = module_tree - .modules_for_file(file_id) + .modules_for_source(ModuleSource::File(file_id)) .into_iter() .filter_map(|module_id| { let link = module_id.parent_link(&module_tree)?; @@ -252,7 +252,7 @@ impl AnalysisImpl { let module_tree = self.module_tree(file_id)?; let crate_graph = self.db.crate_graph(); let res = module_tree - .modules_for_file(file_id) + .modules_for_source(ModuleSource::File(file_id)) .into_iter() .map(|it| it.root(&module_tree)) .filter_map(|it| it.source(&module_tree).as_file()) @@ -376,7 +376,7 @@ impl AnalysisImpl { fix: None, }) .collect::>(); - if let Some(m) = module_tree.any_module_for_file(file_id) { + if let Some(m) = module_tree.any_module_for_source(ModuleSource::File(file_id)) { for (name_node, problem) in m.problems(&module_tree, &*self.db) { let diag = match problem { Problem::UnresolvedModule { candidate } => { @@ -539,7 +539,7 @@ impl AnalysisImpl { Some(name) => name.text(), None => return Vec::new(), }; - let module_id = match module_tree.any_module_for_file(file_id) { + let module_id = match module_tree.any_module_for_source(ModuleSource::File(file_id)) { Some(id) => id, None => return Vec::new(), }; -- cgit v1.2.3