diff options
author | Aleksey Kladov <[email protected]> | 2018-10-25 08:57:55 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-25 14:25:40 +0100 |
commit | ee4d904cfb1b604bc8627491e05980ac43cd59e3 (patch) | |
tree | 54d1b937de544b8f6a8f2821ad9599aa82192375 /crates/ra_analysis/src/db.rs | |
parent | 2cb2074c4b7219b32993abdcc7084637c0123d49 (diff) |
Store all the data in the Salsa Database
Diffstat (limited to 'crates/ra_analysis/src/db.rs')
-rw-r--r-- | crates/ra_analysis/src/db.rs | 136 |
1 files changed, 0 insertions, 136 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs deleted file mode 100644 index b527cde61..000000000 --- a/crates/ra_analysis/src/db.rs +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | use std::{ | ||
2 | fmt, | ||
3 | hash::{Hash, Hasher}, | ||
4 | sync::Arc, | ||
5 | }; | ||
6 | |||
7 | use ra_editor::LineIndex; | ||
8 | use ra_syntax::File; | ||
9 | use rustc_hash::FxHashSet; | ||
10 | use salsa; | ||
11 | |||
12 | use crate::{ | ||
13 | db, | ||
14 | Cancelable, Canceled, | ||
15 | descriptors::module::{SubmodulesQuery, ModuleTreeQuery, ModulesDatabase}, | ||
16 | symbol_index::SymbolIndex, | ||
17 | FileId, FileResolverImp, | ||
18 | }; | ||
19 | |||
20 | #[derive(Default)] | ||
21 | pub(crate) struct RootDatabase { | ||
22 | runtime: salsa::Runtime<RootDatabase>, | ||
23 | } | ||
24 | |||
25 | impl fmt::Debug for RootDatabase { | ||
26 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
27 | fmt.write_str("RootDatabase { ... }") | ||
28 | } | ||
29 | } | ||
30 | |||
31 | impl salsa::Database for RootDatabase { | ||
32 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { | ||
33 | &self.runtime | ||
34 | } | ||
35 | } | ||
36 | |||
37 | pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> { | ||
38 | if db.salsa_runtime().is_current_revision_canceled() { | ||
39 | Err(Canceled) | ||
40 | } else { | ||
41 | Ok(()) | ||
42 | } | ||
43 | } | ||
44 | |||
45 | impl salsa::ParallelDatabase for RootDatabase { | ||
46 | fn fork(&self) -> Self { | ||
47 | RootDatabase { | ||
48 | runtime: self.runtime.fork(), | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
53 | impl Clone for RootDatabase { | ||
54 | fn clone(&self) -> RootDatabase { | ||
55 | salsa::ParallelDatabase::fork(self) | ||
56 | } | ||
57 | } | ||
58 | |||
59 | salsa::database_storage! { | ||
60 | pub(crate) struct RootDatabaseStorage for RootDatabase { | ||
61 | impl FilesDatabase { | ||
62 | fn file_text() for FileTextQuery; | ||
63 | fn file_set() for FileSetQuery; | ||
64 | } | ||
65 | impl SyntaxDatabase { | ||
66 | fn file_syntax() for FileSyntaxQuery; | ||
67 | fn file_lines() for FileLinesQuery; | ||
68 | fn file_symbols() for FileSymbolsQuery; | ||
69 | } | ||
70 | impl ModulesDatabase { | ||
71 | fn module_tree() for ModuleTreeQuery; | ||
72 | fn module_descriptor() for SubmodulesQuery; | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | |||
77 | salsa::query_group! { | ||
78 | pub(crate) trait FilesDatabase: salsa::Database { | ||
79 | fn file_text(file_id: FileId) -> Arc<String> { | ||
80 | type FileTextQuery; | ||
81 | storage input; | ||
82 | } | ||
83 | fn file_set() -> Arc<FileSet> { | ||
84 | type FileSetQuery; | ||
85 | storage input; | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | |||
90 | #[derive(Default, Debug, Eq)] | ||
91 | pub(crate) struct FileSet { | ||
92 | pub(crate) files: FxHashSet<FileId>, | ||
93 | pub(crate) resolver: FileResolverImp, | ||
94 | } | ||
95 | |||
96 | impl PartialEq for FileSet { | ||
97 | fn eq(&self, other: &FileSet) -> bool { | ||
98 | self.files == other.files && self.resolver == other.resolver | ||
99 | } | ||
100 | } | ||
101 | |||
102 | impl Hash for FileSet { | ||
103 | fn hash<H: Hasher>(&self, hasher: &mut H) { | ||
104 | let mut files = self.files.iter().cloned().collect::<Vec<_>>(); | ||
105 | files.sort(); | ||
106 | files.hash(hasher); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | salsa::query_group! { | ||
111 | pub(crate) trait SyntaxDatabase: FilesDatabase { | ||
112 | fn file_syntax(file_id: FileId) -> File { | ||
113 | type FileSyntaxQuery; | ||
114 | } | ||
115 | fn file_lines(file_id: FileId) -> Arc<LineIndex> { | ||
116 | type FileLinesQuery; | ||
117 | } | ||
118 | fn file_symbols(file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { | ||
119 | type FileSymbolsQuery; | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | |||
124 | fn file_syntax(db: &impl SyntaxDatabase, file_id: FileId) -> File { | ||
125 | let text = db.file_text(file_id); | ||
126 | File::parse(&*text) | ||
127 | } | ||
128 | fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> { | ||
129 | let text = db.file_text(file_id); | ||
130 | Arc::new(LineIndex::new(&*text)) | ||
131 | } | ||
132 | fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { | ||
133 | db::check_canceled(db)?; | ||
134 | let syntax = db.file_syntax(file_id); | ||
135 | Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) | ||
136 | } | ||