2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2018 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2018-07-13 12:33:46 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-01-31 12:15:43 +01:00
|
|
|
#include "client.h"
|
2019-09-18 14:43:08 +02:00
|
|
|
#include "languageclient_global.h"
|
2018-09-10 15:15:37 +02:00
|
|
|
#include "languageclientsettings.h"
|
2019-04-05 10:05:25 +02:00
|
|
|
#include "locatorfilter.h"
|
2021-02-10 14:03:45 +01:00
|
|
|
#include "lspinspector.h"
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2021-09-03 17:14:54 +02:00
|
|
|
#include <utils/algorithm.h>
|
2020-06-26 13:59:38 +02:00
|
|
|
#include <utils/id.h>
|
2018-07-13 12:33:46 +02:00
|
|
|
|
|
|
|
|
#include <languageserverprotocol/diagnostics.h>
|
|
|
|
|
#include <languageserverprotocol/languagefeatures.h>
|
|
|
|
|
#include <languageserverprotocol/textsynchronization.h>
|
|
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
class IEditor;
|
|
|
|
|
class IDocument;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer { class Project; }
|
|
|
|
|
|
|
|
|
|
namespace LanguageClient {
|
|
|
|
|
|
|
|
|
|
class LanguageClientMark;
|
|
|
|
|
|
2019-09-18 14:43:08 +02:00
|
|
|
class LANGUAGECLIENT_EXPORT LanguageClientManager : public QObject
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2018-11-14 01:21:20 +01:00
|
|
|
LanguageClientManager(const LanguageClientManager &other) = delete;
|
|
|
|
|
LanguageClientManager(LanguageClientManager &&other) = delete;
|
2018-07-13 12:33:46 +02:00
|
|
|
~LanguageClientManager() override;
|
|
|
|
|
|
|
|
|
|
static void init();
|
|
|
|
|
|
2021-02-12 14:01:24 +01:00
|
|
|
static void clientStarted(Client *client);
|
|
|
|
|
static void clientFinished(Client *client);
|
2022-03-14 09:34:12 +01:00
|
|
|
static Client *startClient(const BaseSettings *setting, ProjectExplorer::Project *project = nullptr);
|
2022-05-31 16:35:10 +02:00
|
|
|
static const QList<Client *> clients();
|
2021-08-25 13:55:45 +02:00
|
|
|
static void addClient(Client *client);
|
2023-01-09 14:37:19 +01:00
|
|
|
static void restartClient(Client *client);
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2019-05-09 09:13:54 +02:00
|
|
|
static void shutdownClient(Client *client);
|
2019-01-31 12:15:43 +01:00
|
|
|
static void deleteClient(Client *client);
|
2018-09-13 13:39:01 +02:00
|
|
|
|
2018-09-13 15:31:00 +02:00
|
|
|
static void shutdown();
|
2022-09-22 09:27:10 +02:00
|
|
|
static bool isShuttingDown();
|
2018-09-13 15:31:00 +02:00
|
|
|
|
|
|
|
|
static LanguageClientManager *instance();
|
|
|
|
|
|
2019-09-11 11:15:39 +02:00
|
|
|
static QList<Client *> clientsSupportingDocument(const TextEditor::TextDocument *doc);
|
2018-11-23 09:45:51 +01:00
|
|
|
|
2019-03-27 15:09:08 +01:00
|
|
|
static void applySettings();
|
|
|
|
|
static QList<BaseSettings *> currentSettings();
|
2019-09-18 14:50:42 +02:00
|
|
|
static void registerClientSettings(BaseSettings *settings);
|
2022-06-22 13:46:50 +02:00
|
|
|
static void enableClientSettings(const QString &settingsId, bool enable = true);
|
2022-03-14 08:56:32 +01:00
|
|
|
static QList<Client *> clientsForSetting(const BaseSettings *setting);
|
2019-03-15 11:25:48 +01:00
|
|
|
static const BaseSettings *settingForClient(Client *setting);
|
2019-09-11 11:15:39 +02:00
|
|
|
static Client *clientForDocument(TextEditor::TextDocument *document);
|
2019-09-10 08:03:58 +02:00
|
|
|
static Client *clientForFilePath(const Utils::FilePath &filePath);
|
2021-02-23 13:51:41 +01:00
|
|
|
static const QList<Client *> clientsForProject(const ProjectExplorer::Project *project);
|
2021-09-03 17:14:54 +02:00
|
|
|
template<typename T> static bool hasClients();
|
2020-05-12 09:20:01 +02:00
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// \brief openDocumentWithClient
|
|
|
|
|
/// makes sure the document is opened and activated with the client and
|
|
|
|
|
/// deactivates the document for a potential previous active client
|
|
|
|
|
///
|
|
|
|
|
static void openDocumentWithClient(TextEditor::TextDocument *document, Client *client);
|
2019-03-27 15:09:08 +01:00
|
|
|
|
2022-05-10 11:40:56 +02:00
|
|
|
static void logJsonRpcMessage(const LspLogMessage::MessageSender sender,
|
|
|
|
|
const QString &clientName,
|
|
|
|
|
const LanguageServerProtocol::JsonRpcMessage &message);
|
|
|
|
|
|
2021-02-10 14:03:45 +01:00
|
|
|
static void showInspector();
|
2020-02-20 10:13:14 +01:00
|
|
|
|
2018-09-13 15:31:00 +02:00
|
|
|
signals:
|
2022-08-02 16:08:14 +02:00
|
|
|
void clientAdded(Client *client);
|
2021-06-18 16:30:03 +02:00
|
|
|
void clientRemoved(Client *client);
|
2018-09-13 15:31:00 +02:00
|
|
|
void shutdownFinished();
|
|
|
|
|
|
2018-07-13 12:33:46 +02:00
|
|
|
private:
|
2019-03-27 14:05:30 +01:00
|
|
|
LanguageClientManager(QObject *parent);
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2019-03-12 12:53:13 +01:00
|
|
|
void editorOpened(Core::IEditor *editor);
|
2019-03-12 12:46:38 +01:00
|
|
|
void documentOpened(Core::IDocument *document);
|
|
|
|
|
void documentClosed(Core::IDocument *document);
|
2018-07-13 12:33:46 +02:00
|
|
|
void documentContentsSaved(Core::IDocument *document);
|
|
|
|
|
void documentWillSave(Core::IDocument *document);
|
|
|
|
|
|
2020-05-11 15:00:07 +02:00
|
|
|
void updateProject(ProjectExplorer::Project *project);
|
2020-05-22 12:06:30 +02:00
|
|
|
void projectAdded(ProjectExplorer::Project *project);
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2022-03-14 08:36:37 +01:00
|
|
|
QList<Client *> reachableClients();
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2022-03-14 08:36:37 +01:00
|
|
|
QList<Client *> m_clients;
|
2023-01-09 14:37:19 +01:00
|
|
|
QSet<Client *> m_restartingClients;
|
2019-03-27 15:09:08 +01:00
|
|
|
QList<BaseSettings *> m_currentSettings; // owned
|
2022-03-14 08:36:37 +01:00
|
|
|
QMap<QString, QList<Client *>> m_clientsForSetting;
|
2019-09-11 11:15:39 +02:00
|
|
|
QHash<TextEditor::TextDocument *, QPointer<Client>> m_clientForDocument;
|
2019-04-05 10:05:25 +02:00
|
|
|
DocumentLocatorFilter m_currentDocumentLocatorFilter;
|
2019-04-30 11:05:43 +02:00
|
|
|
WorkspaceLocatorFilter m_workspaceLocatorFilter;
|
|
|
|
|
WorkspaceClassLocatorFilter m_workspaceClassLocatorFilter;
|
|
|
|
|
WorkspaceMethodLocatorFilter m_workspaceMethodLocatorFilter;
|
2021-02-10 14:03:45 +01:00
|
|
|
LspInspector m_inspector;
|
2018-07-13 12:33:46 +02:00
|
|
|
};
|
2021-09-03 17:14:54 +02:00
|
|
|
|
|
|
|
|
template<typename T> bool LanguageClientManager::hasClients()
|
|
|
|
|
{
|
|
|
|
|
return Utils::contains(instance()->m_clients, [](const Client *c) {
|
|
|
|
|
return qobject_cast<const T* >(c);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 12:33:46 +02:00
|
|
|
} // namespace LanguageClient
|