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