remove Cancelable from Module API

This commit is contained in:
Aleksey Kladov 2019-01-15 18:26:29 +03:00
parent 91feed736f
commit ca52cf1ecd
6 changed files with 18 additions and 22 deletions

View File

@ -78,12 +78,12 @@ pub enum Problem {
impl Module {
/// Name of this module.
pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
self.name_impl(db)
}
/// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
pub fn definition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> {
pub fn definition_source(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) {
self.definition_source_impl(db)
}
@ -92,7 +92,7 @@ impl Module {
pub fn declaration_source(
&self,
db: &impl HirDatabase,
) -> Cancelable<Option<(FileId, TreeArc<ast::Module>)>> {
) -> Option<(FileId, TreeArc<ast::Module>)> {
self.declaration_source_impl(db)
}

View File

@ -30,17 +30,14 @@ impl Module {
Module::new(def_id)
}
pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Option<Name> {
let loc = self.def_id.loc(db);
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()))
let link = loc.module_id.parent_link(&module_tree)?;
Some(link.name(&module_tree).clone())
}
pub fn definition_source_impl(
&self,
db: &impl HirDatabase,
) -> Cancelable<(FileId, ModuleSource)> {
pub fn definition_source_impl(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) {
let loc = self.def_id.loc(db);
let file_id = loc.source_item_id.file_id.as_original_file();
let syntax_node = db.file_item(loc.source_item_id);
@ -50,23 +47,23 @@ impl Module {
let module = ast::Module::cast(&syntax_node).unwrap();
ModuleSource::Module(module.to_owned())
};
Ok((file_id, module_source))
(file_id, module_source)
}
pub fn declaration_source_impl(
&self,
db: &impl HirDatabase,
) -> Cancelable<Option<(FileId, TreeArc<ast::Module>)>> {
) -> Option<(FileId, TreeArc<ast::Module>)> {
let loc = self.def_id.loc(db);
let module_tree = db.module_tree(loc.source_root_id);
let link = ctry!(loc.module_id.parent_link(&module_tree));
let link = loc.module_id.parent_link(&module_tree)?;
let file_id = link
.owner(&module_tree)
.source(&module_tree)
.file_id
.as_original_file();
let src = link.source(&module_tree, db);
Ok(Some((file_id, src)))
Some((file_id, src))
}
pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {

View File

@ -167,7 +167,7 @@ impl ModuleImplBlocks {
}
fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> {
let (file_id, module_source) = module.definition_source(db)?;
let (file_id, module_source) = module.definition_source(db);
let node = match &module_source {
ModuleSource::SourceFile(node) => node.syntax(),
ModuleSource::Module(node) => node

View File

@ -20,7 +20,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
}
let module_scope = module.scope(ctx.db)?;
let (file_id, _) = module.definition_source(ctx.db)?;
let (file_id, _) = module.definition_source(ctx.db);
module_scope
.entries()
.filter(|(_name, res)| {

View File

@ -73,9 +73,9 @@ impl NavigationTarget {
db: &RootDatabase,
module: hir::Module,
) -> Cancelable<NavigationTarget> {
let (file_id, source) = module.definition_source(db)?;
let (file_id, source) = module.definition_source(db);
let name = module
.name(db)?
.name(db)
.map(|it| it.to_string().into())
.unwrap_or_default();
let res = match source {
@ -94,10 +94,10 @@ impl NavigationTarget {
module: hir::Module,
) -> Cancelable<NavigationTarget> {
let name = module
.name(db)?
.name(db)
.map(|it| it.to_string().into())
.unwrap_or_default();
if let Some((file_id, source)) = module.declaration_source(db)? {
if let Some((file_id, source)) = module.declaration_source(db) {
return Ok(NavigationTarget::from_syntax(
file_id,
name,

View File

@ -83,8 +83,7 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Opt
.ok()?
.into_iter()
.rev()
.filter_map(|it| it.name(db).ok())
.filter_map(|it| it)
.filter_map(|it| it.name(db))
.join("::");
Some(Runnable {
range,