Debian Codegraph @

LspCpp/src/jsonrpc/Endpoint.cpp

raw
1 #include "LibLsp/JsonRpc/Endpoint.h"
2 #include "LibLsp/JsonRpc/message.h"
3
4 bool GenericEndpoint::notify(std::unique_ptr<LspMessage> msg)
5 {
6 auto findIt = method2notification.find(msg->GetMethodType());
7
8 if (findIt != method2notification.end())
9 {
10 return findIt->second(std::move(msg));
11 }
12 std::string info = "can't find method2notification for notification:\n" + msg->ToJson() + "\n";
13 log.log(lsp::Log::Level::SEVERE, info);
14 return false;
15 }
16
17 bool GenericEndpoint::onResponse(std::string const& method, std::unique_ptr<LspMessage> msg)
18 {
19 auto findIt = method2response.find(method);
20
21 if (findIt != method2response.end())
22 {
23 return findIt->second(std::move(msg));
24 }
25
26 std::string info = "can't find method2response for response:\n" + msg->ToJson() + "\n";
27 log.log(lsp::Log::Level::SEVERE, info);
28
29 return false;
30 }
31
32 bool GenericEndpoint::onRequest(std::unique_ptr<LspMessage> request)
33 {
34 auto findIt = method2request.find(request->GetMethodType());
35
36 if (findIt != method2request.end())
37 {
38 return findIt->second(std::move(request));
39 }
40 std::string info = "can't find method2request for request:\n" + request->ToJson() + "\n";
41 log.log(lsp::Log::Level::SEVERE, info);
42 return false;
43 }