[Lldb-commits] [lldb] [lldb] Refactoring JSONTransport into an abstract RPC Message Handler and transport layer. (PR #153121)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Aug 13 15:31:38 PDT 2025
================
@@ -258,36 +259,33 @@ void DAP::SendJSON(const llvm::json::Value &json) {
llvm::json::Path::Root root;
if (!fromJSON(json, message, root)) {
DAP_LOG_ERROR(log, root.getError(), "({1}) encoding failed: {0}",
- transport.GetClientName());
+ m_client_name);
return;
}
Send(message);
}
void DAP::Send(const Message &message) {
- // FIXME: After all the requests have migrated from LegacyRequestHandler >
- // RequestHandler<> this should be handled in RequestHandler<>::operator().
- if (auto *resp = std::get_if<Response>(&message);
- resp && debugger.InterruptRequested()) {
- // Clear the interrupt request.
- debugger.CancelInterruptRequest();
-
- // If the debugger was interrupted, convert this response into a 'cancelled'
- // response because we might have a partial result.
- Response cancelled{/*request_seq=*/resp->request_seq,
- /*command=*/resp->command,
- /*success=*/false,
- /*message=*/eResponseMessageCancelled,
- /*body=*/std::nullopt};
- if (llvm::Error err = transport.Write(cancelled))
- DAP_LOG_ERROR(log, std::move(err), "({1}) write failed: {0}",
- transport.GetClientName());
- return;
+ if (const protocol::Event *event = std::get_if<protocol::Event>(&message)) {
+ transport.Event(*event);
+ } else if (const Request *req = std::get_if<Request>(&message)) {
+ transport.Request(*req);
+ } else if (const Response *resp = std::get_if<Response>(&message)) {
+ // FIXME: After all the requests have migrated from LegacyRequestHandler >
+ // RequestHandler<> this should be handled in RequestHandler<>::operator().
+ if (debugger.InterruptRequested())
+ // If the debugger was interrupted, convert this response into a
+ // 'cancelled' response because we might have a partial result.
+ transport.Response(Response{/*request_seq=*/resp->request_seq,
+ /*command=*/resp->command,
+ /*success=*/false,
+ /*message=*/eResponseMessageCancelled,
+ /*body=*/std::nullopt});
+ else
+ transport.Response(*resp);
----------------
JDevlieghere wrote:
According to the style guide, this does require braces:
```suggestion
if (debugger.InterruptRequested()) {
// If the debugger was interrupted, convert this response into a
// 'cancelled' response because we might have a partial result.
transport.Response(Response{/*request_seq=*/resp->request_seq,
/*command=*/resp->command,
/*success=*/false,
/*message=*/eResponseMessageCancelled,
/*body=*/std::nullopt});
} else {
transport.Response(*resp);
}
```
https://github.com/llvm/llvm-project/pull/153121
More information about the lldb-commits
mailing list