mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
remove Cancelable from Module API, part 2
This commit is contained in:
parent
ca52cf1ecd
commit
c159e414b4
7 changed files with 28 additions and 33 deletions
|
@ -66,21 +66,21 @@ impl Module {
|
|||
Some((file_id, src))
|
||||
}
|
||||
|
||||
pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
|
||||
let root = self.crate_root(db)?;
|
||||
pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Option<Crate> {
|
||||
let root = self.crate_root(db);
|
||||
let loc = root.def_id.loc(db);
|
||||
let file_id = loc.source_item_id.file_id.as_original_file();
|
||||
|
||||
let crate_graph = db.crate_graph();
|
||||
let crate_id = ctry!(crate_graph.crate_id_for_crate_root(file_id));
|
||||
Ok(Some(Crate::new(crate_id)))
|
||||
let crate_id = crate_graph.crate_id_for_crate_root(file_id)?;
|
||||
Some(Crate::new(crate_id))
|
||||
}
|
||||
|
||||
pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Cancelable<Module> {
|
||||
pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Module {
|
||||
let loc = self.def_id.loc(db);
|
||||
let module_tree = db.module_tree(loc.source_root_id);
|
||||
let module_id = loc.module_id.crate_root(&module_tree);
|
||||
Ok(Module::from_module_id(db, loc.source_root_id, module_id))
|
||||
Module::from_module_id(db, loc.source_root_id, module_id)
|
||||
}
|
||||
|
||||
/// Finds a child module with the specified name.
|
||||
|
@ -92,7 +92,7 @@ impl Module {
|
|||
}
|
||||
|
||||
/// Iterates over all child modules.
|
||||
pub fn children_impl(&self, db: &impl HirDatabase) -> Cancelable<impl Iterator<Item = Module>> {
|
||||
pub fn children_impl(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> {
|
||||
// FIXME this should be implementable without collecting into a vec, but
|
||||
// it's kind of hard since the iterator needs to keep a reference to the
|
||||
// module tree.
|
||||
|
@ -103,18 +103,14 @@ impl Module {
|
|||
.children(&module_tree)
|
||||
.map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id))
|
||||
.collect::<Vec<_>>();
|
||||
Ok(children.into_iter())
|
||||
children.into_iter()
|
||||
}
|
||||
|
||||
pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {
|
||||
pub fn parent_impl(&self, db: &impl HirDatabase) -> Option<Module> {
|
||||
let loc = self.def_id.loc(db);
|
||||
let module_tree = db.module_tree(loc.source_root_id);
|
||||
let parent_id = ctry!(loc.module_id.parent(&module_tree));
|
||||
Ok(Some(Module::from_module_id(
|
||||
db,
|
||||
loc.source_root_id,
|
||||
parent_id,
|
||||
)))
|
||||
let parent_id = loc.module_id.parent(&module_tree)?;
|
||||
Some(Module::from_module_id(db, loc.source_root_id, parent_id))
|
||||
}
|
||||
|
||||
/// Returns a `ModuleScope`: a set of items, visible in this module.
|
||||
|
@ -132,10 +128,10 @@ impl Module {
|
|||
) -> Cancelable<PerNs<DefId>> {
|
||||
let mut curr_per_ns = PerNs::types(
|
||||
match path.kind {
|
||||
PathKind::Crate => self.crate_root(db)?,
|
||||
PathKind::Crate => self.crate_root(db),
|
||||
PathKind::Self_ | PathKind::Plain => self.clone(),
|
||||
PathKind::Super => {
|
||||
if let Some(p) = self.parent(db)? {
|
||||
if let Some(p) = self.parent(db) {
|
||||
p
|
||||
} else {
|
||||
return Ok(PerNs::none());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue