2018-07-13 12:33:46 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
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);
|
2019-07-24 13:40:12 +02:00
|
|
|
static Client *startClient(BaseSettings *setting, ProjectExplorer::Project *project = nullptr);
|
2019-01-31 12:15:43 +01:00
|
|
|
static QVector<Client *> clients();
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2019-01-31 12:15:43 +01:00
|
|
|
static void addExclusiveRequest(const LanguageServerProtocol::MessageId &id, Client *client);
|
|
|
|
|
static void reportFinished(const LanguageServerProtocol::MessageId &id, Client *byClient);
|
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();
|
|
|
|
|
|
|
|
|
|
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);
|
2019-10-17 10:03:57 +02:00
|
|
|
static void enableClientSettings(const QString &settingsId);
|
2019-05-09 09:13:54 +02:00
|
|
|
static QVector<Client *> clientForSetting(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);
|
|
|
|
|
static Client *clientForUri(const LanguageServerProtocol::DocumentUri &uri);
|
2021-02-23 13:51:41 +01:00
|
|
|
static const QList<Client *> clientsForProject(const ProjectExplorer::Project *project);
|
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
|
|
|
|
2020-02-20 10:13:14 +01:00
|
|
|
static void logBaseMessage(const LspLogMessage::MessageSender sender,
|
|
|
|
|
const QString &clientName,
|
|
|
|
|
const LanguageServerProtocol::BaseMessage &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:
|
|
|
|
|
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
|
|
|
void projectRemoved(ProjectExplorer::Project *project);
|
|
|
|
|
|
2019-01-31 12:15:43 +01:00
|
|
|
QVector<Client *> reachableClients();
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2018-09-13 15:31:00 +02:00
|
|
|
bool m_shuttingDown = false;
|
2019-01-31 12:15:43 +01:00
|
|
|
QVector<Client *> m_clients;
|
2019-03-27 15:09:08 +01:00
|
|
|
QList<BaseSettings *> m_currentSettings; // owned
|
2019-05-09 09:13:54 +02:00
|
|
|
QMap<QString, QVector<Client *>> m_clientsForSetting;
|
2019-09-11 11:15:39 +02:00
|
|
|
QHash<TextEditor::TextDocument *, QPointer<Client>> m_clientForDocument;
|
2019-01-31 12:15:43 +01:00
|
|
|
QHash<LanguageServerProtocol::MessageId, QList<Client *>> m_exclusiveRequests;
|
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
|
|
|
};
|
|
|
|
|
} // namespace LanguageClient
|