php_lsp/db/analysis.rs
1//! Database + AnalysisHost split (rust-analyzer pattern).
2//!
3//! `AnalysisHost` owns the mutable salsa database; LSP write paths
4//! (`did_open`, `did_change`, workspace scan) go through the host.
5//! Read-only handlers snapshot the db (cheap `Arc<Zalsa>` clone) and run
6//! queries lock-free.
7//!
8//! After the mir 0.22 migration, this module no longer owns the workspace
9//! `MirDb` — that's the responsibility of `mir_analyzer::AnalysisSession`
10//! held by `DocumentStore`. Salsa is for parsed_doc / file_index only.
11
12use salsa::{Database, Storage};
13
14#[salsa::db]
15#[derive(Default, Clone)]
16pub struct RootDatabase {
17 storage: Storage<Self>,
18}
19
20#[salsa::db]
21impl Database for RootDatabase {}
22
23/// Owns the mutable salsa database. Backend will hold one of these.
24#[derive(Default)]
25pub struct AnalysisHost {
26 db: RootDatabase,
27}
28
29impl AnalysisHost {
30 pub fn new() -> Self {
31 Self::default()
32 }
33
34 pub fn db(&self) -> &RootDatabase {
35 &self.db
36 }
37
38 pub fn db_mut(&mut self) -> &mut RootDatabase {
39 &mut self.db
40 }
41}