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

//! `code_actions`.
//!
//! Returns the available actions; the agent decides what to do with them
//! (typically inspect the action's `edit` and apply it via its own
//! Edit/Write tools, or invoke `execute_command` for actions that come back
//! as commands rather than edits).

use {
  crate::{
    connect::lsp::{
      LspClient,
      request::CodeActionRequest,
    },
    connect::mcp::{
      schema,
      tool::{
        Tool,
        ToolError,
        ToolRegistry,
      },
    },
    protocol::lsp::{
      CodeActionParams,
      CodeActionResponse,
    },
  },
  serde_json::json,
};

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

pub enum CodeActions {}

impl Tool for CodeActions {
  type Input = CodeActionParams;
  type Output = Option<CodeActionResponse>;

  const NAME: &'static str = "code_actions";
  const DESCRIPTION: &'static str =
    "List code actions (quick fixes, refactors, etc.) applicable to a range \
     in a file. Wraps LSP `textDocument/codeAction`. Returns the action \
     descriptors; does not apply them.";

  fn input_schema() -> serde_json::Value {
    json!({
      "type": "object",
      "properties": {
        "textDocument": schema::text_document_identifier(),
        "range":        schema::range(),
        "context": {
          "type": "object",
          "properties": {
            "diagnostics": { "type": "array" },
            "only":        { "type": "array", "items": { "type": "string" } },
            "triggerKind": { "type": "integer" }
          },
          "required": ["diagnostics"]
        }
      },
      "required": ["textDocument", "range", "context"]
    })
  }

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