symbolique 0.1.0

Symbol table pipeline for language servers — parse, link, merge, and resolve symbols across files, built on the laburnum LSP framework.
// Copyright Two Neutron Stars Incorporated and contributors
// SPDX-License-Identifier: BlueOak-1.0.0

//! Merged-level symbol reader extension trait.
//!
//! This module provides [`MergedSymboliqueReadExt`], for querying merged-level
//! symbols from `QueryClient`.

use {
  crate::{
    core::{Ident, SymbolPath, Value},
    partitions::{merged::MergedSymbols, records::SymbolEntry, symbols::Symbols},
  },
  laburnum::database::{
    HasPartition, RecordRef,
    query::QueryClient,
    storage::Partitions,
  },
};

/// Extension trait for reading merged-level symbols from partitions.
///
/// Provides typed methods for querying symbols written during the merge stage.
/// Methods query the `MergedSymbols` index and optionally follow handles to
/// the shared `Symbols` partition.
pub trait MergedSymboliqueReadExt<P: Partitions> {
  /// Look up a merged symbol by exact sort key.
  fn merged_symbol_at_path<V, I, Path>(
    &self,
    sort_key: &str,
  ) -> Option<SymbolEntry<V, I, Path>>
  where
    V: Value<I>,
    I: Ident,
    Path: SymbolPath,
    P::Stores: HasPartition<MergedSymbols<V, I, Path>>;

  /// Query merged symbols with a sort key prefix.
  fn merged_symbols_with_prefix<V, I, Path>(
    &self,
    prefix: &str,
  ) -> Vec<(String, SymbolEntry<V, I, Path>)>
  where
    V: Value<I>,
    I: Ident,
    Path: SymbolPath,
    P::Stores: HasPartition<MergedSymbols<V, I, Path>>;

  /// Follow a symbol entry's handle to retrieve the full symbol shape.
  fn resolve_merged_symbol<V, I, Path>(
    &self,
    entry: &SymbolEntry<V, I, Path>,
  ) -> Option<RecordRef<'_, Symbols<V, I, Path>>>
  where
    V: Value<I> + 'static,
    I: Ident,
    Path: SymbolPath + 'static,
    P::Stores: HasPartition<Symbols<V, I, Path>>;
}

impl<P: Partitions> MergedSymboliqueReadExt<P> for QueryClient<P> {
  fn merged_symbol_at_path<V, I, Path>(
    &self,
    sort_key: &str,
  ) -> Option<SymbolEntry<V, I, Path>>
  where
    V: Value<I>,
    I: Ident,
    Path: SymbolPath,
    P::Stores: HasPartition<MergedSymbols<V, I, Path>>,
  {
    self.index_get::<MergedSymbols<V, I, Path>>(sort_key)
  }

  fn merged_symbols_with_prefix<V, I, Path>(
    &self,
    prefix: &str,
  ) -> Vec<(String, SymbolEntry<V, I, Path>)>
  where
    V: Value<I>,
    I: Ident,
    Path: SymbolPath,
    P::Stores: HasPartition<MergedSymbols<V, I, Path>>,
  {
    self.index_range::<MergedSymbols<V, I, Path>>(prefix)
  }

  fn resolve_merged_symbol<V, I, Path>(
    &self,
    entry: &SymbolEntry<V, I, Path>,
  ) -> Option<RecordRef<'_, Symbols<V, I, Path>>>
  where
    V: Value<I> + 'static,
    I: Ident,
    Path: SymbolPath + 'static,
    P::Stores: HasPartition<Symbols<V, I, Path>>,
  {
    self.get::<Symbols<V, I, Path>>(entry.symbol.content_hash())
  }
}