From a300fb68e25ea0cbf2cfba38968a40674cd4c805 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Nov 2018 17:16:33 +0300 Subject: Make most of modules impl private --- crates/ra_analysis/src/descriptors/mod.rs | 14 +++++++------- crates/ra_analysis/src/descriptors/module/imp.rs | 2 +- crates/ra_analysis/src/descriptors/module/mod.rs | 12 ++++++++---- crates/ra_analysis/src/imp.rs | 11 +++-------- 4 files changed, 19 insertions(+), 20 deletions(-) (limited to 'crates') diff --git a/crates/ra_analysis/src/descriptors/mod.rs b/crates/ra_analysis/src/descriptors/mod.rs index f47ac49c5..a8489f89c 100644 --- a/crates/ra_analysis/src/descriptors/mod.rs +++ b/crates/ra_analysis/src/descriptors/mod.rs @@ -20,19 +20,19 @@ use crate::{ salsa::query_group! { pub(crate) trait DescriptorDatabase: SyntaxDatabase + IdDatabase { - fn module_tree(source_root_id: SourceRootId) -> Cancelable> { + fn fn_scopes(fn_id: FnId) -> Arc { + type FnScopesQuery; + use fn function::imp::fn_scopes; + } + + fn _module_tree(source_root_id: SourceRootId) -> Cancelable> { type ModuleTreeQuery; use fn module::imp::module_tree; } - fn module_scope(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable> { + fn _module_scope(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable> { type ModuleScopeQuery; use fn module::imp::module_scope; } - fn fn_scopes(fn_id: FnId) -> Arc { - type FnScopesQuery; - use fn function::imp::fn_scopes; - } - fn _fn_syntax(fn_id: FnId) -> FnDefNode { type FnSyntaxQuery; // Don't retain syntax trees in memory diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs index ec0885938..defe87216 100644 --- a/crates/ra_analysis/src/descriptors/module/imp.rs +++ b/crates/ra_analysis/src/descriptors/module/imp.rs @@ -86,7 +86,7 @@ pub(crate) fn module_scope( source_root_id: SourceRootId, module_id: ModuleId, ) -> Cancelable> { - let tree = db.module_tree(source_root_id)?; + let tree = db._module_tree(source_root_id)?; let source = module_id.source(&tree).resolve(db); let res = match source { ModuleSourceNode::SourceFile(it) => ModuleScope::new(it.borrowed().items()), diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index a894025ed..ff7afe16e 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs @@ -8,7 +8,7 @@ use ra_editor::find_node_at_offset; use ra_syntax::{ algo::generate, ast::{self, AstNode, NameOwner}, - SmolStr, SyntaxNode, SyntaxNodeRef, + SmolStr, SyntaxNode, }; use relative_path::RelativePathBuf; @@ -62,7 +62,7 @@ impl ModuleDescriptor { module_source: ModuleSource, ) -> Cancelable> { let source_root_id = db.file_source_root(file_id); - let module_tree = db.module_tree(source_root_id)?; + let module_tree = db._module_tree(source_root_id)?; let res = match module_tree.any_module_for_source(module_source) { None => None, @@ -124,7 +124,11 @@ impl ModuleDescriptor { /// Returns a `ModuleScope`: a set of items, visible in this module. pub fn scope(&self, db: &impl DescriptorDatabase) -> Cancelable> { - db.module_scope(self.source_root_id, self.module_id) + db._module_scope(self.source_root_id, self.module_id) + } + + pub fn problems(&self, db: &impl DescriptorDatabase) -> Vec<(SyntaxNode, Problem)> { + self.module_id.problems(&self.tree, db) } } @@ -209,7 +213,7 @@ impl ModuleId { .find(|it| it.name == name)?; Some(*link.points_to.first()?) } - pub(crate) fn problems( + fn problems( self, tree: &ModuleTree, db: &impl SyntaxDatabase, diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 1bbf0cb6d..61296215c 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -21,7 +21,7 @@ use crate::{ db::{self, FileSyntaxQuery, SyntaxDatabase}, descriptors::{ function::{FnDescriptor, FnId}, - module::{ModuleDescriptor, ModuleSource, ModuleTree, Problem}, + module::{ModuleDescriptor, Problem}, DeclarationDescriptor, DescriptorDatabase, }, input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, @@ -216,10 +216,6 @@ impl AnalysisImpl { .sweep(salsa::SweepStrategy::default().discard_values()); Ok(query.search(&buf)) } - fn module_tree(&self, file_id: FileId) -> Cancelable> { - let source_root = self.db.file_source_root(file_id); - self.db.module_tree(source_root) - } /// This return `Vec`: a module may be inclucded from several places. /// We don't handle this case yet though, so the Vec has length at most one. pub fn parent_module(&self, position: FilePosition) -> Cancelable> { @@ -354,7 +350,6 @@ impl AnalysisImpl { } pub fn diagnostics(&self, file_id: FileId) -> Cancelable> { - let module_tree = self.module_tree(file_id)?; let syntax = self.db.file_syntax(file_id); let mut res = ra_editor::diagnostics(&syntax) @@ -365,8 +360,8 @@ impl AnalysisImpl { fix: None, }) .collect::>(); - if let Some(m) = module_tree.any_module_for_source(ModuleSource::SourceFile(file_id)) { - for (name_node, problem) in m.problems(&module_tree, &*self.db) { + if let Some(m) = ModuleDescriptor::guess_from_file_id(&*self.db, file_id)? { + for (name_node, problem) in m.problems(&*self.db) { let diag = match problem { Problem::UnresolvedModule { candidate } => { let create_file = FileSystemEdit::CreateFile { -- cgit v1.2.3