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

//! JSON Schema fragments for LSP primitives.
//!
//! The MCP `tools/list` response includes a JSON Schema for each tool's
//! `Input`. Rather than redeclaring `Position`, `Range`, etc. inside every
//! tool's schema, tools compose these fragments via [`serde_json::json!`].
//!
//! Field naming matches the LSP serde representation (`camelCase`), so the
//! schemas describe exactly what the LSP type's `Deserialize` impl accepts.

use serde_json::{
  Value,
  json,
};

/// Schema for [`crate::Uri`] — a URI string.
pub fn uri() -> Value {
  json!({ "type": "string", "format": "uri" })
}

/// Schema for `lsp::TextDocumentIdentifier` — `{ uri }`.
pub fn text_document_identifier() -> Value {
  json!({
    "type": "object",
    "properties": { "uri": uri() },
    "required": ["uri"]
  })
}

/// Schema for `lsp::Position` — `{ line, character }`. Per ADR0010 the
/// MCP server negotiates `utf-8` so `character` is a UTF-8 byte offset
/// within the line.
pub fn position() -> Value {
  json!({
    "type": "object",
    "properties": {
      "line":      { "type": "integer", "minimum": 0 },
      "character": { "type": "integer", "minimum": 0 }
    },
    "required": ["line", "character"]
  })
}

/// Schema for `lsp::Range` — `{ start, end }`.
pub fn range() -> Value {
  json!({
    "type": "object",
    "properties": { "start": position(), "end": position() },
    "required": ["start", "end"]
  })
}

/// Schema for `lsp::TextDocumentPositionParams` (after serde flatten):
/// `{ textDocument, position }`. Used by every position-based tool.
pub fn text_document_position() -> Value {
  json!({
    "type": "object",
    "properties": {
      "textDocument": text_document_identifier(),
      "position":     position()
    },
    "required": ["textDocument", "position"]
  })
}

/// Schema for an `lsp::CallHierarchyItem` or `lsp::TypeHierarchyItem`.
/// Used by the hierarchy follow-up tools where the agent passes the item
/// returned by the prepare step.
pub fn hierarchy_item() -> Value {
  json!({
    "type": "object",
    "properties": {
      "name": { "type": "string" },
      "kind": { "type": "integer" },
      "uri":  uri(),
      "range":          range(),
      "selectionRange": range(),
      "tags":   { "type": "array", "items": { "type": "integer" } },
      "detail": { "type": "string" },
      "data":   {}
    },
    "required": ["name", "kind", "uri", "range", "selectionRange"]
  })
}