Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-mcp

Model Context Protocol server for Pudu language documentation and compiler tools

0.1.1Apache-2.01

InstallClose

Lsp.pudu

Pudu24 lines1.2 KB

GitHub ↗
1/** @Services.Lsp.Adapter — asks the installed language server once */2module PuduLangMcp.Services.Lsp34import PuduLangMcp.Constants.Server as Server5import PuduLangMcp.Domain.Lsp.Conversation as Conversation6import PuduLangMcp.Errors.ToolError as ToolError7import PuduLangMcp.Services.Toolchain as Toolchain89/// The command the language server is started with.10const COMMAND: Str = "pudu lsp"1112/// The language server's answer to one question, or why there is none.13export fn ask(toolchain: &Toolchain.Toolchain, rootUri: Str, uri: Str, source: Str, directory: Str, question: &Conversation.Question) -> Result[Conversation.Answer, ToolError.ToolFailure] {14  if toolchain.compiler == None { return Err(ToolError.ToolchainMissing) }15  let said = Conversation.conversation(rootUri, uri, source, question)16  let done = match toolchain.run(["lsp"], said, directory, Server.LSP_TIMEOUT_MS, Server.OUTPUT_CAP_BYTES) {17    case Ok(finished) => finished18    case Err(problem) => { return Err(ToolError.CommandFailed(problem)) }19  }20  let answer = Conversation.answerIn(done.output)21  if answer.result != None || answer.error != None { return Ok(answer) }22  if done.timedOut { Err(ToolError.TimedOut(COMMAND, Server.LSP_TIMEOUT_MS)) } else { Err(ToolError.Unavailable("The language server ended without answering.")) }23}24