Author: Sylvestre Ledru Date: 2025-08-28T14:01:55+02:00 New Revision: 1bb8db5d5e1a3ea99525fd2648164a257955cd6d
URL: https://github.com/llvm/llvm-project/commit/1bb8db5d5e1a3ea99525fd2648164a257955cd6d DIFF: https://github.com/llvm/llvm-project/commit/1bb8db5d5e1a3ea99525fd2648164a257955cd6d.diff LOG: Revert "[lldb] NFC Moving mcp::Transport into its own file. (#155711)" This reverts commit 71a065ed07cda66f628e1cfa7b875eeef7e9a141. Added: Modified: lldb/include/lldb/Protocol/MCP/MCPError.h lldb/include/lldb/Protocol/MCP/Protocol.h lldb/include/lldb/Protocol/MCP/Server.h lldb/source/Plugins/Protocol/MCP/ProtocolServerMCP.cpp lldb/source/Protocol/MCP/CMakeLists.txt lldb/source/Protocol/MCP/Server.cpp lldb/unittests/Protocol/ProtocolMCPServerTest.cpp Removed: lldb/include/lldb/Protocol/MCP/Transport.h lldb/source/Protocol/MCP/Transport.cpp ################################################################################ diff --git a/lldb/include/lldb/Protocol/MCP/MCPError.h b/lldb/include/lldb/Protocol/MCP/MCPError.h index 52c5a78fa23c0..55dd40f124a15 100644 --- a/lldb/include/lldb/Protocol/MCP/MCPError.h +++ b/lldb/include/lldb/Protocol/MCP/MCPError.h @@ -19,7 +19,7 @@ class MCPError : public llvm::ErrorInfo<MCPError> { public: static char ID; - MCPError(std::string message, int64_t error_code = eErrorCodeInternalError); + MCPError(std::string message, int64_t error_code = kInternalError); void log(llvm::raw_ostream &OS) const override; std::error_code convertToErrorCode() const override; @@ -28,6 +28,9 @@ class MCPError : public llvm::ErrorInfo<MCPError> { lldb_protocol::mcp::Error toProtocolError() const; + static constexpr int64_t kResourceNotFound = -32002; + static constexpr int64_t kInternalError = -32603; + private: std::string m_message; int64_t m_error_code; diff --git a/lldb/include/lldb/Protocol/MCP/Protocol.h b/lldb/include/lldb/Protocol/MCP/Protocol.h index 295f1f6e1b037..6e1ffcbe1f3e3 100644 --- a/lldb/include/lldb/Protocol/MCP/Protocol.h +++ b/lldb/include/lldb/Protocol/MCP/Protocol.h @@ -55,11 +55,6 @@ enum ErrorCode : signed { eErrorCodeInvalidParams = -32602, /// Internal JSON-RPC error. eErrorCodeInternalError = -32603, - - /// Additional MCP error codes. - - /// Resource related uri not found. - eErrorCodeResourceNotFound = -32002, }; struct Error { diff --git a/lldb/include/lldb/Protocol/MCP/Server.h b/lldb/include/lldb/Protocol/MCP/Server.h index 009c574fde92f..aa5714e45755e 100644 --- a/lldb/include/lldb/Protocol/MCP/Server.h +++ b/lldb/include/lldb/Protocol/MCP/Server.h @@ -9,20 +9,43 @@ #ifndef LLDB_PROTOCOL_MCP_SERVER_H #define LLDB_PROTOCOL_MCP_SERVER_H +#include "lldb/Host/JSONTransport.h" #include "lldb/Host/MainLoop.h" #include "lldb/Protocol/MCP/Protocol.h" #include "lldb/Protocol/MCP/Resource.h" #include "lldb/Protocol/MCP/Tool.h" -#include "lldb/Protocol/MCP/Transport.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/Error.h" +#include <mutex> namespace lldb_protocol::mcp { -class Server : public Transport::MessageHandler { +class MCPTransport + : public lldb_private::JSONRPCTransport<Request, Response, Notification> { +public: + using LogCallback = std::function<void(llvm::StringRef message)>; + + MCPTransport(lldb::IOObjectSP in, lldb::IOObjectSP out, + std::string client_name, LogCallback log_callback = {}) + : JSONRPCTransport(in, out), m_client_name(std::move(client_name)), + m_log_callback(log_callback) {} + virtual ~MCPTransport() = default; + + void Log(llvm::StringRef message) override { + if (m_log_callback) + m_log_callback(llvm::formatv("{0}: {1}", m_client_name, message).str()); + } + +private: + std::string m_client_name; + LogCallback m_log_callback; +}; + +class Server : public MCPTransport::MessageHandler { public: Server(std::string name, std::string version, - std::unique_ptr<Transport> transport_up, lldb_private::MainLoop &loop); + std::unique_ptr<MCPTransport> transport_up, + lldb_private::MainLoop &loop); ~Server() = default; using NotificationHandler = std::function<void(const Notification &)>; @@ -69,7 +92,7 @@ class Server : public Transport::MessageHandler { const std::string m_name; const std::string m_version; - std::unique_ptr<Transport> m_transport_up; + std::unique_ptr<MCPTransport> m_transport_up; lldb_private::MainLoop &m_loop; llvm::StringMap<std::unique_ptr<Tool>> m_tools; diff --git a/lldb/include/lldb/Protocol/MCP/Transport.h b/lldb/include/lldb/Protocol/MCP/Transport.h deleted file mode 100644 index 3cb725131f3b0..0000000000000 --- a/lldb/include/lldb/Protocol/MCP/Transport.h +++ /dev/null @@ -1,39 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_PROTOCOL_MCP_TRANSPORT_H -#define LLDB_PROTOCOL_MCP_TRANSPORT_H - -#include "lldb/Host/JSONTransport.h" -#include "lldb/Protocol/MCP/Protocol.h" -#include "lldb/lldb-forward.h" -#include "llvm/ADT/StringRef.h" -#include <functional> -#include <string> - -namespace lldb_protocol::mcp { - -class Transport - : public lldb_private::JSONRPCTransport<Request, Response, Notification> { -public: - using LogCallback = std::function<void(llvm::StringRef message)>; - - Transport(lldb::IOObjectSP in, lldb::IOObjectSP out, std::string client_name, - LogCallback log_callback = {}); - virtual ~Transport() = default; - - void Log(llvm::StringRef message) override; - -private: - std::string m_client_name; - LogCallback m_log_callback; -}; - -} // namespace lldb_protocol::mcp - -#endif diff --git a/lldb/source/Plugins/Protocol/MCP/ProtocolServerMCP.cpp b/lldb/source/Plugins/Protocol/MCP/ProtocolServerMCP.cpp index a9c4164313a6d..57132534cf680 100644 --- a/lldb/source/Plugins/Protocol/MCP/ProtocolServerMCP.cpp +++ b/lldb/source/Plugins/Protocol/MCP/ProtocolServerMCP.cpp @@ -67,7 +67,7 @@ void ProtocolServerMCP::AcceptCallback(std::unique_ptr<Socket> socket) { LLDB_LOG(log, "New MCP client connected: {0}", client_name); lldb::IOObjectSP io_sp = std::move(socket); - auto transport_up = std::make_unique<lldb_protocol::mcp::Transport>( + auto transport_up = std::make_unique<lldb_protocol::mcp::MCPTransport>( io_sp, io_sp, std::move(client_name), [&](llvm::StringRef message) { LLDB_LOG(GetLog(LLDBLog::Host), "{0}", message); }); diff --git a/lldb/source/Protocol/MCP/CMakeLists.txt b/lldb/source/Protocol/MCP/CMakeLists.txt index 23da62085537e..a73e7e6a7cab1 100644 --- a/lldb/source/Protocol/MCP/CMakeLists.txt +++ b/lldb/source/Protocol/MCP/CMakeLists.txt @@ -3,7 +3,6 @@ add_lldb_library(lldbProtocolMCP NO_PLUGIN_DEPENDENCIES Protocol.cpp Server.cpp Tool.cpp - Transport.cpp LINK_COMPONENTS Support diff --git a/lldb/source/Protocol/MCP/Server.cpp b/lldb/source/Protocol/MCP/Server.cpp index fb317083b015e..63c2d01d17922 100644 --- a/lldb/source/Protocol/MCP/Server.cpp +++ b/lldb/source/Protocol/MCP/Server.cpp @@ -15,7 +15,7 @@ using namespace lldb_protocol::mcp; using namespace llvm; Server::Server(std::string name, std::string version, - std::unique_ptr<Transport> transport_up, + std::unique_ptr<MCPTransport> transport_up, lldb_private::MainLoop &loop) : m_name(std::move(name)), m_version(std::move(version)), m_transport_up(std::move(transport_up)), m_loop(loop) { @@ -180,7 +180,7 @@ llvm::Expected<Response> Server::ResourcesReadHandler(const Request &request) { return make_error<MCPError>( llvm::formatv("no resource handler for uri: {0}", uri_str).str(), - eErrorCodeResourceNotFound); + MCPError::kResourceNotFound); } ServerCapabilities Server::GetCapabilities() { @@ -219,7 +219,7 @@ void Server::Received(const Request &request) { response.takeError(), [&](const MCPError &err) { protocol_error = err.toProtocolError(); }, [&](const llvm::ErrorInfoBase &err) { - protocol_error.code = eErrorCodeInternalError; + protocol_error.code = MCPError::kInternalError; protocol_error.message = err.message(); }); Response error_response; diff --git a/lldb/source/Protocol/MCP/Transport.cpp b/lldb/source/Protocol/MCP/Transport.cpp deleted file mode 100644 index 58c66af7320ed..0000000000000 --- a/lldb/source/Protocol/MCP/Transport.cpp +++ /dev/null @@ -1,32 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "lldb/Protocol/MCP/Transport.h" -#include "lldb/Host/JSONTransport.h" -#include "lldb/lldb-forward.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/Support/FormatVariadic.h" -#include <string> -#include <utility> - -using namespace llvm; -using namespace lldb; - -namespace lldb_protocol::mcp { - -Transport::Transport(IOObjectSP in, IOObjectSP out, std::string client_name, - LogCallback log_callback) - : JSONRPCTransport(in, out), m_client_name(std::move(client_name)), - m_log_callback(log_callback) {} - -void Transport::Log(StringRef message) { - if (m_log_callback) - m_log_callback(formatv("{0}: {1}", m_client_name, message).str()); -} - -} // namespace lldb_protocol::mcp diff --git a/lldb/unittests/Protocol/ProtocolMCPServerTest.cpp b/lldb/unittests/Protocol/ProtocolMCPServerTest.cpp index 846582ab9a74e..9fa446133d46f 100644 --- a/lldb/unittests/Protocol/ProtocolMCPServerTest.cpp +++ b/lldb/unittests/Protocol/ProtocolMCPServerTest.cpp @@ -21,7 +21,6 @@ #include "lldb/Protocol/MCP/Resource.h" #include "lldb/Protocol/MCP/Server.h" #include "lldb/Protocol/MCP/Tool.h" -#include "lldb/Protocol/MCP/Transport.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Support/JSON.h" @@ -37,12 +36,12 @@ using namespace lldb_private; using namespace lldb_protocol::mcp; namespace { -class TestMCPTransport final : public lldb_protocol::mcp::Transport { +class TestMCPTransport final : public MCPTransport { public: TestMCPTransport(lldb::IOObjectSP in, lldb::IOObjectSP out) - : lldb_protocol::mcp::Transport(in, out, "unittest") {} + : lldb_protocol::mcp::MCPTransport(in, out, "unittest") {} - using Transport::Write; + using MCPTransport::Write; void Log(llvm::StringRef message) override { log_messages.emplace_back(message); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits