diff options
Diffstat (limited to 'crates/libanalysis/src/db/queries.rs')
-rw-r--r-- | crates/libanalysis/src/db/queries.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/crates/libanalysis/src/db/queries.rs b/crates/libanalysis/src/db/queries.rs new file mode 100644 index 000000000..2d4aac6e9 --- /dev/null +++ b/crates/libanalysis/src/db/queries.rs | |||
@@ -0,0 +1,43 @@ | |||
1 | use std::sync::Arc; | ||
2 | use libsyntax2::{File}; | ||
3 | use { | ||
4 | FileId, FileResolverImp, | ||
5 | db::{Query, GroundQuery, QueryCtx, hash}, | ||
6 | }; | ||
7 | |||
8 | |||
9 | impl<'a> QueryCtx<'a> { | ||
10 | pub(crate) fn file_set(&self) -> Arc<(Vec<FileId>, FileResolverImp)> { | ||
11 | self.get_g(FILE_SET, ()) | ||
12 | } | ||
13 | pub(crate) fn file_text(&self, file_id: FileId) -> Arc<str> { | ||
14 | Arc::clone(&*self.get_g(FILE_TEXT, file_id)) | ||
15 | } | ||
16 | pub(crate) fn file_syntax(&self, file_id: FileId) -> File { | ||
17 | (&*self.get(FILE_SYNTAX, file_id)).clone() | ||
18 | } | ||
19 | } | ||
20 | |||
21 | pub(super) const FILE_TEXT: GroundQuery<FileId, Arc<str>> = GroundQuery { | ||
22 | id: 10, | ||
23 | f: |state, id| state.file_map[&id].clone(), | ||
24 | h: hash, | ||
25 | }; | ||
26 | |||
27 | pub(super) const FILE_SET: GroundQuery<(), (Vec<FileId>, FileResolverImp)> = GroundQuery { | ||
28 | id: 11, | ||
29 | f: |state, &()| { | ||
30 | let files = state.file_map.keys().cloned().collect(); | ||
31 | let resolver = state.resolver.clone(); | ||
32 | (files, resolver) | ||
33 | }, | ||
34 | h: |(files, _)| hash(files), | ||
35 | }; | ||
36 | |||
37 | pub(super) const FILE_SYNTAX: Query<FileId, File> = Query { | ||
38 | id: 20, | ||
39 | f: |ctx, file_id: &FileId| { | ||
40 | let text = ctx.file_text(*file_id); | ||
41 | File::parse(&*text) | ||
42 | } | ||
43 | }; | ||