make source_root API more abstract

This commit is contained in:
Aleksey Kladov 2019-09-05 22:36:04 +03:00
parent 3bdb456d17
commit 9ae455ea52
7 changed files with 31 additions and 17 deletions

View file

@ -12,7 +12,7 @@ pub use crate::{
cancellation::Canceled,
input::{CrateGraph, CrateId, Dependency, Edition, FileId, SourceRoot, SourceRootId},
};
pub use ::salsa;
pub use salsa;
pub trait CheckCanceled {
/// Aborts current query if there are pending changes.
@ -93,8 +93,7 @@ pub trait SourceDatabase: CheckCanceled + std::fmt::Debug {
fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> {
let root = db.source_root(id);
let graph = db.crate_graph();
let res =
root.files.values().filter_map(|&it| graph.crate_id_for_crate_root(it)).collect::<Vec<_>>();
let res = root.walk().filter_map(|it| graph.crate_id_for_crate_root(it)).collect::<Vec<_>>();
Arc::new(res)
}