forked from qt-creator/qt-creator
Nim: FilePathify NimSuggest
Change-Id: I9beeaa9f5441e040c039e8ceeeecf9c4b2053d22 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -41,10 +41,10 @@ class NimPluginPrivate
|
|||||||
public:
|
public:
|
||||||
NimPluginPrivate()
|
NimPluginPrivate()
|
||||||
{
|
{
|
||||||
Suggest::NimSuggestCache::instance().setExecutablePath(settings.nimSuggestPath.stringValue());
|
Suggest::NimSuggestCache::instance().setExecutablePath(settings.nimSuggestPath());
|
||||||
QObject::connect(&settings.nimSuggestPath, &StringAspect::changed,
|
QObject::connect(&settings.nimSuggestPath, &StringAspect::changed,
|
||||||
&Suggest::NimSuggestCache::instance(), [this] {
|
&Suggest::NimSuggestCache::instance(), [this] {
|
||||||
Suggest::NimSuggestCache::instance().setExecutablePath(settings.nimSuggestPath.stringValue());
|
Suggest::NimSuggestCache::instance().setExecutablePath(settings.nimSuggestPath());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,8 +3,9 @@
|
|||||||
|
|
||||||
#include "nimsuggest.h"
|
#include "nimsuggest.h"
|
||||||
|
|
||||||
namespace Nim {
|
using namespace Utils;
|
||||||
namespace Suggest {
|
|
||||||
|
namespace Nim::Suggest {
|
||||||
|
|
||||||
NimSuggest::NimSuggest(QObject *parent)
|
NimSuggest::NimSuggest(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
@@ -16,12 +17,12 @@ NimSuggest::NimSuggest(QObject *parent)
|
|||||||
connect(&m_client, &NimSuggestClient::connected, this, &NimSuggest::onClientConnected);
|
connect(&m_client, &NimSuggestClient::connected, this, &NimSuggest::onClientConnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString NimSuggest::projectFile() const
|
FilePath NimSuggest::projectFile() const
|
||||||
{
|
{
|
||||||
return m_projectFile;
|
return m_projectFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimSuggest::setProjectFile(const QString &file)
|
void NimSuggest::setProjectFile(const Utils::FilePath &file)
|
||||||
{
|
{
|
||||||
if (m_projectFile == file)
|
if (m_projectFile == file)
|
||||||
return;
|
return;
|
||||||
@@ -32,12 +33,12 @@ void NimSuggest::setProjectFile(const QString &file)
|
|||||||
restart();
|
restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString NimSuggest::executablePath() const
|
FilePath NimSuggest::executablePath() const
|
||||||
{
|
{
|
||||||
return m_executablePath;
|
return m_executablePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimSuggest::setExecutablePath(const QString &path)
|
void NimSuggest::setExecutablePath(const FilePath &path)
|
||||||
{
|
{
|
||||||
if (m_executablePath == path)
|
if (m_executablePath == path)
|
||||||
return;
|
return;
|
||||||
@@ -145,5 +146,4 @@ void NimSuggest::onClientDisconnected()
|
|||||||
connectClient();
|
connectClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Suggest
|
} // Nim::Suggest
|
||||||
} // namespace Nim
|
|
||||||
|
@@ -6,8 +6,10 @@
|
|||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
namespace Nim {
|
#include <utils/filepath.h>
|
||||||
namespace Suggest {
|
|
||||||
|
|
||||||
|
namespace Nim::Suggest {
|
||||||
|
|
||||||
class NimSuggest : public QObject
|
class NimSuggest : public QObject
|
||||||
{
|
{
|
||||||
@@ -16,11 +18,11 @@ class NimSuggest : public QObject
|
|||||||
public:
|
public:
|
||||||
NimSuggest(QObject *parent = nullptr);
|
NimSuggest(QObject *parent = nullptr);
|
||||||
|
|
||||||
QString projectFile() const;
|
Utils::FilePath projectFile() const;
|
||||||
void setProjectFile(const QString &file);
|
void setProjectFile(const Utils::FilePath &file);
|
||||||
|
|
||||||
QString executablePath() const;
|
Utils::FilePath executablePath() const;
|
||||||
void setExecutablePath(const QString &path);
|
void setExecutablePath(const Utils::FilePath &path);
|
||||||
|
|
||||||
bool isReady() const;
|
bool isReady() const;
|
||||||
|
|
||||||
@@ -32,8 +34,8 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void readyChanged(bool ready);
|
void readyChanged(bool ready);
|
||||||
void projectFileChanged(const QString &projectFile);
|
void projectFileChanged(const Utils::FilePath &projectFile);
|
||||||
void executablePathChanged(const QString &executablePath);
|
void executablePathChanged(const Utils::FilePath &executablePath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void restart();
|
void restart();
|
||||||
@@ -61,11 +63,10 @@ private:
|
|||||||
bool m_ready = false;
|
bool m_ready = false;
|
||||||
bool m_clientReady = false;
|
bool m_clientReady = false;
|
||||||
bool m_serverReady = false;
|
bool m_serverReady = false;
|
||||||
QString m_projectFile;
|
Utils::FilePath m_projectFile;
|
||||||
QString m_executablePath;
|
Utils::FilePath m_executablePath;
|
||||||
NimSuggestServer m_server;
|
NimSuggestServer m_server;
|
||||||
NimSuggestClient m_client;
|
NimSuggestClient m_client;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Suggest
|
} // Nim::Suggest
|
||||||
} // namespace Nim
|
|
||||||
|
@@ -5,12 +5,14 @@
|
|||||||
|
|
||||||
#include "nimconstants.h"
|
#include "nimconstants.h"
|
||||||
#include "nimsuggest.h"
|
#include "nimsuggest.h"
|
||||||
|
#include "settings/nimsettings.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
|
|
||||||
namespace Nim {
|
using namespace Utils;
|
||||||
namespace Suggest {
|
|
||||||
|
namespace Nim::Suggest {
|
||||||
|
|
||||||
NimSuggestCache &NimSuggestCache::instance()
|
NimSuggestCache &NimSuggestCache::instance()
|
||||||
{
|
{
|
||||||
@@ -20,12 +22,12 @@ NimSuggestCache &NimSuggestCache::instance()
|
|||||||
|
|
||||||
NimSuggestCache::~NimSuggestCache() = default;
|
NimSuggestCache::~NimSuggestCache() = default;
|
||||||
|
|
||||||
NimSuggest *NimSuggestCache::get(const Utils::FilePath &filename)
|
NimSuggest *NimSuggestCache::get(const FilePath &filename)
|
||||||
{
|
{
|
||||||
auto it = m_nimSuggestInstances.find(filename);
|
auto it = m_nimSuggestInstances.find(filename);
|
||||||
if (it == m_nimSuggestInstances.end()) {
|
if (it == m_nimSuggestInstances.end()) {
|
||||||
auto instance = std::make_unique<Suggest::NimSuggest>(this);
|
auto instance = std::make_unique<Suggest::NimSuggest>(this);
|
||||||
instance->setProjectFile(filename.toString());
|
instance->setProjectFile(filename);
|
||||||
instance->setExecutablePath(m_executablePath);
|
instance->setExecutablePath(m_executablePath);
|
||||||
it = m_nimSuggestInstances.emplace(filename, std::move(instance)).first;
|
it = m_nimSuggestInstances.emplace(filename, std::move(instance)).first;
|
||||||
}
|
}
|
||||||
@@ -41,12 +43,12 @@ NimSuggestCache::NimSuggestCache()
|
|||||||
this, &NimSuggestCache::onEditorClosed);
|
this, &NimSuggestCache::onEditorClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString NimSuggestCache::executablePath() const
|
FilePath NimSuggestCache::executablePath() const
|
||||||
{
|
{
|
||||||
return m_executablePath;
|
return m_executablePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimSuggestCache::setExecutablePath(const QString &path)
|
void NimSuggestCache::setExecutablePath(const FilePath &path)
|
||||||
{
|
{
|
||||||
if (m_executablePath == path)
|
if (m_executablePath == path)
|
||||||
return;
|
return;
|
||||||
@@ -72,5 +74,4 @@ void Nim::Suggest::NimSuggestCache::onEditorClosed(Core::IEditor *editor)
|
|||||||
m_nimSuggestInstances.erase(it);
|
m_nimSuggestInstances.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // Nim::Suggest
|
||||||
}
|
|
||||||
|
@@ -11,8 +11,7 @@
|
|||||||
|
|
||||||
namespace Core { class IEditor; }
|
namespace Core { class IEditor; }
|
||||||
|
|
||||||
namespace Nim {
|
namespace Nim::Suggest {
|
||||||
namespace Suggest {
|
|
||||||
|
|
||||||
class NimSuggest;
|
class NimSuggest;
|
||||||
|
|
||||||
@@ -25,8 +24,8 @@ public:
|
|||||||
|
|
||||||
NimSuggest *get(const Utils::FilePath &filename);
|
NimSuggest *get(const Utils::FilePath &filename);
|
||||||
|
|
||||||
QString executablePath() const;
|
Utils::FilePath executablePath() const;
|
||||||
void setExecutablePath(const QString &path);
|
void setExecutablePath(const Utils::FilePath &path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NimSuggestCache();
|
NimSuggestCache();
|
||||||
@@ -37,8 +36,7 @@ private:
|
|||||||
|
|
||||||
std::unordered_map<Utils::FilePath, std::unique_ptr<Suggest::NimSuggest>> m_nimSuggestInstances;
|
std::unordered_map<Utils::FilePath, std::unique_ptr<Suggest::NimSuggest>> m_nimSuggestInstances;
|
||||||
|
|
||||||
QString m_executablePath;
|
Utils::FilePath m_executablePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Suggest
|
} // Nim::Suggest
|
||||||
} // namespace Nim
|
|
||||||
|
@@ -5,8 +5,7 @@
|
|||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Nim {
|
namespace Nim::Suggest {
|
||||||
namespace Suggest {
|
|
||||||
|
|
||||||
NimSuggestServer::NimSuggestServer(QObject *parent) : QObject(parent)
|
NimSuggestServer::NimSuggestServer(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
@@ -15,20 +14,14 @@ NimSuggestServer::NimSuggestServer(QObject *parent) : QObject(parent)
|
|||||||
&NimSuggestServer::onStandardOutputAvailable);
|
&NimSuggestServer::onStandardOutputAvailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString NimSuggestServer::executablePath() const
|
bool NimSuggestServer::start(const FilePath &executablePath, const FilePath &projectFilePath)
|
||||||
{
|
{
|
||||||
return m_executablePath;
|
if (!executablePath.exists()) {
|
||||||
}
|
|
||||||
|
|
||||||
bool NimSuggestServer::start(const QString &executablePath,
|
|
||||||
const QString &projectFilePath)
|
|
||||||
{
|
|
||||||
if (!QFile::exists(executablePath)) {
|
|
||||||
qWarning() << "NimSuggest executable path" << executablePath << "does not exist";
|
qWarning() << "NimSuggest executable path" << executablePath << "does not exist";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!QFile::exists(projectFilePath)) {
|
if (!projectFilePath.exists()) {
|
||||||
qWarning() << "Project file" << projectFilePath << "doesn't exist";
|
qWarning() << "Project file" << projectFilePath << "doesn't exist";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -36,7 +29,7 @@ bool NimSuggestServer::start(const QString &executablePath,
|
|||||||
stop();
|
stop();
|
||||||
m_executablePath = executablePath;
|
m_executablePath = executablePath;
|
||||||
m_projectFilePath = projectFilePath;
|
m_projectFilePath = projectFilePath;
|
||||||
m_process.setCommand({FilePath::fromString(executablePath), {"--epc", m_projectFilePath}});
|
m_process.setCommand({executablePath, {"--epc", m_projectFilePath.path()}});
|
||||||
m_process.start();
|
m_process.start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -52,11 +45,6 @@ quint16 NimSuggestServer::port() const
|
|||||||
return m_port;
|
return m_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString NimSuggestServer::projectFilePath() const
|
|
||||||
{
|
|
||||||
return m_projectFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NimSuggestServer::onStandardOutputAvailable()
|
void NimSuggestServer::onStandardOutputAvailable()
|
||||||
{
|
{
|
||||||
if (!m_portAvailable) {
|
if (!m_portAvailable) {
|
||||||
@@ -81,5 +69,4 @@ void NimSuggestServer::clearState()
|
|||||||
m_port = 0;
|
m_port = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Suggest
|
} // namespace Nim::Suggest
|
||||||
} // namespace Nim
|
|
||||||
|
@@ -3,14 +3,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include <utils/process.h>
|
#include <utils/process.h>
|
||||||
|
|
||||||
namespace Nim {
|
namespace Nim::Suggest {
|
||||||
namespace Suggest {
|
|
||||||
|
|
||||||
class NimSuggestServer : public QObject
|
class NimSuggestServer : public QObject
|
||||||
{
|
{
|
||||||
@@ -19,12 +14,10 @@ class NimSuggestServer : public QObject
|
|||||||
public:
|
public:
|
||||||
NimSuggestServer(QObject *parent = nullptr);
|
NimSuggestServer(QObject *parent = nullptr);
|
||||||
|
|
||||||
bool start(const QString &executablePath, const QString &projectFilePath);
|
bool start(const Utils::FilePath &executablePath, const Utils::FilePath &projectFilePath);
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
quint16 port() const;
|
quint16 port() const;
|
||||||
QString executablePath() const;
|
|
||||||
QString projectFilePath() const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void started();
|
void started();
|
||||||
@@ -38,9 +31,8 @@ private:
|
|||||||
bool m_portAvailable = false;
|
bool m_portAvailable = false;
|
||||||
Utils::Process m_process;
|
Utils::Process m_process;
|
||||||
quint16 m_port = 0;
|
quint16 m_port = 0;
|
||||||
QString m_projectFilePath;
|
Utils::FilePath m_projectFilePath;
|
||||||
QString m_executablePath;
|
Utils::FilePath m_executablePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Suggest
|
} // Nim::Suggest
|
||||||
} // namespace Nim
|
|
||||||
|
Reference in New Issue
Block a user