Skip to main content

php_lsp/db/
input.rs

1//! Salsa inputs.
2
3use std::sync::Arc;
4
5use mir_analyzer::PhpVersion;
6
7use crate::file_index::FileIndex;
8
9/// Opaque file identifier used as a stable key for a source file across edits.
10/// Backend will map `Url` <-> `FileId`; salsa queries key on `SourceFile` which
11/// wraps this id plus the current text.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13pub struct FileId(pub u32);
14
15/// Per-file salsa input. A new revision is observed whenever `text` is set.
16///
17/// `uri` is the LSP document URI as a string (e.g. `file:///path/Foo.php`).
18/// It lives on the input so that tracked queries like `file_refs` can emit
19/// per-symbol location records keyed by URI without needing a separate
20/// FileId→URI map outside salsa.
21///
22/// `cached_index` (Phase K2): when `Some`, holds a pre-computed `FileIndex`
23/// loaded from the on-disk cache. `file_index` checks this field first and
24/// returns the cached index instead of parsing + extracting. Cleared back to
25/// `None` on any text edit — see `DocumentStore::mirror_text` — so a stale
26/// cached index cannot mask a real change. Seeded by workspace scan via
27/// `DocumentStore::seed_cached_index` before the first `file_index` call for
28/// 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_index: Option<Arc<FileIndex>>,
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}