aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src/db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/src/db.rs')
-rw-r--r--crates/libanalysis/src/db.rs28
1 files changed, 25 insertions, 3 deletions
diff --git a/crates/libanalysis/src/db.rs b/crates/libanalysis/src/db.rs
index 335c79e76..5e3c8fb7a 100644
--- a/crates/libanalysis/src/db.rs
+++ b/crates/libanalysis/src/db.rs
@@ -1,6 +1,7 @@
1use std::{ 1use std::{
2 hash::Hash, 2 hash::Hash,
3 sync::Arc, 3 sync::Arc,
4 cell::RefCell,
4}; 5};
5use libsyntax2::{File}; 6use libsyntax2::{File};
6use im; 7use im;
@@ -36,17 +37,38 @@ impl Db {
36 self.file_resolver = file_resolver 37 self.file_resolver = file_resolver
37 } 38 }
38 pub(crate) fn query_ctx(&self) -> QueryCtx { 39 pub(crate) fn query_ctx(&self) -> QueryCtx {
39 QueryCtx { db: self.clone() } 40 QueryCtx {
41 db: self.clone(),
42 trace: RefCell::new(Vec::new()),
43 }
40 } 44 }
41} 45}
42 46
43pub(crate) struct QueryCtx { 47pub(crate) struct QueryCtx {
44 db: Db 48 db: Db,
49 pub(crate) trace: RefCell<Vec<TraceEvent>>,
50}
51
52#[derive(Clone, Copy, Debug)]
53pub(crate) struct TraceEvent {
54 pub(crate) query_id: u32,
55 pub(crate) kind: TraceEventKind
56}
57
58#[derive(Clone, Copy, Debug, PartialEq, Eq)]
59pub(crate) enum TraceEventKind {
60 Start, Finish
45} 61}
46 62
47impl QueryCtx { 63impl QueryCtx {
48 pub(crate) fn get<Q: Get>(&self, params: &Q::Params) -> Q::Output { 64 pub(crate) fn get<Q: Get>(&self, params: &Q::Params) -> Q::Output {
49 Q::get(self, params) 65 self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Start });
66 let res = Q::get(self, params);
67 self.trace(TraceEvent { query_id: Q::ID, kind: TraceEventKind::Finish });
68 res
69 }
70 fn trace(&self, event: TraceEvent) {
71 self.trace.borrow_mut().push(event)
50 } 72 }
51} 73}
52 74