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

//! `find_references`.

use {
  crate::{
    connect::lsp::{
      LspClient,
      request::References,
    },
    connect::mcp::{
      schema,
      tool::{
        Tool,
        ToolError,
        ToolRegistry,
      },
    },
    protocol::lsp::{
      Location,
      ReferenceParams,
    },
  },
  serde_json::json,
};

pub fn register(registry: &mut ToolRegistry) {
  registry.register::<FindReferences>();
}

pub enum FindReferences {}

impl Tool for FindReferences {
  type Input = ReferenceParams;
  type Output = Option<Vec<Location>>;

  const NAME: &'static str = "find_references";
  const DESCRIPTION: &'static str =
    "Find all references to the symbol at the given position across the \
     workspace. Wraps LSP `textDocument/references`.";

  fn input_schema() -> serde_json::Value {
    json!({
      "type": "object",
      "properties": {
        "textDocument": schema::text_document_identifier(),
        "position":     schema::position(),
        "context": {
          "type": "object",
          "properties": {
            "includeDeclaration": {
              "type": "boolean",
              "description": "If true, the declaration site is included in the result."
            }
          },
          "required": ["includeDeclaration"]
        }
      },
      "required": ["textDocument", "position", "context"]
    })
  }

  async fn call(
    client: &LspClient,
    input: Self::Input,
  ) -> Result<Self::Output, ToolError> {
    Ok(client.send_request::<References>(input).await?)
  }
}