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

//! `file_diagnostics` and `workspace_diagnostics`.

use {
  crate::{
    connect::lsp::{
      LspClient,
      request::{
        DocumentDiagnosticRequest,
        WorkspaceDiagnosticRequest,
      },
    },
    connect::mcp::{
      schema,
      tool::{
        Tool,
        ToolError,
        ToolRegistry,
      },
    },
    protocol::lsp::{
      DocumentDiagnosticParams,
      DocumentDiagnosticReportResult,
      WorkspaceDiagnosticParams,
      WorkspaceDiagnosticReportResult,
    },
  },
  serde_json::json,
};

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

pub enum FileDiagnostics {}

impl Tool for FileDiagnostics {
  type Input = DocumentDiagnosticParams;
  type Output = DocumentDiagnosticReportResult;

  const NAME: &'static str = "file_diagnostics";
  const DESCRIPTION: &'static str =
    "Return the diagnostics (errors, warnings, hints) for a single file. \
     Pull-model — wraps LSP `textDocument/diagnostic`.";

  fn input_schema() -> serde_json::Value {
    json!({
      "type": "object",
      "properties": {
        "textDocument": schema::text_document_identifier(),
        "identifier":         { "type": "string" },
        "previousResultId":   { "type": "string" }
      },
      "required": ["textDocument"]
    })
  }

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

pub enum WorkspaceDiagnostics {}

impl Tool for WorkspaceDiagnostics {
  type Input = WorkspaceDiagnosticParams;
  type Output = WorkspaceDiagnosticReportResult;

  const NAME: &'static str = "workspace_diagnostics";
  const DESCRIPTION: &'static str =
    "Return all known diagnostics across the workspace, grouped by file. \
     Wraps LSP `workspace/diagnostic`.";

  fn input_schema() -> serde_json::Value {
    json!({
      "type": "object",
      "properties": {
        "identifier":        { "type": "string" },
        "previousResultIds": { "type": "array" }
      },
      "required": ["previousResultIds"]
    })
  }

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