:arrow_up salsa

This commit is contained in:
Aleksey Kladov 2019-01-25 15:16:50 +03:00
parent ae97cd59ff
commit 8cf092d5de
9 changed files with 79 additions and 158 deletions

View file

@ -5,11 +5,8 @@
/// Note that neither this module, nor any other part of the analyzer's core do
/// actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how
/// actual IO is done and lowered to input.
use std::sync::Arc;
use relative_path::RelativePathBuf;
use rustc_hash::FxHashMap;
use salsa;
use ra_syntax::SmolStr;
use rustc_hash::FxHashSet;
@ -146,45 +143,6 @@ impl CrateGraph {
}
}
#[salsa::query_group]
pub trait FilesDatabase: salsa::Database {
/// Text of the file.
#[salsa::input]
fn file_text(&self, file_id: FileId) -> Arc<String>;
/// Path to a file, relative to the root of its source root.
#[salsa::input]
fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf;
/// Source root of the file.
#[salsa::input]
fn file_source_root(&self, file_id: FileId) -> SourceRootId;
/// Contents of the source root.
#[salsa::input]
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
fn source_root_crates(&self, id: SourceRootId) -> Arc<Vec<CrateId>>;
/// The set of "local" (that is, from the current workspace) roots.
/// Files in local roots are assumed to change frequently.
#[salsa::input]
fn local_roots(&self) -> Arc<Vec<SourceRootId>>;
/// The set of roots for crates.io libraries.
/// Files in libraries are assumed to never change.
#[salsa::input]
fn library_roots(&self) -> Arc<Vec<SourceRootId>>;
/// The crate graph.
#[salsa::input]
fn crate_graph(&self) -> Arc<CrateGraph>;
}
fn source_root_crates(db: &impl FilesDatabase, 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<_>>();
Arc::new(res)
}
#[cfg(test)]
mod tests {
use super::{CrateGraph, FileId, SmolStr};