Skip to main content

php_lsp/db/
input.rs

1//! Salsa inputs.
2
3use std::sync::Arc;
4
5use mir_analyzer::PhpVersion;
6use mir_codebase::storage::StubSlice;
7
8/// Opaque file identifier used as a stable key for a source file across edits.
9/// Backend will map `Url` <-> `FileId`; salsa queries key on `SourceFile` which
10/// wraps this id plus the current text.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub struct FileId(pub u32);
13
14/// Per-file salsa input. A new revision is observed whenever `text` is set.
15///
16/// `uri` is the LSP document URI as a string (e.g. `file:///path/Foo.php`).
17/// It lives on the input so that tracked queries like `file_refs` can emit
18/// per-symbol location records keyed by URI without needing a separate
19/// FileId→URI map outside salsa.
20///
21/// `cached_slice` (Phase K2): when `Some`, holds a pre-computed `StubSlice`
22/// loaded from the on-disk cache. `file_definitions` checks this field
23/// first and returns the cached slice instead of parsing + running
24/// `DefinitionCollector`. Cleared back to `None` on any text edit — see
25/// `DocumentStore::mirror_text` — so a stale cached slice cannot mask a
26/// real change. Seeded by workspace scan via
27/// `DocumentStore::seed_cached_slice` before the first `file_definitions`
28/// call for that file.
29#[salsa::input]
30pub struct SourceFile {
31    pub id: FileId,
32    pub uri: Arc<str>,
33    pub text: Arc<str>,
34    pub cached_slice: Option<Arc<StubSlice>>,
35}
36
37/// Workspace-level input: the set of files that participate in whole-program
38/// analyses (codebase, references). Updated by the backend when files are
39/// discovered (workspace scan, did_open on previously-unseen file) or removed
40/// (watched-files delete).
41///
42/// Uses `durability = HIGH` conceptually — the file list changes rarely
43/// (workspace scan, deletions), not on every edit. Salsa's default durability
44/// is LOW; backend can opt into HIGH via `set_files` if churn becomes an issue.
45#[salsa::input]
46pub struct Workspace {
47    pub files: Arc<[SourceFile]>,
48    /// Target PHP version for analysis. Changing this invalidates all
49    /// `semantic_issues` queries so diagnostics are re-evaluated against the
50    /// new version's rules.
51    pub php_version: PhpVersion,
52}