blob: ab01242be067c95c5356a9510d325ee511f502a8 (
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
|
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtJsonRpc/private/qjsonrpcprotocol_p.h>
#include <QtLanguageServer/private/qlanguageserverprotocol_p.h>
#include <QtLanguageServer/private/qlanguageservergen_p_p.h>
#include <QtCore/qjsonobject.h>
#include <memory>
QT_BEGIN_NAMESPACE
using namespace QLspSpecification;
using namespace Qt::StringLiterals;
/*!
\internal
\class QLanguageServerProtocol
\brief Implements the language server protocol
QLanguageServerProtocol objects handles the language server
protocol both to send and receive (ask the client and reply to the
client).
To ask the client you use the requestXX or notifyXX methods.
To reply to client request you have to register your handlers via
registerXXRequestHandler, notifications can be handled connecting the
receivedXXNotification signals.
The method themselves are implemented in qlanguageservergen*
files which are generated form the specification.
You have to provide a function to send the data that the protocol
generates to the constructor, and you have to feed the data you
receive to it via the receivedData method.
Limitations: for the client use case (Creator),the handling of partial
results could be improved. A clean solution should handle the progress
notification, do some extra tracking and give the partial results back
to the call that did the request.
*/
QLanguageServerProtocol::QLanguageServerProtocol(const QJsonRpcTransport::DataHandler &sender)
: ProtocolGen(std::make_unique<ProtocolGenPrivate>())
{
transport()->setDataHandler(sender);
transport()->setDiagnosticHandler([this](QJsonRpcTransport::DiagnosticLevel l,
const QString &msg) {
handleResponseError(
ResponseError { int(ErrorCodes::InternalError), msg.toUtf8(),
QJsonObject({ { u"errorLevel"_s,
((l == QJsonRpcTransport::DiagnosticLevel::Error)
? u"error"_s
: u"warning"_s) } }) });
});
}
void QLanguageServerProtocol::receiveData(const QByteArray &data)
{
transport()->receiveData(data);
}
QT_END_NAMESPACE
|