LSP: let the settings generate the client

In preperation for settings other than the stdio client.

Change-Id: I11635119db9165163947d822e911ee26ce8548f1
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2018-09-17 13:55:26 +02:00
parent fb058b850b
commit 1b2ad0e989
4 changed files with 14 additions and 13 deletions

View File

@@ -165,17 +165,6 @@ void LanguageClientManager::removeMarks(const Core::Id &id)
removeMarks(fileName, id); removeMarks(fileName, id);
} }
void LanguageClientManager::startClient(LanguageClientSettings setting)
{
if (managerInstance->m_shuttingDown)
return;
auto client = new StdIOClient(setting.m_executable, setting.m_arguments);
client->setName(setting.m_name);
if (setting.m_mimeType != noLanguageFilter)
client->setSupportedMimeType({setting.m_mimeType});
startClient(client);
}
void LanguageClientManager::startClient(BaseClient *client) void LanguageClientManager::startClient(BaseClient *client)
{ {
if (managerInstance->m_shuttingDown) { if (managerInstance->m_shuttingDown) {

View File

@@ -61,7 +61,6 @@ public:
static void removeMarks(const Utils::FileName &fileName, const Core::Id &id); static void removeMarks(const Utils::FileName &fileName, const Core::Id &id);
static void removeMarks(const Core::Id &id); static void removeMarks(const Core::Id &id);
static void startClient(LanguageClientSettings setting);
static void startClient(BaseClient *client); static void startClient(BaseClient *client);
static QVector<BaseClient *> clients(); static QVector<BaseClient *> clients();

View File

@@ -371,7 +371,7 @@ void LanguageClientSettingsModel::applyChanges()
} }
for (auto setting : toStart) { for (auto setting : toStart) {
if (setting.isValid() && setting.m_enabled) if (setting.isValid() && setting.m_enabled)
LanguageClientManager::startClient(setting); LanguageClientManager::startClient(setting.createClient());
} }
} }
@@ -389,6 +389,15 @@ bool LanguageClientSettings::operator==(const LanguageClientSettings &other) con
&& m_arguments == other.m_arguments; && m_arguments == other.m_arguments;
} }
BaseClient *LanguageClientSettings::createClient()
{
auto client = new StdIOClient(m_executable, m_arguments);
client->setName(m_name);
if (m_mimeType != noLanguageFilter)
client->setSupportedMimeType({m_mimeType});
return client;
}
QVariantMap LanguageClientSettings::toMap() const QVariantMap LanguageClientSettings::toMap() const
{ {
QVariantMap map; QVariantMap map;

View File

@@ -35,6 +35,8 @@ namespace LanguageClient {
constexpr char noLanguageFilter[] = "No Filter"; constexpr char noLanguageFilter[] = "No Filter";
class BaseClient;
class LanguageClientSettings class LanguageClientSettings
{ {
public: public:
@@ -57,6 +59,8 @@ public:
bool operator==(const LanguageClientSettings &other) const; bool operator==(const LanguageClientSettings &other) const;
BaseClient *createClient();
QVariantMap toMap() const; QVariantMap toMap() const;
static LanguageClientSettings fromMap(const QVariantMap &map); static LanguageClientSettings fromMap(const QVariantMap &map);
static void init(); static void init();