Debian Codegraph @

LspCpp/src/jsonrpc/MessageJsonHandler.cpp

raw
1 #include "LibLsp/JsonRpc/MessageJsonHandler.h"
2 #include <string>
3 #include <rapidjson/document.h>
4
5 std::unique_ptr<LspMessage> MessageJsonHandler::parseResponseMessage(std::string const& method, Reader& r)
6 {
7 auto findIt = method2response.find(method);
8
9 if (findIt != method2response.end())
10 {
11 return findIt->second(r);
12 }
13 return nullptr;
14 }
15
16 std::unique_ptr<LspMessage> MessageJsonHandler::parseRequstMessage(std::string const& method, Reader& r)
17 {
18 auto findIt = method2request.find(method);
19
20 if (findIt != method2request.end())
21 {
22 return findIt->second(r);
23 }
24 return nullptr;
25 }
26
27 bool MessageJsonHandler::resovleResponseMessage(Reader& r, std::pair<std::string, std::unique_ptr<LspMessage>>& result)
28 {
29 for (auto& handler : method2response)
30 {
31 try
32 {
33 auto msg = handler.second(r);
34 result.first = handler.first;
35 result.second = std::move(msg);
36 return true;
37 }
38 catch (...)
39 {
40 }
41 }
42 return false;
43 }
44
45 std::unique_ptr<LspMessage> MessageJsonHandler::parseNotificationMessage(std::string const& method, Reader& r)
46 {
47 auto findIt = method2notification.find(method);
48
49 if (findIt != method2notification.end())
50 {
51 return findIt->second(r);
52 }
53 return nullptr;
54 }