Make most of modules impl private

This commit is contained in:
Aleksey Kladov 2018-11-20 17:16:33 +03:00
parent 0dd26a2f5b
commit a300fb68e2
4 changed files with 20 additions and 21 deletions
crates/ra_analysis/src
descriptors
imp.rs

@ -20,19 +20,19 @@ use crate::{
salsa::query_group! {
pub(crate) trait DescriptorDatabase: SyntaxDatabase + IdDatabase {
fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> {
type ModuleTreeQuery;
use fn module::imp::module_tree;
}
fn module_scope(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<ModuleScope>> {
type ModuleScopeQuery;
use fn module::imp::module_scope;
}
fn fn_scopes(fn_id: FnId) -> Arc<FnScopes> {
type FnScopesQuery;
use fn function::imp::fn_scopes;
}
fn _module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> {
type ModuleTreeQuery;
use fn module::imp::module_tree;
}
fn _module_scope(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<ModuleScope>> {
type ModuleScopeQuery;
use fn module::imp::module_scope;
}
fn _fn_syntax(fn_id: FnId) -> FnDefNode {
type FnSyntaxQuery;
// Don't retain syntax trees in memory

@ -86,7 +86,7 @@ pub(crate) fn module_scope(
source_root_id: SourceRootId,
module_id: ModuleId,
) -> Cancelable<Arc<ModuleScope>> {
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()),

@ -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<Option<ModuleDescriptor>> {
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<Arc<ModuleScope>> {
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,

@ -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<Arc<ModuleTree>> {
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<Vec<(FileId, FileSymbol)>> {
@ -354,7 +350,6 @@ impl AnalysisImpl {
}
pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
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::<Vec<_>>();
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 {