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::{
        Command,
        DynamicRegistrationClientCapabilities,
        PartialResultParams,
        Range,
        TextDocumentIdentifier,
        TextDocumentRegistrationOptions,
        WorkDoneProgressParams,
      },
    },
    scheduler::{
      lanes::{
        self,
        Lane,
      },
      task::TaskContext,
    },
  },
  serde::{
    Deserialize,
    Serialize,
  },
  serde_json::Value,
};

pub type CodeLensClientCapabilities = DynamicRegistrationClientCapabilities;

/// Code Lens options.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeLensOptions {
  /// Code lens has a resolve provider as well.
  #[serde(skip_serializing_if = "Option::is_none")]
  pub resolve_provider: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeLensParams {
  /// The document to request code lens for.
  pub text_document: TextDocumentIdentifier,

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

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

/// A code lens represents a command that should be shown along with
/// source text, like the number of references, a way to run tests, etc.
///
/// A code lens is _unresolved_ when no command is associated to it. For
/// performance reasons the creation of a code lens and resolving should be done
/// in two stages.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeLens {
  /// The range in which this code lens is valid. Should only span a single
  /// line.
  pub range: Range,

  /// The command this code lens represents.
  #[serde(skip_serializing_if = "Option::is_none")]
  pub command: Option<Command>,

  /// A data entry field that is preserved on a code lens item between
  /// a code lens and a code lens resolve request.
  #[serde(skip_serializing_if = "Option::is_none")]
  pub data: Option<Value>,
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeLensWorkspaceClientCapabilities {
  /// Whether the client implementation supports a refresh request sent from
  /// the server to the client.
  ///
  /// Note that this event is global and will force the client to refresh all
  /// code lenses currently shown. It should be used with absolute care and is
  /// useful for situation where a server for example detect a project wide
  /// change that requires such a calculation.
  #[serde(skip_serializing_if = "Option::is_none")]
  pub refresh_support: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeLensRegistrationOptions {
  #[serde(flatten)]
  pub text_document_registration_options: TextDocumentRegistrationOptions,

  #[serde(flatten)]
  pub code_lens_options: CodeLensOptions,
}

pub trait CodeLensService<
  P: crate::database::storage::Partitions,
  T: crate::protocol::lsp::LanguageServer<P>,
>: Send + Sync + 'static
{
  /// The [`textDocument/codeLens`] request is sent from the client to the
  /// server to compute code lenses for a given text document.
  ///
  /// [`textDocument/codeLens`]: https://microsoft.github.io/language-server-protocol/specification#textDocument_codeLens
  fn code_lens(
    &self,
    params: CodeLensParams,
    ctx: &mut TaskContext<P, T>,
    writer: &mut PartitionWriteContextRef<'_, P>,
  ) -> impl std::future::Future<Output = jsonrpc::Result<Option<Vec<CodeLens>>>> + Send
  {
    async move {
      otel::span!(
        "laburnum.lsp.code_lens",
        "document.uri" = params.text_document.uri.to_string()
      );

      let _ = (params, ctx, writer);
      Err(jsonrpc::Error::method_not_found())
    }
  }
  const CODE_LENS_LANE: Lane = lanes::DEFAULT_LANE;

  /// The [`codeLens/resolve`] request is sent from the client to the server to
  /// resolve the command for a given code lens item.
  ///
  /// [`codeLens/resolve`]: https://microsoft.github.io/language-server-protocol/specification#codeLens_resolve
  fn code_lens_resolve(
    &self,
    params: CodeLens,
    ctx: &mut TaskContext<P, T>,
    writer: &mut PartitionWriteContextRef<'_, P>,
  ) -> impl std::future::Future<Output = jsonrpc::Result<CodeLens>> + Send {
    async move {
      otel::span!("laburnum.lsp.code_lens_resolve");

      let _ = (params, ctx, writer);
      Err(jsonrpc::Error::method_not_found())
    }
  }
  const CODE_LENS_RESOLVE_LANE: Lane = lanes::SYNC_LANE;
}