laburnum 1.17.0

An LSP framework for building language servers and compilers, powered by an incremental query tree with content-addressed storage, task-based dataflow, and parallel queries.
Documentation
// Copyright Two Neutron Stars Incorporated and contributors
// SPDX-License-Identifier: BlueOak-1.0.0

//! # Database Partition Definitions
//!
//! This module contains standardized partition definitions for the Laburnum
//! database. Each partition follows a consistent pattern to ensure uniformity
//! across the codebase.
//!
//! # Standard Partitions
//!
//! Laburnum provides standard partitions for common LSP features:
//! - [`Diagnostics`] - Errors, warnings, and info messages
//! - [`DocumentSymbols`] - Symbols for outline view / breadcrumbs
//! - [`WorkspaceSymbols`] - Global symbol search across workspace
//! - [`TextDocumentPosition`] - Position-to-symbol mapping for hover/goto
//! - [`TextDocumentReferences`] - Symbol references for "find all references"
//! - [`DocumentFoldingRange`] - Code folding regions
//! - [`Workspace`] - Workspace-level configuration
//!
//! Writing to these standard partitions enables LSP features to work
//! automatically.
//!
//! # Using Standard Partitions
//!
//! Language crates using Laburnum write to these partitions by:
//!
//! 1. Defining a concrete record type that implements the partition's record
//!    trait (e.g., `DiagnosticRecord`)
//! 2. Using [`impl_partition_for_dyn!`] to create a wrapper partition type
//! 3. Writing records via the normal partition write path
//!
//! ## Example
//!
//! ```rust,ignore
//! use laburnum::{
//!   impl_partition_for_dyn,
//!   partitions::{Diagnostics, diagnostics::DiagnosticRecord},
//! };
//!
//! // 1. Define your concrete record type implementing the required trait
//! #[derive(Debug)]
//! pub struct MyDiagnostic { /* ... */ }
//!
//! impl DiagnosticRecord for MyDiagnostic { /* ... */ }
//! impl laburnum::record::Record for MyDiagnostic { /* ... */ }
//!
//! // 2. Create a wrapper partition using the macro
//! // This enforces at compile time that MyDiagnostic implements DiagnosticRecord
//! impl_partition_for_dyn!(MyDiagnosticsPartition, Diagnostics, MyDiagnostic);
//!
//! // 3. Write records using the wrapper partition
//! use laburnum::partitions::diagnostics::DiagnosticSortKey;
//!
//! let sort_key = DiagnosticSortKey::Diagnostic {
//!   source_key,
//!   severity: DiagnosticSeverity::ERROR,
//!   sequence: 0,
//! };
//! writer.write::<MyDiagnosticsPartition>(sort_key, my_diagnostic.into());
//! ```
//!
//! The [`impl_partition_for_dyn!`] macro:
//! - Creates a new partition type that shares the same `KEY` as the Laburnum
//!   partition
//! - Enforces at compile time that your record type implements the required
//!   trait via [`DynPartitionRecord`]
//! - Allows you to use the standard partition write path
//!
//! # Partition File Structure
//!
//! Each partition is defined in its own file following this structure:
//!
//! ### 1. Partition Marker Type
//! A zero-sized marker type that implements [`DynPartition`]:
//! ```rust,ignore
//! pub struct MyPartition;
//!
//! impl PartitionKey for MyPartition {
//!   const KEY: Ident = Ident::new("laburnum::my_partition");
//! }
//!
//! impl DynPartition for MyPartition {
//!   type DynSortKey = MyPartitionSortKey;
//!   type RecordConstraint = dyn MyPartitionRecord;
//! }
//!
//! // Blanket impl connecting any type implementing MyPartitionRecord to this
//! // partition
//! impl<R: MyPartitionRecord + crate::record::Record>
//!   crate::database::DynPartitionRecord<MyPartition> for R
//! {}
//! ```
//!
//! ### 2. Sort Key Enum
//! An enum representing sort key variants and query prefixes:
//! ```rust,ignore
//! #[derive(Debug, Clone)]
//! pub enum MyPartitionSortKey {
//!   Record { field1: Type1, field2: Type2 },
//!   All,
//!   Prefix { field1: Type1 },
//! }
//! ```
//!
//! ### 3. Display Implementation
//! Formats the enum into sort key strings:
//! ```rust,ignore
//! impl std::fmt::Display for MyPartitionSortKey {
//!   fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
//!     match self {
//!       Self::Record { field1, field2 } => write!(f, "{}|{}", field1, field2),
//!       Self::All => Ok(()),
//!       Self::Prefix { field1 } => write!(f, "{}|", field1),
//!     }
//!   }
//! }
//! ```
//!
//! ### 4. Record Trait
//! The trait that concrete record types must implement:
//! ```rust,ignore
//! pub trait MyPartitionRecord: Send + Sync + std::fmt::Debug {
//!   fn method1(&self) -> ReturnType;
//!   fn method2(&self) -> ReturnType;
//! }
//! ```
//!
//! [`impl_partition_for_dyn!`]: crate::impl_partition_for_dyn
//! [`DynPartition`]: crate::database::DynPartition
//! [`DynPartitionRecord`]: crate::database::DynPartitionRecord

pub mod clients;
pub mod diagnostics;
pub mod document_folding_range;
pub mod document_symbols;
pub mod text_document_references;
pub mod text_document_position;
pub mod work_done_progress;
pub mod workspace;
pub mod workspace_symbols;

pub use {
  crate::connect::lsp::ClientKind,
  clients::{
    ClientRecord,
    ClientSortKey,
    ClientWriteExt,
    Clients,
  },
  diagnostics::Diagnostics,
  document_folding_range::DocumentFoldingRange,
  document_symbols::DocumentSymbols,
  text_document_references::TextDocumentReferences,
  text_document_position::TextDocumentPosition,
  work_done_progress::WorkDoneProgress,
  workspace::Workspace,
  workspace_symbols::WorkspaceSymbols,
};