aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_db/src/input.rs')
-rw-r--r--crates/ra_db/src/input.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
new file mode 100644
index 000000000..9101ac7a8
--- /dev/null
+++ b/crates/ra_db/src/input.rs
@@ -0,0 +1,73 @@
1use std::sync::Arc;
2
3use rustc_hash::FxHashMap;
4use rustc_hash::FxHashSet;
5use salsa;
6
7use crate::file_resolver::FileResolverImp;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub struct FileId(pub u32);
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
13pub struct CrateId(pub u32);
14
15#[derive(Debug, Clone, Default, PartialEq, Eq)]
16pub struct CrateGraph {
17 pub(crate) crate_roots: FxHashMap<CrateId, FileId>,
18}
19
20impl CrateGraph {
21 pub fn crate_root(&self, crate_id: CrateId) -> FileId {
22 self.crate_roots[&crate_id]
23 }
24 pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId {
25 let crate_id = CrateId(self.crate_roots.len() as u32);
26 let prev = self.crate_roots.insert(crate_id, file_id);
27 assert!(prev.is_none());
28 crate_id
29 }
30 pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> {
31 let (&crate_id, _) = self
32 .crate_roots
33 .iter()
34 .find(|(_crate_id, &root_id)| root_id == file_id)?;
35 Some(crate_id)
36 }
37}
38
39salsa::query_group! {
40 pub trait FilesDatabase: salsa::Database {
41 fn file_text(file_id: FileId) -> Arc<String> {
42 type FileTextQuery;
43 storage input;
44 }
45 fn file_source_root(file_id: FileId) -> SourceRootId {
46 type FileSourceRootQuery;
47 storage input;
48 }
49 fn source_root(id: SourceRootId) -> Arc<SourceRoot> {
50 type SourceRootQuery;
51 storage input;
52 }
53 fn libraries() -> Arc<Vec<SourceRootId>> {
54 type LibrariesQuery;
55 storage input;
56 }
57 fn crate_graph() -> Arc<CrateGraph> {
58 type CrateGraphQuery;
59 storage input;
60 }
61 }
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
65pub struct SourceRootId(pub u32);
66
67#[derive(Default, Clone, Debug, PartialEq, Eq)]
68pub struct SourceRoot {
69 pub file_resolver: FileResolverImp,
70 pub files: FxHashSet<FileId>,
71}
72
73pub const WORKSPACE: SourceRootId = SourceRootId(0);