summaryrefslogtreecommitdiff
path: root/graphics/asymptote/LspCpp/src/jsonrpc/Endpoint.cpp
blob: fe80eb7081728fdf1a44a8f3e5586c7d5edb54e9 (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
#include "LibLsp/JsonRpc/Endpoint.h"
#include "LibLsp/JsonRpc/message.h"

bool GenericEndpoint::notify(std::unique_ptr<LspMessage> msg)
{
    auto findIt = method2notification.find(msg->GetMethodType());

    if (findIt != method2notification.end())
    {
        return findIt->second(std::move(msg));
    }
    std::string info = "can't find method2notification for notification:\n" + msg->ToJson() + "\n";
    log.log(lsp::Log::Level::SEVERE, info);
    return false;
}

bool GenericEndpoint::onResponse(std::string const& method, std::unique_ptr<LspMessage> msg)
{
    auto findIt = method2response.find(method);

    if (findIt != method2response.end())
    {
        return findIt->second(std::move(msg));
    }

    std::string info = "can't find method2response for response:\n" + msg->ToJson() + "\n";
    log.log(lsp::Log::Level::SEVERE, info);

    return false;
}

bool GenericEndpoint::onRequest(std::unique_ptr<LspMessage> request)
{
    auto findIt = method2request.find(request->GetMethodType());

    if (findIt != method2request.end())
    {
        return findIt->second(std::move(request));
    }
    std::string info = "can't find method2request for request:\n" + request->ToJson() + "\n";
    log.log(lsp::Log::Level::SEVERE, info);
    return false;
}