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::{
    TRACER,
    database::PartitionWriteContextRef,
    protocol::{
      jsonrpc,
      lsp::{
        DynamicRegistrationClientCapabilities,
        PartialResultParams,
        Range,
        TextDocumentPositionParams,
        WorkDoneProgressParams,
      },
      macros::lsp_enum,
    },
    scheduler::task::TaskContext,
  },
  serde::{
    Deserialize,
    Serialize,
  },
};

pub type DocumentHighlightClientCapabilities =
  DynamicRegistrationClientCapabilities;

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentHighlightParams {
  #[serde(flatten)]
  pub text_document_position_params: TextDocumentPositionParams,

  #[serde(flatten)]
  pub work_done_progress_params: WorkDoneProgressParams,

  #[serde(flatten)]
  pub partial_result_params: PartialResultParams,
}

/// A document highlight is a range inside a text document which deserves
/// special attention. Usually a document highlight is visualized by changing
/// the background color of its range.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct DocumentHighlight {
  /// The range this highlight applies to.
  pub range: Range,

  /// The highlight kind, default is DocumentHighlightKind.Text.
  #[serde(skip_serializing_if = "Option::is_none")]
  pub kind: Option<DocumentHighlightKind>,
}

/// A document highlight kind.
#[derive(Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
#[serde(transparent)]
pub struct DocumentHighlightKind(i32);

lsp_enum! {
    impl DocumentHighlightKind {
        /// A textual occurrence.
        const TEXT = 1;
        /// Read-access of a symbol, like reading a variable.
        const READ = 2;
        /// Write-access of a symbol, like writing to a variable.
        const WRITE = 3;
    }
}

pub trait DocumentHighlightService<
  P: crate::database::storage::Partitions,
  T: crate::protocol::lsp::LanguageServer<P>,
>: Send + Sync + 'static
{
  /// The [`textDocument/documentHighlight`] request is sent from the client to
  /// the server to resolve appropriate highlights for a given text document
  /// position.
  ///
  /// [`textDocument/documentHighlight`]: https://microsoft.github.io/language-server-protocol/specification#textDocument_documentHighlight
  ///
  /// For programming languages, this usually highlights all textual references
  /// to the symbol scoped to this file.
  ///
  /// This request differs slightly from `textDocument/references` in that this
  /// one is allowed to be more fuzzy.
  fn document_highlight(
    &self,
    params: DocumentHighlightParams,
    ctx: &mut TaskContext<P, T>,
    writer: &mut PartitionWriteContextRef<'_, P>,
  ) -> impl std::future::Future<
    Output = jsonrpc::Result<Option<Vec<DocumentHighlight>>>,
  > + Send {
    async move {
      otel::span!(
        "laburnum.lsp.document_highlight",
        "document.uri" = params
          .text_document_position_params
          .text_document
          .uri
          .to_string(),
        "position.line" =
          params.text_document_position_params.position.line as i64,
        "position.character" =
          params.text_document_position_params.position.character as i64
      );
      let _ = params;
      Err(jsonrpc::Error::method_not_found())
    }
  }
  const DOCUMENT_HIGHLIGHT_LANE: crate::scheduler::lanes::Lane =
    crate::scheduler::lanes::DEFAULT_LANE;
}