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