remove Cancelable from module_tree_query

This commit is contained in:
Aleksey Kladov 2019-01-15 17:55:15 +03:00
parent 443ff27724
commit 68ff52566d
6 changed files with 28 additions and 31 deletions

View File

@ -25,7 +25,7 @@ impl Crate {
let file_id = crate_graph.crate_root(self.crate_id);
let source_root_id = db.file_source_root(file_id);
let file_id = HirFileId::from(file_id);
let module_tree = db.module_tree(source_root_id)?;
let module_tree = db.module_tree(source_root_id);
// FIXME: teach module tree about crate roots instead of guessing
let source = SourceItemId {
file_id,

View File

@ -19,7 +19,7 @@ impl Module {
source_root_id: SourceRootId,
module_id: ModuleId,
) -> Cancelable<Self> {
let module_tree = db.module_tree(source_root_id)?;
let module_tree = db.module_tree(source_root_id);
let def_loc = DefLoc {
kind: DefKind::Module,
source_root_id,
@ -33,7 +33,7 @@ impl Module {
pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
let loc = self.def_id.loc(db);
let module_tree = db.module_tree(loc.source_root_id)?;
let module_tree = db.module_tree(loc.source_root_id);
let link = ctry!(loc.module_id.parent_link(&module_tree));
Ok(Some(link.name(&module_tree).clone()))
}
@ -59,7 +59,7 @@ impl Module {
db: &impl HirDatabase,
) -> Cancelable<Option<(FileId, TreeArc<ast::Module>)>> {
let loc = self.def_id.loc(db);
let module_tree = db.module_tree(loc.source_root_id)?;
let module_tree = db.module_tree(loc.source_root_id);
let link = ctry!(loc.module_id.parent_link(&module_tree));
let file_id = link
.owner(&module_tree)
@ -82,7 +82,7 @@ impl Module {
pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Cancelable<Module> {
let loc = self.def_id.loc(db);
let module_tree = db.module_tree(loc.source_root_id)?;
let module_tree = db.module_tree(loc.source_root_id);
let module_id = loc.module_id.crate_root(&module_tree);
Module::from_module_id(db, loc.source_root_id, module_id)
}
@ -90,7 +90,7 @@ impl Module {
/// Finds a child module with the specified name.
pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
let loc = self.def_id.loc(db);
let module_tree = db.module_tree(loc.source_root_id)?;
let module_tree = db.module_tree(loc.source_root_id);
let child_id = ctry!(loc.module_id.child(&module_tree, name));
Module::from_module_id(db, loc.source_root_id, child_id).map(Some)
}
@ -101,7 +101,7 @@ impl Module {
// it's kind of hard since the iterator needs to keep a reference to the
// module tree.
let loc = self.def_id.loc(db);
let module_tree = db.module_tree(loc.source_root_id)?;
let module_tree = db.module_tree(loc.source_root_id);
let children = loc
.module_id
.children(&module_tree)
@ -112,7 +112,7 @@ impl Module {
pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {
let loc = self.def_id.loc(db);
let module_tree = db.module_tree(loc.source_root_id)?;
let module_tree = db.module_tree(loc.source_root_id);
let parent_id = ctry!(loc.module_id.parent(&module_tree));
Module::from_module_id(db, loc.source_root_id, parent_id).map(Some)
}
@ -190,7 +190,7 @@ impl Module {
db: &impl HirDatabase,
) -> Cancelable<Vec<(TreeArc<SyntaxNode>, Problem)>> {
let loc = self.def_id.loc(db);
let module_tree = db.module_tree(loc.source_root_id)?;
let module_tree = db.module_tree(loc.source_root_id);
Ok(loc.module_id.problems(&module_tree, db))
}
}

View File

@ -77,7 +77,7 @@ pub trait HirDatabase: SyntaxDatabase
use fn query_definitions::file_item;
}
fn submodules(source: SourceItemId) -> Cancelable<Arc<Vec<crate::module_tree::Submodule>>> {
fn submodules(source: SourceItemId) -> Arc<Vec<crate::module_tree::Submodule>> {
type SubmodulesQuery;
use fn crate::module_tree::Submodule::submodules_query;
}
@ -92,7 +92,7 @@ pub trait HirDatabase: SyntaxDatabase
use fn query_definitions::item_map;
}
fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> {
fn module_tree(source_root_id: SourceRootId) -> Arc<ModuleTree> {
type ModuleTreeQuery;
use fn crate::module_tree::ModuleTree::module_tree_query;
}

View File

@ -3,7 +3,7 @@ use std::sync::Arc;
use rustc_hash::{FxHashMap, FxHashSet};
use arrayvec::ArrayVec;
use relative_path::RelativePathBuf;
use ra_db::{FileId, SourceRootId, Cancelable, SourceRoot};
use ra_db::{FileId, SourceRootId, SourceRoot};
use ra_syntax::{
SyntaxNode, TreeArc,
algo::generate,
@ -41,7 +41,7 @@ impl Submodule {
pub(crate) fn submodules_query(
db: &impl HirDatabase,
source: SourceItemId,
) -> Cancelable<Arc<Vec<Submodule>>> {
) -> Arc<Vec<Submodule>> {
db.check_canceled();
let file_id = source.file_id;
let file_items = db.file_items(file_id);
@ -54,7 +54,7 @@ impl Submodule {
collect_submodules(file_id, &file_items, module.item_list().unwrap())
}
};
return Ok(Arc::new(submodules));
return Arc::new(submodules);
fn collect_submodules(
file_id: HirFileId,
@ -116,10 +116,10 @@ impl ModuleTree {
pub(crate) fn module_tree_query(
db: &impl HirDatabase,
source_root: SourceRootId,
) -> Cancelable<Arc<ModuleTree>> {
) -> Arc<ModuleTree> {
db.check_canceled();
let res = create_module_tree(db, source_root);
Ok(Arc::new(res?))
Arc::new(res)
}
pub(crate) fn modules<'a>(&'a self) -> impl Iterator<Item = ModuleId> + 'a {
@ -225,10 +225,7 @@ fn modules(root: &impl ast::ModuleItemOwner) -> impl Iterator<Item = (Name, &ast
})
}
fn create_module_tree<'a>(
db: &impl HirDatabase,
source_root: SourceRootId,
) -> Cancelable<ModuleTree> {
fn create_module_tree<'a>(db: &impl HirDatabase, source_root: SourceRootId) -> ModuleTree {
let mut tree = ModuleTree::default();
let mut roots = FxHashMap::default();
@ -252,10 +249,10 @@ fn create_module_tree<'a>(
&mut roots,
None,
source,
)?;
);
roots.insert(file_id, module_id);
}
Ok(tree)
tree
}
fn build_subtree(
@ -266,14 +263,14 @@ fn build_subtree(
roots: &mut FxHashMap<FileId, ModuleId>,
parent: Option<LinkId>,
source: SourceItemId,
) -> Cancelable<ModuleId> {
) -> ModuleId {
visited.insert(source);
let id = tree.push_mod(ModuleData {
source,
parent,
children: Vec::new(),
});
for sub in db.submodules(source)?.iter() {
for sub in db.submodules(source).iter() {
let link = tree.push_link(LinkData {
source: sub.source,
name: sub.name.clone(),
@ -289,7 +286,7 @@ fn build_subtree(
.map(|file_id| match roots.remove(&file_id) {
Some(module_id) => {
tree.mods[module_id].parent = Some(link);
Ok(module_id)
module_id
}
None => build_subtree(
db,
@ -304,7 +301,7 @@ fn build_subtree(
},
),
})
.collect::<Cancelable<Vec<_>>>()?;
.collect::<Vec<_>>();
(points_to, problem)
} else {
let points_to = build_subtree(
@ -315,14 +312,14 @@ fn build_subtree(
roots,
Some(link),
sub.source,
)?;
);
(vec![points_to], None)
};
tree.links[link].points_to = points_to;
tree.links[link].problem = problem;
}
Ok(id)
id
}
fn resolve_submodule(

View File

@ -48,7 +48,7 @@ pub(super) fn input_module_items(
source_root_id: SourceRootId,
module_id: ModuleId,
) -> Cancelable<Arc<InputModuleItems>> {
let module_tree = db.module_tree(source_root_id)?;
let module_tree = db.module_tree(source_root_id);
let source = module_id.source(&module_tree);
let file_id = source.file_id;
let source = ModuleSource::from_source_item_id(db, source);
@ -98,7 +98,7 @@ pub(super) fn item_map(
source_root: SourceRootId,
) -> Cancelable<Arc<ItemMap>> {
let start = Instant::now();
let module_tree = db.module_tree(source_root)?;
let module_tree = db.module_tree(source_root);
let input = module_tree
.modules()
.map(|id| {

View File

@ -92,7 +92,7 @@ pub fn module_from_child_node(
fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Cancelable<Option<Module>> {
let source_root_id = db.file_source_root(source.file_id.as_original_file());
let module_tree = db.module_tree(source_root_id)?;
let module_tree = db.module_tree(source_root_id);
let module_id = ctry!(module_tree.find_module_by_source(source));
Ok(Some(Module::from_module_id(db, source_root_id, module_id)?))
}