php-lsp 0.7.0

A PHP Language Server Protocol implementation
Documentation
//! Salsa inputs.

use std::sync::Arc;

use mir_analyzer::PhpVersion;

use crate::file_index::FileIndex;

/// Opaque file identifier used as a stable key for a source file across edits.
/// Backend will map `Url` <-> `FileId`; salsa queries key on `SourceFile` which
/// wraps this id plus the current text.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FileId(pub u32);

/// Per-file salsa input. A new revision is observed whenever `text` is set.
///
/// `uri` is the LSP document URI as a string (e.g. `file:///path/Foo.php`).
/// It lives on the input so that tracked queries like `file_refs` can emit
/// per-symbol location records keyed by URI without needing a separate
/// FileId→URI map outside salsa.
///
/// `cached_index` (Phase K2): when `Some`, holds a pre-computed `FileIndex`
/// loaded from the on-disk cache. `file_index` checks this field first and
/// returns the cached index instead of parsing + extracting. Cleared back to
/// `None` on any text edit — see `DocumentStore::mirror_text` — so a stale
/// cached index cannot mask a real change. Seeded by workspace scan via
/// `DocumentStore::seed_cached_index` before the first `file_index` call for
/// that file.
#[salsa::input]
pub struct SourceFile {
    pub id: FileId,
    pub uri: Arc<str>,
    pub text: Arc<str>,
    pub cached_index: Option<Arc<FileIndex>>,
}

/// Workspace-level input: the set of files that participate in whole-program
/// analyses (codebase, references). Updated by the backend when files are
/// discovered (workspace scan, did_open on previously-unseen file) or removed
/// (watched-files delete).
///
/// Uses `durability = HIGH` conceptually — the file list changes rarely
/// (workspace scan, deletions), not on every edit. Salsa's default durability
/// is LOW; backend can opt into HIGH via `set_files` if churn becomes an issue.
#[salsa::input]
pub struct Workspace {
    pub files: Arc<[SourceFile]>,
    /// Target PHP version for analysis. Changing this invalidates all
    /// `semantic_issues` queries so diagnostics are re-evaluated against the
    /// new version's rules.
    pub php_version: PhpVersion,
}