aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-04 17:21:20 +0000
committerAleksey Kladov <[email protected]>2018-11-05 09:36:38 +0000
commit88a15d10d543c09ef66a9f105c3dcdb5011abbee (patch)
tree773470eb035991ba0e137cc8b863179674d9b94f /crates/ra_analysis/src
parentcd878658d3072ee0741cd04c16d330e7d5907f94 (diff)
use module_for_source
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/completion.rs4
-rw-r--r--crates/ra_analysis/src/descriptors/module/mod.rs8
-rw-r--r--crates/ra_analysis/src/imp.rs8
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};
11use crate::{ 11use crate::{
12 db::{self, SyntaxDatabase}, 12 db::{self, SyntaxDatabase},
13 descriptors::function::FnScopes, 13 descriptors::function::FnScopes,
14 descriptors::module::{ModuleId, ModuleScope, ModuleTree}, 14 descriptors::module::{ModuleId, ModuleScope, ModuleTree, ModuleSource},
15 descriptors::DescriptorDatabase, 15 descriptors::DescriptorDatabase,
16 input::FilesDatabase, 16 input::FilesDatabase,
17 Cancelable, FileId, 17 Cancelable, FileId,
@@ -35,7 +35,7 @@ pub(crate) fn resolve_based_completion(
35 let source_root_id = db.file_source_root(file_id); 35 let source_root_id = db.file_source_root(file_id);
36 let file = db.file_syntax(file_id); 36 let file = db.file_syntax(file_id);
37 let module_tree = db.module_tree(source_root_id)?; 37 let module_tree = db.module_tree(source_root_id)?;
38 let module_id = match module_tree.any_module_for_file(file_id) { 38 let module_id = match module_tree.any_module_for_source(ModuleSource::File(file_id)) {
39 None => return Ok(None), 39 None => return Ok(None),
40 Some(it) => it, 40 Some(it) => it,
41 }; 41 };
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 {
34 .collect() 34 .collect()
35 } 35 }
36 36
37 pub(crate) fn modules_for_file(&self, file_id: FileId) -> Vec<ModuleId> { 37 pub(crate) fn any_module_for_source(&self, source: ModuleSource) -> Option<ModuleId> {
38 self.modules_for_source(ModuleSource::File(file_id)) 38 self.modules_for_source(source).pop()
39 }
40
41 pub(crate) fn any_module_for_file(&self, file_id: FileId) -> Option<ModuleId> {
42 self.modules_for_file(file_id).pop()
43 } 39 }
44} 40}
45 41
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 {
224 let module_tree = self.module_tree(file_id)?; 224 let module_tree = self.module_tree(file_id)?;
225 225
226 let res = module_tree 226 let res = module_tree
227 .modules_for_file(file_id) 227 .modules_for_source(ModuleSource::File(file_id))
228 .into_iter() 228 .into_iter()
229 .filter_map(|module_id| { 229 .filter_map(|module_id| {
230 let link = module_id.parent_link(&module_tree)?; 230 let link = module_id.parent_link(&module_tree)?;
@@ -252,7 +252,7 @@ impl AnalysisImpl {
252 let module_tree = self.module_tree(file_id)?; 252 let module_tree = self.module_tree(file_id)?;
253 let crate_graph = self.db.crate_graph(); 253 let crate_graph = self.db.crate_graph();
254 let res = module_tree 254 let res = module_tree
255 .modules_for_file(file_id) 255 .modules_for_source(ModuleSource::File(file_id))
256 .into_iter() 256 .into_iter()
257 .map(|it| it.root(&module_tree)) 257 .map(|it| it.root(&module_tree))
258 .filter_map(|it| it.source(&module_tree).as_file()) 258 .filter_map(|it| it.source(&module_tree).as_file())
@@ -376,7 +376,7 @@ impl AnalysisImpl {
376 fix: None, 376 fix: None,
377 }) 377 })
378 .collect::<Vec<_>>(); 378 .collect::<Vec<_>>();
379 if let Some(m) = module_tree.any_module_for_file(file_id) { 379 if let Some(m) = module_tree.any_module_for_source(ModuleSource::File(file_id)) {
380 for (name_node, problem) in m.problems(&module_tree, &*self.db) { 380 for (name_node, problem) in m.problems(&module_tree, &*self.db) {
381 let diag = match problem { 381 let diag = match problem {
382 Problem::UnresolvedModule { candidate } => { 382 Problem::UnresolvedModule { candidate } => {
@@ -539,7 +539,7 @@ impl AnalysisImpl {
539 Some(name) => name.text(), 539 Some(name) => name.text(),
540 None => return Vec::new(), 540 None => return Vec::new(),
541 }; 541 };
542 let module_id = match module_tree.any_module_for_file(file_id) { 542 let module_id = match module_tree.any_module_for_source(ModuleSource::File(file_id)) {
543 Some(id) => id, 543 Some(id) => id,
544 None => return Vec::new(), 544 None => return Vec::new(),
545 }; 545 };