Skip to main content

php_lsp/db/
analysis.rs

1//! Database + Analysis/AnalysisHost split (rust-analyzer pattern).
2//!
3//! `AnalysisHost` owns the mutable database; LSP write paths (`did_open`,
4//! `did_change`, workspace scan) go through the host. `Analysis` is a read-only
5//! view used by request handlers. Phase A keeps this minimal — cancellation and
6//! true snapshot semantics land in Phase E.
7
8use salsa::{Database, Storage};
9
10#[salsa::db]
11#[derive(Default, Clone)]
12pub struct RootDatabase {
13    storage: Storage<Self>,
14}
15
16#[salsa::db]
17impl Database for RootDatabase {}
18
19/// Owns the mutable salsa database. Backend will hold one of these.
20#[derive(Default)]
21pub struct AnalysisHost {
22    db: RootDatabase,
23}
24
25impl AnalysisHost {
26    pub fn new() -> Self {
27        Self::default()
28    }
29
30    pub fn db(&self) -> &RootDatabase {
31        &self.db
32    }
33
34    pub fn db_mut(&mut self) -> &mut RootDatabase {
35        &mut self.db
36    }
37}