aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/src/db')
-rw-r--r--crates/libanalysis/src/db/imp.rs3
-rw-r--r--crates/libanalysis/src/db/mod.rs42
2 files changed, 9 insertions, 36 deletions
diff --git a/crates/libanalysis/src/db/imp.rs b/crates/libanalysis/src/db/imp.rs
index 1b4ee5cf3..f26be1046 100644
--- a/crates/libanalysis/src/db/imp.rs
+++ b/crates/libanalysis/src/db/imp.rs
@@ -122,9 +122,6 @@ impl QueryRegistry {
122 let config = config.with_query(id, q.f()); 122 let config = config.with_query(id, q.f());
123 self.config= Some(config); 123 self.config= Some(config);
124 } 124 }
125 pub(super) fn finish(mut self) -> salsa::QueryConfig<State, Data> {
126 self.config.take().unwrap()
127 }
128} 125}
129 126
130fn hash<T: Hash>(x: &T) -> u64 { 127fn hash<T: Hash>(x: &T) -> u64 {
diff --git a/crates/libanalysis/src/db/mod.rs b/crates/libanalysis/src/db/mod.rs
index 1111a4f87..22769d112 100644
--- a/crates/libanalysis/src/db/mod.rs
+++ b/crates/libanalysis/src/db/mod.rs
@@ -29,6 +29,12 @@ pub(crate) struct QueryRegistry {
29 imp: imp::QueryRegistry, 29 imp: imp::QueryRegistry,
30} 30}
31 31
32impl Default for Db {
33 fn default() -> Db {
34 Db::new()
35 }
36}
37
32impl Db { 38impl Db {
33 pub(crate) fn new() -> Db { 39 pub(crate) fn new() -> Db {
34 let reg = QueryRegistry::new(); 40 let reg = QueryRegistry::new();
@@ -44,6 +50,7 @@ impl Db {
44 let ctx = QueryCtx { imp: &self.imp.imp.query_ctx() }; 50 let ctx = QueryCtx { imp: &self.imp.imp.query_ctx() };
45 f(ctx) 51 f(ctx)
46 } 52 }
53 #[allow(unused)]
47 pub(crate) fn trace_query<F: FnOnce(QueryCtx) -> R, R>(&self, f: F) -> (R, Vec<&'static str>) { 54 pub(crate) fn trace_query<F: FnOnce(QueryCtx) -> R, R>(&self, f: F) -> (R, Vec<&'static str>) {
48 let ctx = QueryCtx { imp: &self.imp.imp.query_ctx() }; 55 let ctx = QueryCtx { imp: &self.imp.imp.query_ctx() };
49 let res = f(ctx); 56 let res = f(ctx);
@@ -65,42 +72,11 @@ pub(crate) fn file_text(ctx: QueryCtx, file_id: FileId) -> Arc<String> {
65pub(crate) fn file_set(ctx: QueryCtx) -> Arc<(Vec<FileId>, FileResolverImp)> { 72pub(crate) fn file_set(ctx: QueryCtx) -> Arc<(Vec<FileId>, FileResolverImp)> {
66 imp::file_set(ctx) 73 imp::file_set(ctx)
67} 74}
68pub(crate) use self::queries::file_syntax;
69
70mod queries {
71 use std::sync::Arc;
72 use libsyntax2::File;
73 use libeditor::LineIndex;
74 use {FileId};
75 use super::{Query, QueryCtx, QueryRegistry, file_text};
76
77 pub(crate) fn register_queries(reg: &mut QueryRegistry) {
78 reg.add(FILE_SYNTAX, "FILE_SYNTAX");
79 reg.add(FILE_LINES, "FILE_LINES");
80 }
81
82 pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File {
83 (&*ctx.get(FILE_SYNTAX, file_id)).clone()
84 }
85 pub(crate) fn file_lines(ctx: QueryCtx, file_id: FileId) -> Arc<LineIndex> {
86 ctx.get(FILE_LINES, file_id)
87 }
88
89 pub(super) const FILE_SYNTAX: Query<FileId, File> = Query(16, |ctx, file_id: &FileId| {
90 let text = file_text(ctx, *file_id);
91 File::parse(&*text)
92 });
93 pub(super) const FILE_LINES: Query<FileId, LineIndex> = Query(17, |ctx, file_id: &FileId| {
94 let text = file_text(ctx, *file_id);
95 LineIndex::new(&*text)
96 });
97}
98
99impl QueryRegistry { 75impl QueryRegistry {
100 fn new() -> QueryRegistry { 76 fn new() -> QueryRegistry {
101 let mut reg = QueryRegistry { imp: imp::QueryRegistry::new() }; 77 let mut reg = QueryRegistry { imp: imp::QueryRegistry::new() };
102 queries::register_queries(&mut reg); 78 ::queries::register_queries(&mut reg);
103 ::module_map_db::register_queries(&mut reg); 79 ::module_map::register_queries(&mut reg);
104 reg 80 reg
105 } 81 }
106 pub(crate) fn add<Q: imp::EvalQuery>(&mut self, q: Q, name: &'static str) { 82 pub(crate) fn add<Q: imp::EvalQuery>(&mut self, q: Q, name: &'static str) {