aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/lsp/messages.h
blob: 8c7d05c6d03ffc8043a8cc2534fd63bbf9112c51 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include "jsonrpcmessages.h"

namespace lsp {

enum MessageType {
    Error = 1,
    Warning = 2,
    Info = 3,
    Log = 4,
};

class LANGUAGESERVERPROTOCOL_EXPORT ShowMessageParams : public JsonObject
{
public:
    using JsonObject::JsonObject;

    int type() const { return typedValue<int>(typeKey); }
    void setType(int type) { insert(typeKey, type); }

    QString message() const { return typedValue<QString>(messageKey); }
    void setMessage(QString message) { insert(messageKey, message); }

    QString toString() const;

    bool isValid() const override
    { return contains(typeKey) && contains(messageKey); }
};

class LANGUAGESERVERPROTOCOL_EXPORT ShowMessageNotification : public Notification<ShowMessageParams>
{
public:
    explicit ShowMessageNotification(const ShowMessageParams &params);
    using Notification::Notification;
    constexpr static const char methodName[] = "window/showMessage";
};

class LANGUAGESERVERPROTOCOL_EXPORT MessageActionItem : public JsonObject
{
public:
    using JsonObject::JsonObject;

    QString title() const { return typedValue<QString>(titleKey); }
    void setTitle(QString title) { insert(titleKey, title); }

    bool isValid() const override { return contains(titleKey); }
};

class LANGUAGESERVERPROTOCOL_EXPORT ShowMessageRequestParams : public ShowMessageParams
{
public:
    using ShowMessageParams::ShowMessageParams;

    std::optional<QList<MessageActionItem>> actions() const
    { return optionalArray<MessageActionItem>(actionsKey); }
    void setActions(const QList<MessageActionItem> &actions) { insertArray(actionsKey, actions); }
    void clearActions() { remove(actionsKey); }
};

class LANGUAGESERVERPROTOCOL_EXPORT ShowMessageRequest : public Request<
        LanguageClientValue<MessageActionItem>, std::nullptr_t, ShowMessageRequestParams>
{
public:
    explicit ShowMessageRequest(const ShowMessageRequestParams &params);
    using Request::Request;
    constexpr static const char methodName[] = "window/showMessageRequest";
};

using LogMessageParams = ShowMessageParams;

class LANGUAGESERVERPROTOCOL_EXPORT LogMessageNotification : public Notification<LogMessageParams>
{
public:
    explicit LogMessageNotification(const LogMessageParams &params);
    using Notification::Notification;
    constexpr static const char methodName[] = "window/logMessage";
};

class LANGUAGESERVERPROTOCOL_EXPORT TelemetryNotification : public Notification<JsonObject>
{
public:
    explicit TelemetryNotification(const JsonObject &params);
    using Notification::Notification;
    constexpr static const char methodName[] = "telemetry/event";

    bool parametersAreValid(QString * /*error*/) const override { return params().has_value(); }
};

} // namespace LanguageClient