Skip to main content

php_lsp/db/
index.rs

1//! `file_index` salsa query — derives a compact `FileIndex` from a parsed
2//! document. Depends on `parsed_doc`, so editing a file reparses once and the
3//! index re-extracts from the new AST.
4
5use std::sync::Arc;
6
7use crate::index::file_index::FileIndex;
8
9/// Arc wrapper for `FileIndex`. Uses structural equality on the inner
10/// `FileIndex` so salsa can short-circuit downstream queries (e.g.
11/// `workspace_index`) when a body-only edit produces an identical index.
12#[derive(Clone, PartialEq, Debug)]
13pub struct IndexArc(pub Arc<FileIndex>);
14
15impl IndexArc {
16    pub fn get(&self) -> &FileIndex {
17        &self.0
18    }
19}
20
21// SAFETY: writes through `old_pointer` only when returning `true`. Uses
22// structural equality on `FileIndex` so that body-only edits (no declaration
23// change) return `false` and don't cascade to `workspace_index`.
24unsafe impl salsa::Update for IndexArc {
25    unsafe fn maybe_update(old_pointer: *mut Self, new_value: Self) -> bool {
26        let old_ref = unsafe { &mut *old_pointer };
27        if *old_ref.0 == *new_value.0 {
28            false
29        } else {
30            *old_ref = new_value;
31            true
32        }
33    }
34}