mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-10 12:26:50 +00:00
Clean up more outdated documentation in db.rs
- Removed references to 'LspFileSystem' (now WorkspaceFileSystem) - Removed verbose 'overlay' explanations (now using Buffers abstraction) - Simplified struct field documentation to be accurate and concise - Removed unnecessary mentions of 'Ruff's pattern' everywhere The documentation now accurately reflects the current implementation without verbose explanations of outdated architecture.
This commit is contained in:
parent
af8820b7bc
commit
c685f53dec
1 changed files with 19 additions and 28 deletions
|
@ -6,12 +6,12 @@
|
||||||
//! ## Architecture
|
//! ## Architecture
|
||||||
//!
|
//!
|
||||||
//! The system uses a two-layer approach:
|
//! The system uses a two-layer approach:
|
||||||
//! 1. **Buffer layer** ([`crate::Buffers`]) - Stores open document content in memory
|
//! 1. **Buffer layer** ([`Buffers`]) - Stores open document content in memory
|
||||||
//! 2. **Salsa layer** ([`Database`]) - Tracks files and computes derived queries
|
//! 2. **Salsa layer** ([`Database`]) - Tracks files and computes derived queries
|
||||||
//!
|
//!
|
||||||
//! When Salsa needs file content, it calls [`source_text`] which:
|
//! When Salsa needs file content, it calls [`source_text`] which:
|
||||||
//! 1. Creates a dependency on the file's revision (critical!)
|
//! 1. Creates a dependency on the file's revision (critical!)
|
||||||
//! 2. Reads through [`crate::WorkspaceFileSystem`] which checks buffers first
|
//! 2. Reads through [`WorkspaceFileSystem`] which checks buffers first
|
||||||
//! 3. Falls back to disk if no buffer exists
|
//! 3. Falls back to disk if no buffer exists
|
||||||
//!
|
//!
|
||||||
//! ## The Revision Dependency
|
//! ## The Revision Dependency
|
||||||
|
@ -22,7 +22,9 @@
|
||||||
//! ```ignore
|
//! ```ignore
|
||||||
//! let _ = file.revision(db); // Creates the dependency chain!
|
//! let _ = file.revision(db); // Creates the dependency chain!
|
||||||
//! ```
|
//! ```
|
||||||
|
//!
|
||||||
|
//! [`Buffers`]: crate::buffers::Buffers
|
||||||
|
//! [`WorkspaceFileSystem`]: crate::fs::WorkspaceFileSystem
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -36,36 +38,29 @@ use crate::{FileKind, FileSystem};
|
||||||
/// Database trait that provides file system access for Salsa queries
|
/// Database trait that provides file system access for Salsa queries
|
||||||
#[salsa::db]
|
#[salsa::db]
|
||||||
pub trait Db: salsa::Database {
|
pub trait Db: salsa::Database {
|
||||||
/// Get the file system for reading files (with overlay support)
|
/// Get the file system for reading files.
|
||||||
fn fs(&self) -> Option<Arc<dyn FileSystem>>;
|
fn fs(&self) -> Option<Arc<dyn FileSystem>>;
|
||||||
|
|
||||||
/// Read file content through the file system
|
/// Read file content through the file system.
|
||||||
/// This is the primary way Salsa queries should read files, as it
|
///
|
||||||
/// automatically checks overlays before falling back to disk.
|
/// Checks buffers first via [`crate::WorkspaceFileSystem`], then falls back to disk.
|
||||||
fn read_file_content(&self, path: &Path) -> std::io::Result<String>;
|
fn read_file_content(&self, path: &Path) -> std::io::Result<String>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Salsa database root for workspace
|
/// Salsa database for incremental computation.
|
||||||
///
|
///
|
||||||
/// The [`Database`] provides default storage and, in tests, captures Salsa events for
|
/// Tracks files and computes derived queries incrementally. Integrates with
|
||||||
/// reuse/diagnostics. It serves as the core incremental computation engine, tracking
|
/// [`crate::WorkspaceFileSystem`] to read file content, which checks buffers
|
||||||
/// dependencies and invalidations across all inputs and derived queries.
|
/// before falling back to disk.
|
||||||
///
|
|
||||||
/// The database integrates with the FileSystem abstraction to read files through
|
|
||||||
/// the LspFileSystem, which automatically checks overlays before falling back to disk.
|
|
||||||
#[salsa::db]
|
#[salsa::db]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
storage: salsa::Storage<Self>,
|
storage: salsa::Storage<Self>,
|
||||||
|
|
||||||
/// FileSystem integration for reading files (with overlay support)
|
/// File system for reading file content (checks buffers first, then disk).
|
||||||
/// This allows the database to read files through LspFileSystem, which
|
|
||||||
/// automatically checks for overlays before falling back to disk files.
|
|
||||||
fs: Option<Arc<dyn FileSystem>>,
|
fs: Option<Arc<dyn FileSystem>>,
|
||||||
|
|
||||||
/// File tracking outside of Salsa but within Database (Arc for cheap cloning).
|
/// Maps paths to [`SourceFile`] entities for O(1) lookup.
|
||||||
/// This follows Ruff's pattern where files are tracked in the Database struct
|
|
||||||
/// but not as part of Salsa's storage, enabling cheap clones via Arc.
|
|
||||||
files: Arc<DashMap<PathBuf, SourceFile>>,
|
files: Arc<DashMap<PathBuf, SourceFile>>,
|
||||||
|
|
||||||
// The logs are only used for testing and demonstrating reuse:
|
// The logs are only used for testing and demonstrating reuse:
|
||||||
|
@ -126,9 +121,7 @@ impl Database {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read file content through the file system
|
/// Read file content through the file system.
|
||||||
/// This is the primary way Salsa queries should read files, as it
|
|
||||||
/// automatically checks overlays before falling back to disk.
|
|
||||||
pub fn read_file_content(&self, path: &Path) -> std::io::Result<String> {
|
pub fn read_file_content(&self, path: &Path) -> std::io::Result<String> {
|
||||||
if let Some(fs) = &self.fs {
|
if let Some(fs) = &self.fs {
|
||||||
fs.read_to_string(path)
|
fs.read_to_string(path)
|
||||||
|
@ -214,12 +207,10 @@ pub struct SourceFile {
|
||||||
pub revision: u64,
|
pub revision: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read file content through the FileSystem, creating proper Salsa dependencies.
|
/// Read file content, creating a Salsa dependency on the file's revision.
|
||||||
///
|
///
|
||||||
/// This is the CRITICAL function that implements Ruff's two-layer architecture.
|
/// **Critical**: The call to `file.revision(db)` creates the dependency chain.
|
||||||
/// The call to `file.revision(db)` creates a Salsa dependency, ensuring that
|
/// Without it, revision changes won't trigger query invalidation.
|
||||||
/// when the revision changes, this function (and all dependent queries) are
|
|
||||||
/// invalidated and re-executed.
|
|
||||||
#[salsa::tracked]
|
#[salsa::tracked]
|
||||||
pub fn source_text(db: &dyn Db, file: SourceFile) -> Arc<str> {
|
pub fn source_text(db: &dyn Db, file: SourceFile) -> Arc<str> {
|
||||||
// This line creates the Salsa dependency on revision! Without this call,
|
// This line creates the Salsa dependency on revision! Without this call,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue