forked from Palm1r/QodeAssist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLSPCompletion.hpp
144 lines (127 loc) · 4.91 KB
/
LSPCompletion.hpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright (C) 2023 The Qt Company Ltd.
* Copyright (C) 2024 Petr Mironychev
*
* This file is part of QodeAssist.
*
* The Qt Company portions:
* SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
*
* Petr Mironychev portions:
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <languageserverprotocol/jsonkeys.h>
#include <languageserverprotocol/jsonrpcmessages.h>
#include <languageserverprotocol/lsptypes.h>
namespace QodeAssist {
class Completion : public LanguageServerProtocol::JsonObject
{
static constexpr LanguageServerProtocol::Key displayTextKey{"displayText"};
static constexpr LanguageServerProtocol::Key uuidKey{"uuid"};
public:
using JsonObject::JsonObject;
QString displayText() const { return typedValue<QString>(displayTextKey); }
LanguageServerProtocol::Position position() const
{
return typedValue<LanguageServerProtocol::Position>(LanguageServerProtocol::positionKey);
}
void setRange(const LanguageServerProtocol::Range &range)
{
insert(LanguageServerProtocol::rangeKey, range);
}
LanguageServerProtocol::Range range() const
{
return typedValue<LanguageServerProtocol::Range>(LanguageServerProtocol::rangeKey);
}
QString text() const { return typedValue<QString>(LanguageServerProtocol::textKey); }
void setText(const QString &text) { insert(LanguageServerProtocol::textKey, text); }
QString uuid() const { return typedValue<QString>(uuidKey); }
bool isValid() const override
{
return contains(LanguageServerProtocol::textKey)
&& contains(LanguageServerProtocol::rangeKey)
&& contains(LanguageServerProtocol::positionKey);
}
};
class GetCompletionParams : public LanguageServerProtocol::JsonObject
{
public:
static constexpr LanguageServerProtocol::Key docKey{"doc"};
GetCompletionParams(const LanguageServerProtocol::TextDocumentIdentifier &document,
int version,
const LanguageServerProtocol::Position &position)
{
setTextDocument(document);
setVersion(version);
setPosition(position);
}
using JsonObject::JsonObject;
// The text document.
LanguageServerProtocol::TextDocumentIdentifier textDocument() const
{
return typedValue<LanguageServerProtocol::TextDocumentIdentifier>(docKey);
}
void setTextDocument(const LanguageServerProtocol::TextDocumentIdentifier &id)
{
insert(docKey, id);
}
// The position inside the text document.
LanguageServerProtocol::Position position() const
{
return LanguageServerProtocol::fromJsonValue<LanguageServerProtocol::Position>(
value(docKey).toObject().value(LanguageServerProtocol::positionKey));
}
void setPosition(const LanguageServerProtocol::Position &position)
{
QJsonObject result = value(docKey).toObject();
result[LanguageServerProtocol::positionKey] = (QJsonObject) position;
insert(docKey, result);
}
// The version
int version() const { return typedValue<int>(LanguageServerProtocol::versionKey); }
void setVersion(int version)
{
QJsonObject result = value(docKey).toObject();
result[LanguageServerProtocol::versionKey] = version;
insert(docKey, result);
}
bool isValid() const override
{
return contains(docKey)
&& value(docKey).toObject().contains(LanguageServerProtocol::positionKey)
&& value(docKey).toObject().contains(LanguageServerProtocol::versionKey);
}
};
class GetCompletionResponse : public LanguageServerProtocol::JsonObject
{
static constexpr LanguageServerProtocol::Key completionKey{"completions"};
public:
using JsonObject::JsonObject;
LanguageServerProtocol::LanguageClientArray<Completion> completions() const
{
return clientArray<Completion>(completionKey);
}
};
class GetCompletionRequest
: public LanguageServerProtocol::Request<GetCompletionResponse, std::nullptr_t, GetCompletionParams>
{
public:
explicit GetCompletionRequest(const GetCompletionParams ¶ms = {})
: Request(methodName, params)
{}
using Request::Request;
constexpr static const LanguageServerProtocol::Key methodName{"getCompletionsCycling"};
};
} // namespace QodeAssist