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

use {
  crate::{
    TRACER,
    Uri,
    database::PartitionWriteContextRef,
    protocol::{
      jsonrpc,
      lsp::{
        PartialResultParams,
        Range,
        TextDocumentIdentifier,
        WorkDoneProgressOptions,
        WorkDoneProgressParams,
      },
    },
    scheduler::task::TaskContext,
  },
  serde::{
    Deserialize,
    Serialize,
  },
  serde_json::Value,
};

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentLinkClientCapabilities {
  /// Whether document link supports dynamic registration.
  #[serde(skip_serializing_if = "Option::is_none")]
  pub dynamic_registration: Option<bool>,

  /// Whether the client support the `tooltip` property on `DocumentLink`.
  #[serde(skip_serializing_if = "Option::is_none")]
  pub tooltip_support: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentLinkOptions {
  /// Document links have a resolve provider as well.
  #[serde(skip_serializing_if = "Option::is_none")]
  pub resolve_provider: Option<bool>,

  #[serde(flatten)]
  pub work_done_progress_options: WorkDoneProgressOptions,
}

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

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

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

/// A document link is a range in a text document that links to an internal or
/// external resource, like another text document or a web site.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct DocumentLink {
  /// The range this link applies to.
  pub range:  Range,
  /// The uri this link points to.
  #[serde(skip_serializing_if = "Option::is_none")]
  pub target: Option<Uri>,

  /// The tooltip text when you hover over this link.
  ///
  /// If a tooltip is provided, is will be displayed in a string that includes
  /// instructions on how to trigger the link, such as `{0} (ctrl + click)`.
  /// The specific instructions vary depending on OS, user settings, and
  /// localization.
  #[serde(skip_serializing_if = "Option::is_none")]
  pub tooltip: Option<String>,

  /// A data entry field that is preserved on a document link between a
  /// `DocumentLinkRequest` and a `DocumentLinkResolveRequest`.
  #[serde(skip_serializing_if = "Option::is_none")]
  pub data: Option<Value>,
}

pub trait DocumentLinkService<
  P: crate::database::storage::Partitions,
  T: crate::protocol::lsp::LanguageServer<P>,
>: Send + Sync + 'static
{
  /// The [`documentLink/resolve`] request is sent from the client to the server
  /// to resolve the target of a given document link.
  ///
  /// [`documentLink/resolve`]: https://microsoft.github.io/language-server-protocol/specification#documentLink_resolve
  ///
  /// A document link is a range in a text document that links to an internal or
  /// external resource, like another text document or a web site.
  fn document_link_resolve(
    &self,
    params: DocumentLink,
    ctx: &mut TaskContext<P, T>,
    writer: &mut PartitionWriteContextRef<'_, P>,
  ) -> impl std::future::Future<Output = jsonrpc::Result<DocumentLink>> + Send
  {
    async move {
      otel::span!("laburnum.lsp.document_link_resolve");
      let _ = params;
      Err(jsonrpc::Error::method_not_found())
    }
  }
  const DOCUMENT_LINK_RESOLVE_LANE: crate::scheduler::lanes::Lane =
    crate::scheduler::lanes::DEFAULT_LANE;

  /// The [`textDocument/documentLink`] request is sent from the client to the
  /// server to request the location of links in a document.
  ///
  /// A document link is a range in a text document that links to an internal or
  /// external resource, like another text document or a web site.
  ///
  /// [`textDocument/documentLink`]: https://microsoft.github.io/language-server-protocol/specification#textDocument_documentLink
  ///
  /// # Compatibility
  ///
  /// The [`DocumentLink::tooltip`] field was introduced in specification
  /// version 3.15.0 and requires client-side support in order to be used. It
  /// can be returned if the client set the following field to `true` in the
  /// [`initialize`](Self::initialize) method:
  ///
  /// ```text
  /// InitializeParams::capabilities::text_document::document_link::tooltip_support
  /// ```
  fn document_link(
    &self,
    params: DocumentLinkParams,
    ctx: &mut TaskContext<P, T>,
    writer: &mut PartitionWriteContextRef<'_, P>,
  ) -> impl std::future::Future<
    Output = jsonrpc::Result<Option<Vec<DocumentLink>>>,
  > + Send {
    async move {
      otel::span!(
        "laburnum.lsp.document_link",
        "document.uri" = params.text_document.uri.to_string()
      );
      let _ = params;
      Err(jsonrpc::Error::method_not_found())
    }
  }
  const DOCUMENT_LINK_LANE: crate::scheduler::lanes::Lane =
    crate::scheduler::lanes::DEFAULT_LANE;
}