forked from qt-creator/qt-creator
LanguageClient: move current settings to manager
In preparation to have relationship between clients, settings and project to one another in the manager. Change-Id: I00ae15abe03c54b4a58e429d67d6ff939662cce6 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/find/searchresultwindow.h>
|
#include <coreplugin/find/searchresultwindow.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
#include <languageserverprotocol/messages.h>
|
#include <languageserverprotocol/messages.h>
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
@@ -80,6 +81,7 @@ LanguageClientManager::LanguageClientManager(QObject *parent)
|
|||||||
LanguageClientManager::~LanguageClientManager()
|
LanguageClientManager::~LanguageClientManager()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_clients.isEmpty(), qDeleteAll(m_clients));
|
QTC_ASSERT(m_clients.isEmpty(), qDeleteAll(m_clients));
|
||||||
|
qDeleteAll(m_currentSettings);
|
||||||
managerInstance = nullptr;
|
managerInstance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +180,45 @@ QList<Client *> LanguageClientManager::clientsSupportingDocument(
|
|||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LanguageClientManager::applySettings()
|
||||||
|
{
|
||||||
|
QTC_ASSERT(instance(), return);
|
||||||
|
qDeleteAll(instance()->m_currentSettings);
|
||||||
|
instance()->m_currentSettings = Utils::transform(LanguageClientSettings::currentPageSettings(),
|
||||||
|
[](BaseSettings *settings) {
|
||||||
|
return settings->copy();
|
||||||
|
});
|
||||||
|
LanguageClientSettings::toSettings(Core::ICore::settings(), instance()->m_currentSettings);
|
||||||
|
|
||||||
|
const QList<BaseSettings *> restarts = Utils::filtered(LanguageClientManager::currentSettings(),
|
||||||
|
&BaseSettings::needsRestart);
|
||||||
|
|
||||||
|
for (BaseSettings *setting : restarts) {
|
||||||
|
if (auto client = setting->m_client) {
|
||||||
|
if (client->reachable())
|
||||||
|
client->shutdown();
|
||||||
|
else
|
||||||
|
deleteClient(client);
|
||||||
|
}
|
||||||
|
if (setting->isValid() && setting->m_enabled) {
|
||||||
|
const bool start = setting->m_alwaysOn
|
||||||
|
|| Utils::anyOf(Core::DocumentModel::openedDocuments(),
|
||||||
|
[filter = setting->m_languageFilter](
|
||||||
|
Core::IDocument *doc) {
|
||||||
|
return filter.isSupported(doc);
|
||||||
|
});
|
||||||
|
if (start)
|
||||||
|
setting->startClient();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<BaseSettings *> LanguageClientManager::currentSettings()
|
||||||
|
{
|
||||||
|
QTC_ASSERT(instance(), return {});
|
||||||
|
return instance()->m_currentSettings;
|
||||||
|
}
|
||||||
|
|
||||||
QVector<Client *> LanguageClientManager::reachableClients()
|
QVector<Client *> LanguageClientManager::reachableClients()
|
||||||
{
|
{
|
||||||
return Utils::filtered(m_clients, &Client::reachable);
|
return Utils::filtered(m_clients, &Client::reachable);
|
||||||
@@ -247,7 +288,7 @@ void LanguageClientManager::editorOpened(Core::IEditor *editor)
|
|||||||
|
|
||||||
void LanguageClientManager::documentOpened(Core::IDocument *document)
|
void LanguageClientManager::documentOpened(Core::IDocument *document)
|
||||||
{
|
{
|
||||||
for (BaseSettings *setting : LanguageClientSettings::currentSettings()) {
|
for (BaseSettings *setting : LanguageClientSettings::currentPageSettings()) {
|
||||||
if (setting->m_client.isNull() && setting->m_languageFilter.isSupported(document))
|
if (setting->m_client.isNull() && setting->m_languageFilter.isSupported(document))
|
||||||
setting->startClient();
|
setting->startClient();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ public:
|
|||||||
|
|
||||||
static QList<Client *> clientsSupportingDocument(const TextEditor::TextDocument *doc);
|
static QList<Client *> clientsSupportingDocument(const TextEditor::TextDocument *doc);
|
||||||
|
|
||||||
|
static void applySettings();
|
||||||
|
static QList<BaseSettings *> currentSettings();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void shutdownFinished();
|
void shutdownFinished();
|
||||||
|
|
||||||
@@ -94,6 +97,7 @@ private:
|
|||||||
|
|
||||||
bool m_shuttingDown = false;
|
bool m_shuttingDown = false;
|
||||||
QVector<Client *> m_clients;
|
QVector<Client *> m_clients;
|
||||||
|
QList<BaseSettings *> m_currentSettings; // owned
|
||||||
QHash<LanguageServerProtocol::MessageId, QList<Client *>> m_exclusiveRequests;
|
QHash<LanguageServerProtocol::MessageId, QList<Client *>> m_exclusiveRequests;
|
||||||
};
|
};
|
||||||
} // namespace LanguageClient
|
} // namespace LanguageClient
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
LanguageClientSettingsModel m_model;
|
LanguageClientSettingsModel m_model;
|
||||||
QList<BaseSettings *> m_settings; // owned
|
|
||||||
QPointer<LanguageClientSettingsPageWidget> m_widget;
|
QPointer<LanguageClientSettingsPageWidget> m_widget;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -238,7 +237,6 @@ LanguageClientSettingsPage::~LanguageClientSettingsPage()
|
|||||||
{
|
{
|
||||||
if (m_widget)
|
if (m_widget)
|
||||||
delete m_widget;
|
delete m_widget;
|
||||||
qDeleteAll(m_settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanguageClientSettingsPage::init()
|
void LanguageClientSettingsPage::init()
|
||||||
@@ -257,47 +255,31 @@ QWidget *LanguageClientSettingsPage::widget()
|
|||||||
|
|
||||||
void LanguageClientSettingsPage::apply()
|
void LanguageClientSettingsPage::apply()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_settings);
|
|
||||||
if (m_widget)
|
if (m_widget)
|
||||||
m_widget->applyCurrentSettings();
|
m_widget->applyCurrentSettings();
|
||||||
m_settings = Utils::transform(m_model.settings(),
|
LanguageClientManager::applySettings();
|
||||||
[](const BaseSettings *other) { return other->copy(); });
|
|
||||||
LanguageClientSettings::toSettings(Core::ICore::settings(), m_settings);
|
|
||||||
|
|
||||||
QList<BaseSettings *> restarts = Utils::filtered(m_settings, &BaseSettings::needsRestart);
|
for (BaseSettings *setting : m_model.removed()) {
|
||||||
for (auto setting : restarts + m_model.removed()) {
|
if (Client *client = setting->m_client) {
|
||||||
if (auto client = setting->m_client) {
|
|
||||||
if (client->reachable())
|
if (client->reachable())
|
||||||
client->shutdown();
|
client->shutdown();
|
||||||
else
|
else
|
||||||
LanguageClientManager::deleteClient(client);
|
LanguageClientManager::deleteClient(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (BaseSettings *setting : restarts) {
|
|
||||||
if (setting->isValid() && setting->m_enabled) {
|
|
||||||
const bool start = setting->m_alwaysOn
|
|
||||||
|| Utils::anyOf(Core::DocumentModel::openedDocuments(),
|
|
||||||
[filter = setting->m_languageFilter](
|
|
||||||
Core::IDocument *doc) {
|
|
||||||
return filter.isSupported(doc);
|
|
||||||
});
|
|
||||||
if (start)
|
|
||||||
setting->startClient();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_widget) {
|
if (m_widget) {
|
||||||
int row = m_widget->currentRow();
|
int row = m_widget->currentRow();
|
||||||
m_model.reset(m_settings);
|
m_model.reset(LanguageClientManager::currentSettings());
|
||||||
m_widget->resetCurrentSettings(row);
|
m_widget->resetCurrentSettings(row);
|
||||||
} else {
|
} else {
|
||||||
m_model.reset(m_settings);
|
m_model.reset(LanguageClientManager::currentSettings());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanguageClientSettingsPage::finish()
|
void LanguageClientSettingsPage::finish()
|
||||||
{
|
{
|
||||||
m_model.reset(m_settings);
|
m_model.reset(LanguageClientManager::currentSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<BaseSettings *> LanguageClientSettingsPage::settings() const
|
QList<BaseSettings *> LanguageClientSettingsPage::settings() const
|
||||||
@@ -461,7 +443,7 @@ QList<BaseSettings *> LanguageClientSettings::fromSettings(QSettings *settingsIn
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<BaseSettings *> LanguageClientSettings::currentSettings()
|
QList<BaseSettings *> LanguageClientSettings::currentPageSettings()
|
||||||
{
|
{
|
||||||
return settingsPage().settings();
|
return settingsPage().settings();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class LanguageClientSettings
|
|||||||
public:
|
public:
|
||||||
static void init();
|
static void init();
|
||||||
static QList<BaseSettings *> fromSettings(QSettings *settings);
|
static QList<BaseSettings *> fromSettings(QSettings *settings);
|
||||||
static QList<BaseSettings *> currentSettings();
|
static QList<BaseSettings *> currentPageSettings();
|
||||||
static void toSettings(QSettings *settings, const QList<BaseSettings *> &languageClientSettings);
|
static void toSettings(QSettings *settings, const QList<BaseSettings *> &languageClientSettings);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user