laburnum 1.17.1

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

use {
  crate::{Ident, Span, database::chunk::ChunkId},
  thiserror::Error,
};

#[derive(Debug, Error)]
pub enum LaburnumError {
  #[error("Identifier must be 255 bytes or less, got {len} bytes at {span:?}")]
  IdentTooLong { len: usize, span: Span },

  #[error(
    "Duplicate definition for partition key {partition_key} with sort key {sort_key} in chunks {chunks:?}"
  )]
  DuplicateDefinition {
    partition_key: Ident,
    sort_key: String,
    chunks: Vec<ChunkId>,
  },

  #[error("Source not found")]
  SourceNotFound,

  #[error("File ID mismatch: expected {expected}, got {got}")]
  FileIdMismatch { expected: u16, got: u16 },

  #[error(
    "Too many versions for file {file_id}: maximum 1024 versions allowed"
  )]
  TooManyVersions { file_id: u16 },

  #[error("Too many files: maximum 65535 files allowed per package")]
  TooManyFiles,

  #[error("Filesystem error for {uri}: {error}")]
  FileSystemError { uri: crate::Uri, error: String },

  #[error("File not found")]
  FileNotFound,

  #[error("File content evicted")]
  FileEvicted,

  #[error("Invalid range")]
  InvalidRange,

  #[error("Task cancelled: source version no longer available")]
  TaskCancelled,

  #[error("Lock poisoned")]
  LockPoisoned,

  #[error("SpanCache is already complete")]
  SpanCacheAlreadyComplete,

  #[error("SpanCache not set")]
  SpanCacheNotSet,

  #[error("LSP version {lsp_version} already exists in cache")]
  VersionAlreadyExists { lsp_version: i32 },

  #[error("Cannot perform disk operation on open file: {operation}")]
  FileOpenConflict { operation: &'static str },

  #[error(
    "Internal consistency error: file versions not found for file_id {file_id}"
  )]
  FileVersionsNotFound { file_id: u16 },

  #[error("Version slot exhausted: all 1024 version slots are actively in use")]
  VersionSlotExhausted,
}

/// Trait for reporting compilation diagnostics in different contexts (CLI vs
/// LSP)
pub trait ErrorReporter<P, T>: Send + Sync
where
  P: crate::database::storage::Partitions,
  T: crate::protocol::lsp::LanguageServer<P>,
{
  /// Report compilation diagnostics from a compilation session
  ///
  /// This method receives all error types from the compilation pipeline:
  /// - Lexical analysis errors
  /// - CST parsing errors
  /// - AST parsing errors
  /// - Symbol resolution errors
  /// - Output resolution errors (handled separately without resolver)
  ///
  /// It also receives the list of all theme files so it can clear diagnostics
  /// for files that no longer have errors (by publishing empty diagnostic
  /// arrays).
  ///
  /// The fallback_span is used for errors that don't have their own span,
  /// following the priority: theme block > palette block > first file.
  fn report_diagnostics(&self, source_cache: &mut crate::SourceCache<P, T>);

  /// Report no diagnostics
  ///
  /// For LSP clients, used to clear diagnostics for files that no longer have
  /// errors.
  fn report_no_diagnostics(&self, theme_files: &[url::Url]);
}