Skip to main content

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 / method_returns
11//! only.
12
13use salsa::{Database, Storage};
14
15#[salsa::db]
16#[derive(Default, Clone)]
17pub struct RootDatabase {
18    storage: Storage<Self>,
19}
20
21#[salsa::db]
22impl Database for RootDatabase {}
23
24/// Owns the mutable salsa database. Backend will hold one of these.
25#[derive(Default)]
26pub struct AnalysisHost {
27    db: RootDatabase,
28}
29
30impl AnalysisHost {
31    pub fn new() -> Self {
32        Self::default()
33    }
34
35    pub fn db(&self) -> &RootDatabase {
36        &self.db
37    }
38
39    pub fn db_mut(&mut self) -> &mut RootDatabase {
40        &mut self.db
41    }
42}