1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef JSONRPCCALLPROXY_H
6#define JSONRPCCALLPROXY_H
7
8#include "common/lsp/lsp.h"
9
10#include <QProcess>
11
12/**
13 * @brief The JsonRpcCallProxy class
14 * only create main thread
15 */
16class JsonRpcCallProxy : public newlsp::Route
17{
18 Q_OBJECT
19public:
20 typedef std::function<QProcess*(const newlsp::ProjectKey&)> ProcCreatFunc;
21 typedef std::function<bool (const QJsonObject &, QJsonObject &)> MethodFilterFunc;
22 typedef std::function<void (const QJsonObject &)> NotificationFilterFunc;
23
24 JsonRpcCallProxy(const JsonRpcCallProxy &) = delete;
25 explicit JsonRpcCallProxy(QObject *parent = nullptr);
26
27 static JsonRpcCallProxy &ins();
28
29 bool bindCreateProc(const std::string &language, const ProcCreatFunc &func);
30 QProcess *createLspServ(const newlsp::ProjectKey &key);
31
32 void bindFilter(const QString &methodName, const MethodFilterFunc &func);
33 void bindFilter(const QString &methodName, const NotificationFilterFunc &func);
34
35 newlsp::ProjectKey getSelect() { return select; }
36 void setSelect(const newlsp::ProjectKey &value) { select = value;}
37
38public slots:
39 void methodFilter(int id, const QString &method, const QJsonObject &params);
40 void notificationFilter(const QString &method, const QJsonObject &params);
41
42private:
43 newlsp::ProjectKey select;
44 QHash<QString, MethodFilterFunc> redMethods;
45 QHash<QString, NotificationFilterFunc> redNotifications;
46 QHash<QString, ProcCreatFunc> createFuncs;
47};
48
49#endif // JSONRPCCALLPROXY_H
50