1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QLANGUAGESERVER_P_H |
5 | #define QLANGUAGESERVER_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtLanguageServer/private/qlanguageserverspec_p.h> |
19 | #include <QtLanguageServer/private/qlanguageserverprotocol_p.h> |
20 | #include <QtLanguageServer/private/qlspnotifysignals_p.h> |
21 | #include <QtCore/qloggingcategory.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class QLanguageServer; |
26 | class QLanguageServerPrivate; |
27 | Q_DECLARE_LOGGING_CATEGORY(lspServerLog) |
28 | |
29 | class QLanguageServerModule : public QObject |
30 | { |
31 | Q_OBJECT |
32 | public: |
33 | QLanguageServerModule(QObject *parent = nullptr) : QObject(parent) { } |
34 | virtual QString name() const = 0; |
35 | virtual void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) = 0; |
36 | virtual void setupCapabilities(const QLspSpecification::InitializeParams &clientInfo, |
37 | QLspSpecification::InitializeResult &) = 0; |
38 | }; |
39 | |
40 | class QLanguageServer : public QObject |
41 | { |
42 | Q_OBJECT |
43 | Q_PROPERTY(RunStatus runStatus READ runStatus NOTIFY runStatusChanged) |
44 | Q_PROPERTY(bool isInitialized READ isInitialized) |
45 | public: |
46 | QLanguageServer(const QJsonRpcTransport::DataHandler &h, QObject *parent = nullptr); |
47 | enum class RunStatus { |
48 | NotSetup, |
49 | SettingUp, |
50 | DidSetup, |
51 | Initializing, |
52 | DidInitialize, // normal state of execution |
53 | WaitPending, |
54 | Stopping, |
55 | Stopped |
56 | }; |
57 | Q_ENUM(RunStatus) |
58 | |
59 | QLanguageServerProtocol *protocol(); |
60 | void finishSetup(); |
61 | void registerHandlers(QLanguageServerProtocol *protocol); |
62 | void setupCapabilities(const QLspSpecification::InitializeParams &clientInfo, |
63 | QLspSpecification::InitializeResult &serverInfo); |
64 | void addServerModule(QLanguageServerModule *serverModule); |
65 | QLanguageServerModule *moduleByName(const QString &n) const; |
66 | QLspNotifySignals *notifySignals(); |
67 | |
68 | // API |
69 | RunStatus runStatus() const; |
70 | bool isInitialized() const; |
71 | bool isRequestCanceled(const QJsonRpc::IdType &id) const; |
72 | const QLspSpecification::InitializeParams &clientInfo() const; |
73 | const QLspSpecification::InitializeResult &serverInfo() const; |
74 | |
75 | public Q_SLOTS: |
76 | void receiveData(const QByteArray &d); |
77 | Q_SIGNALS: |
78 | void runStatusChanged(RunStatus); |
79 | void clientInitialized(QLanguageServer *server); |
80 | void shutdown(); |
81 | void exit(); |
82 | void lifecycleError(); |
83 | |
84 | private: |
85 | void registerMethods(QJsonRpc::TypedRpc &typedRpc); |
86 | void executeShutdown(); |
87 | Q_DECLARE_PRIVATE(QLanguageServer) |
88 | }; |
89 | |
90 | QT_END_NAMESPACE |
91 | |
92 | #endif // QLANGUAGESERVER_P_H |
93 | |