diff options
Diffstat (limited to 'crates/ra_analysis/src/db/input.rs')
-rw-r--r-- | crates/ra_analysis/src/db/input.rs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/crates/ra_analysis/src/db/input.rs b/crates/ra_analysis/src/db/input.rs new file mode 100644 index 000000000..957d082f9 --- /dev/null +++ b/crates/ra_analysis/src/db/input.rs | |||
@@ -0,0 +1,83 @@ | |||
1 | use std::{ | ||
2 | sync::Arc, | ||
3 | hash::{Hasher, Hash}, | ||
4 | }; | ||
5 | |||
6 | use salsa; | ||
7 | use rustc_hash::FxHashSet; | ||
8 | |||
9 | use crate::{FileId, FileResolverImp, CrateGraph, symbol_index::SymbolIndex}; | ||
10 | |||
11 | salsa::query_group! { | ||
12 | pub(crate) trait FilesDatabase: salsa::Database { | ||
13 | fn file_text(file_id: FileId) -> Arc<String> { | ||
14 | type FileTextQuery; | ||
15 | storage input; | ||
16 | } | ||
17 | fn file_source_root(file_id: FileId) -> SourceRootId { | ||
18 | type FileSourceRootQuery; | ||
19 | storage input; | ||
20 | } | ||
21 | fn source_root(id: SourceRootId) -> Arc<SourceRoot> { | ||
22 | type SourceRootQuery; | ||
23 | storage input; | ||
24 | } | ||
25 | fn libraries() -> Arc<Vec<SourceRootId>> { | ||
26 | type LibrarieseQuery; | ||
27 | storage input; | ||
28 | } | ||
29 | fn library_symbols(id: SourceRootId) -> Arc<SymbolIndex> { | ||
30 | type LibrarySymbolsQuery; | ||
31 | storage input; | ||
32 | } | ||
33 | fn crate_graph() -> Arc<CrateGraph> { | ||
34 | type CrateGraphQuery; | ||
35 | storage input; | ||
36 | } | ||
37 | } | ||
38 | } | ||
39 | |||
40 | #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
41 | pub(crate) struct SourceRootId(pub(crate) u32); | ||
42 | |||
43 | #[derive(Clone, Default, Debug, Eq)] | ||
44 | pub(crate) struct SourceRoot { | ||
45 | pub(crate) file_resolver: FileResolverImp, | ||
46 | pub(crate) files: FxHashSet<FileId>, | ||
47 | } | ||
48 | |||
49 | impl PartialEq for SourceRoot { | ||
50 | fn eq(&self, other: &SourceRoot) -> bool { | ||
51 | self.file_resolver == other.file_resolver | ||
52 | } | ||
53 | } | ||
54 | |||
55 | impl Hash for SourceRoot { | ||
56 | fn hash<H: Hasher>(&self, hasher: &mut H) { | ||
57 | self.file_resolver.hash(hasher); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | pub(crate) const WORKSPACE: SourceRootId = SourceRootId(0); | ||
62 | |||
63 | |||
64 | #[derive(Default, Debug, Eq)] | ||
65 | pub(crate) struct FileSet { | ||
66 | pub(crate) files: FxHashSet<FileId>, | ||
67 | pub(crate) resolver: FileResolverImp, | ||
68 | } | ||
69 | |||
70 | impl PartialEq for FileSet { | ||
71 | fn eq(&self, other: &FileSet) -> bool { | ||
72 | self.files == other.files && self.resolver == other.resolver | ||
73 | } | ||
74 | } | ||
75 | |||
76 | impl Hash for FileSet { | ||
77 | fn hash<H: Hasher>(&self, hasher: &mut H) { | ||
78 | let mut files = self.files.iter().cloned().collect::<Vec<_>>(); | ||
79 | files.sort(); | ||
80 | files.hash(hasher); | ||
81 | } | ||
82 | } | ||
83 | |||