Skip to content

Commit 49c1462

Browse files
committed
Improving comment formatting.
1 parent 04b8f02 commit 49c1462

File tree

3 files changed

+82
-81
lines changed

3 files changed

+82
-81
lines changed

lldb/include/lldb/Host/JSONTransport.h

Lines changed: 70 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,19 @@ class MethodNotFound : public llvm::ErrorInfo<MethodNotFound> {
9595
std::string m_method;
9696
};
9797

98-
// FIXME: Once we upgrade to c++20, use this concept for JSONTransport.
99-
// template <typename T>
100-
// concept ProtocolDescriptor = requires {
101-
// typename T::Id;
102-
// typename T::Req;
103-
// typename T::Resp;
104-
// typename T::Evt;
105-
// };
98+
/*
99+
FIXME: Once we upgrade to c++20, use this concept for JSONTransport.
100+
101+
/// A ProtocolDescriptor details the types used in a JSONTransport for handling
102+
/// transport communication.
103+
template <typename T>
104+
concept ProtocolDescriptor = requires {
105+
typename T::Id;
106+
typename T::Req;
107+
typename T::Resp;
108+
typename T::Evt;
109+
};
110+
*/
106111

107112
/// A transport is responsible for maintaining the connection to a client
108113
/// application, and reading/writing structured messages to it.
@@ -111,17 +116,14 @@ class MethodNotFound : public llvm::ErrorInfo<MethodNotFound> {
111116
/// - Messages will not be sent concurrently.
112117
/// - Messages MAY be sent while Run() is reading, or its callback is active.
113118
///
114-
/// FIXME: Once we upgrade to c++20, use template <ProtocolDescriptor Proto>
119+
/// FIXME: Once we upgrade to c++20, use `template <ProtocolDescriptor Proto>`
115120
template <typename Proto> class JSONTransport {
116121
public:
117122
using Req = typename Proto::Req;
118123
using Resp = typename Proto::Resp;
119124
using Evt = typename Proto::Evt;
120125
using Message = std::variant<Req, Resp, Evt>;
121126

122-
// class Binder;
123-
// using BinderUP = std::unique_ptr<Binder>;
124-
125127
virtual ~JSONTransport() = default;
126128

127129
/// Sends an event, a message that does not require a response.
@@ -382,51 +384,56 @@ using OutgoingRequest = typename detail::request_t<R, P>::type;
382384
/// A function to send an outgoing event.
383385
template <typename P> using OutgoingEvent = typename detail::event_t<P>::type;
384386

385-
// FIXME: With c++20, we should use this concept:
386-
// template <typename T>
387-
// concept BindingBuilder =
388-
// ProtocolDescriptor<T> &&
389-
// requires(T::Id id, T::Req req, T::Resp resp, T::Evt evt,
390-
// llvm::StringRef method, std::optional<llvm::json::Value> params,
391-
// std::optional<llvm::json::Value> result, llvm::Error err) {
392-
// // For initializing the unique sequence identifier;
393-
// { T::InitialId() } -> std::same_as<typename T::Id>;
394-
// // Incrementing the sequence identifier.
395-
// { id++ } -> std::same_as<typename T::Id>;
396-
//
397-
// // Constructing protocol types
398-
// // @{
399-
// // Construct a new request.
400-
// { T::Make(id, method, params) } -> std::same_as<typename T::Req>;
401-
// // Construct a new error response.
402-
// { T::Make(req, std::move(err)) } -> std::same_as<typename T::Resp>;
403-
// // Construct a new success response.
404-
// { T::Make(req, result) } -> std::same_as<typename T::Resp>;
405-
// // Construct a new event.
406-
// { T::Make(method, params) } -> std::same_as<typename T::Evt>;
407-
// // @}
408-
//
409-
// // Keys for associated types.
410-
// // @{
411-
// // Looking up in flight responses.
412-
// { T::KeyFor(resp) } -> std::same_as<typename T::Id>;
413-
// // Extract method from request.
414-
// { T::KeyFor(req) } -> std::same_as<llvm::StringRef>;
415-
// // Extract method from event.
416-
// { T::KeyFor(evt) } -> std::same_as<llvm::StringRef>;
417-
// // @}
418-
//
419-
// // Extracting information from associated types.
420-
// // @{
421-
// // Extract parameters from a request.
422-
// { T::Extract(req) } -> std::same_as<std::optional<llvm::json::Value>>;
423-
// // Extract result from a response.
424-
// { T::Extract(resp) } ->
425-
// std::same_as<llvm::Expected<llvm::json::Value>>;
426-
// // Extract parameters from an event.
427-
// { T::Extract(evt) } -> std::same_as<std::optional<llvm::json::Value>>;
428-
// // @}
429-
// };
387+
/*
388+
FIXME: With c++20, we should use this concept:
389+
390+
/// This represents a protocol description that includes additional helpers
391+
/// for constructing requests, responses and events to work with `Binder`.
392+
template <typename T>
393+
concept BindingBuilder =
394+
ProtocolDescriptor<T> &&
395+
requires(T::Id id, T::Req req, T::Resp resp, T::Evt evt,
396+
llvm::StringRef method, std::optional<llvm::json::Value> params,
397+
std::optional<llvm::json::Value> result, llvm::Error err) {
398+
/// For initializing the unique sequence identifier;
399+
{ T::InitialId() } -> std::same_as<typename T::Id>;
400+
/// Incrementing the sequence identifier.
401+
{ id++ } -> std::same_as<typename T::Id>;
402+
403+
/// Constructing protocol types
404+
/// @{
405+
/// Construct a new request.
406+
{ T::Make(id, method, params) } -> std::same_as<typename T::Req>;
407+
/// Construct a new error response.
408+
{ T::Make(req, std::move(err)) } -> std::same_as<typename T::Resp>;
409+
/// Construct a new success response.
410+
{ T::Make(req, result) } -> std::same_as<typename T::Resp>;
411+
/// Construct a new event.
412+
{ T::Make(method, params) } -> std::same_as<typename T::Evt>;
413+
/// @}
414+
415+
/// Keys for associated types.
416+
/// @{
417+
/// Looking up in flight responses.
418+
{ T::KeyFor(resp) } -> std::same_as<typename T::Id>;
419+
/// Extract method from request.
420+
{ T::KeyFor(req) } -> std::same_as<llvm::StringRef>;
421+
/// Extract method from event.
422+
{ T::KeyFor(evt) } -> std::same_as<llvm::StringRef>;
423+
/// @}
424+
425+
/// Extracting information from associated types.
426+
/// @{
427+
/// Extract parameters from a request.
428+
{ T::Extract(req) } -> std::same_as<std::optional<llvm::json::Value>>;
429+
/// Extract result from a response.
430+
{ T::Extract(resp) } ->
431+
std::same_as<llvm::Expected<llvm::json::Value>>;
432+
/// Extract parameters from an event.
433+
{ T::Extract(evt) } -> std::same_as<std::optional<llvm::json::Value>>;
434+
/// @}
435+
};
436+
*/
430437

431438
/// Binder collects a table of functions that handle calls.
432439
///
@@ -435,25 +442,26 @@ template <typename P> using OutgoingEvent = typename detail::event_t<P>::type;
435442
/// This allows a JSONTransport to handle incoming and outgoing requests and
436443
/// events.
437444
///
438-
/// A simple example could be to a method to a lambda like:
439-
///
445+
/// A bind of an incoming request to a lambda.
440446
/// \code{cpp}
441447
/// Binder binder{transport};
442-
/// // Binds an incoming request handler.
443448
/// binder.bind<int, vector<int>>("adder", [](const vector<int> &params) {
444449
/// int sum = 0;
445450
/// for (int v : params)
446451
/// sum += v;
447452
/// return sum;
448453
/// });
449-
/// // Binds an outgoing request handler.
454+
/// \endcode
455+
///
456+
/// A bind of an outgoing request.
457+
/// \code{cpp}
450458
/// OutgoingRequest<int, vector<int>> call_add =
451459
/// binder.bind<int, vector<int>>("add");
452460
/// call_add({1,2,3}, [](Expected<int> result) {
453461
/// cout << *result << "\n";
454462
/// });
455463
/// \endcode
456-
// FIXME: In c++20 use: template <BindingBuilder Proto>
464+
/// FIXME: In c++20 use `template <BindingBuilder Proto>`.
457465
template <typename Proto>
458466
class Binder : public JSONTransport<Proto>::MessageHandler {
459467
using Req = Proto::Req;

lldb/include/lldb/Protocol/MCP/Protocol.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,4 @@ MakeRequest(int64_t id, llvm::StringRef method,
329329

330330
} // namespace lldb_protocol::mcp
331331

332-
// namespace llvm::json {
333-
// inline Value toJSON(const lldb_protocol::mcp::Void &) { return Object(); }
334-
// inline bool fromJSON(const Value &, lldb_protocol::mcp::Void &, Path) {
335-
// return true;
336-
// }
337-
// } // namespace llvm::json
338-
339332
#endif

lldb/source/Protocol/MCP/Server.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,20 @@ void Server::AddResourceProvider(
127127
}
128128

129129
MCPBinderUP Server::Bind(MCPTransport &transport) {
130-
MCPBinderUP binder = std::make_unique<MCPBinder>(transport);
131-
binder->Bind<InitializeResult, InitializeParams>(
130+
MCPBinderUP binder_up = std::make_unique<MCPBinder>(transport);
131+
binder_up->Bind<InitializeResult, InitializeParams>(
132132
"initialize", &Server::InitializeHandler, this);
133-
binder->Bind<ListToolsResult, void>("tools/list", &Server::ToolsListHandler,
134-
this);
135-
binder->Bind<CallToolResult, CallToolParams>("tools/call",
136-
&Server::ToolsCallHandler, this);
137-
binder->Bind<ListResourcesResult, void>("resources/list",
138-
&Server::ResourcesListHandler, this);
139-
binder->Bind<ReadResourceResult, ReadResourceParams>(
133+
binder_up->Bind<ListToolsResult, void>("tools/list",
134+
&Server::ToolsListHandler, this);
135+
binder_up->Bind<CallToolResult, CallToolParams>(
136+
"tools/call", &Server::ToolsCallHandler, this);
137+
binder_up->Bind<ListResourcesResult, void>(
138+
"resources/list", &Server::ResourcesListHandler, this);
139+
binder_up->Bind<ReadResourceResult, ReadResourceParams>(
140140
"resources/read", &Server::ResourcesReadHandler, this);
141-
binder->Bind<void>("notifications/initialized",
142-
[this]() { Log("MCP initialization complete"); });
143-
return binder;
141+
binder_up->Bind<void>("notifications/initialized",
142+
[this]() { Log("MCP initialization complete"); });
143+
return binder_up;
144144
}
145145

146146
llvm::Error Server::Accept(MainLoop &loop, MCPTransportUP transport) {

0 commit comments

Comments
 (0)