diff --git a/src/plugins/nim/suggest/nimsuggest.cpp b/src/plugins/nim/suggest/nimsuggest.cpp index e51efea0545..fc12c160233 100644 --- a/src/plugins/nim/suggest/nimsuggest.cpp +++ b/src/plugins/nim/suggest/nimsuggest.cpp @@ -32,8 +32,7 @@ NimSuggest::NimSuggest(QObject *parent) : QObject(parent) { connect(&m_server, &NimSuggestServer::started, this, &NimSuggest::onServerStarted); - connect(&m_server, &NimSuggestServer::crashed, this, &NimSuggest::onServerCrashed); - connect(&m_server, &NimSuggestServer::finished, this, &NimSuggest::onServerFinished); + connect(&m_server, &NimSuggestServer::done, this, &NimSuggest::onServerDone); connect(&m_client, &NimSuggestClient::disconnected, this, &NimSuggest::onClientDisconnected); connect(&m_client, &NimSuggestClient::connected, this, &NimSuggest::onClientConnected); @@ -134,14 +133,13 @@ void NimSuggest::disconnectClient() void NimSuggest::stopServer() { - m_server.kill(); + m_server.stop(); } void NimSuggest::startServer() { - if (!m_projectFile.isEmpty() && !m_executablePath.isEmpty()) { + if (!m_projectFile.isEmpty() && !m_executablePath.isEmpty()) m_server.start(m_executablePath, m_projectFile); - } } void NimSuggest::onServerStarted() @@ -150,18 +148,13 @@ void NimSuggest::onServerStarted() connectClient(); } -void NimSuggest::onServerCrashed() +void NimSuggest::onServerDone() { setServerReady(false); disconnectClient(); restart(); } -void NimSuggest::onServerFinished() -{ - onServerCrashed(); -} - void NimSuggest::onClientConnected() { setClientReady(true); diff --git a/src/plugins/nim/suggest/nimsuggest.h b/src/plugins/nim/suggest/nimsuggest.h index 5043455cec3..48190496ab2 100644 --- a/src/plugins/nim/suggest/nimsuggest.h +++ b/src/plugins/nim/suggest/nimsuggest.h @@ -75,8 +75,7 @@ private: void startServer(); void onServerStarted(); - void onServerCrashed(); - void onServerFinished(); + void onServerDone(); void onClientConnected(); void onClientDisconnected(); diff --git a/src/plugins/nim/suggest/server.cpp b/src/plugins/nim/suggest/server.cpp index 48e29d1ceb7..e55151afbe8 100644 --- a/src/plugins/nim/suggest/server.cpp +++ b/src/plugins/nim/suggest/server.cpp @@ -32,17 +32,11 @@ namespace Suggest { NimSuggestServer::NimSuggestServer(QObject *parent) : QObject(parent) { - connect(&m_process, &QtcProcess::finished, this, &NimSuggestServer::onFinished); - connect(&m_process, &QtcProcess::started, this, &NimSuggestServer::onStarted); + connect(&m_process, &QtcProcess::done, this, &NimSuggestServer::onDone); connect(&m_process, &QtcProcess::readyReadStandardOutput, this, &NimSuggestServer::onStandardOutputAvailable); } -NimSuggestServer::~NimSuggestServer() -{ - kill(); -} - QString NimSuggestServer::executablePath() const { return m_executablePath; @@ -61,7 +55,7 @@ bool NimSuggestServer::start(const QString &executablePath, return false; } - m_port = 0; + stop(); m_executablePath = executablePath; m_projectFilePath = projectFilePath; m_process.setCommand({FilePath::fromString(executablePath), {"--epc", m_projectFilePath}}); @@ -69,11 +63,9 @@ bool NimSuggestServer::start(const QString &executablePath, return true; } -void NimSuggestServer::kill() +void NimSuggestServer::stop() { - disconnect(&m_process, &QtcProcess::finished, this, &NimSuggestServer::onFinished); - m_process.kill(); - m_process.waitForFinished(); + m_process.close(); clearState(); } @@ -87,15 +79,10 @@ QString NimSuggestServer::projectFilePath() const return m_projectFilePath; } -void NimSuggestServer::onStarted() -{ - m_started = true; -} - void NimSuggestServer::onStandardOutputAvailable() { - if (m_started && !m_portAvailable) { - auto output = QString::fromUtf8(m_process.readAllStandardOutput()); + if (!m_portAvailable) { + const QString output = QString::fromUtf8(m_process.readAllStandardOutput()); m_port = static_cast(output.toUInt()); m_portAvailable = true; emit started(); @@ -104,19 +91,14 @@ void NimSuggestServer::onStandardOutputAvailable() } } -void NimSuggestServer::onFinished() +void NimSuggestServer::onDone() { clearState(); - - if (m_process.exitStatus() == QProcess::CrashExit) - emit crashed(); - else - emit finished(); + emit done(); } void NimSuggestServer::clearState() { - m_started = false; m_portAvailable = false; m_port = 0; } diff --git a/src/plugins/nim/suggest/server.h b/src/plugins/nim/suggest/server.h index 53f0590288a..4d3a5857ef0 100644 --- a/src/plugins/nim/suggest/server.h +++ b/src/plugins/nim/suggest/server.h @@ -40,10 +40,9 @@ class NimSuggestServer : public QObject public: NimSuggestServer(QObject *parent = nullptr); - ~NimSuggestServer(); bool start(const QString &executablePath, const QString &projectFilePath); - void kill(); + void stop(); quint16 port() const; QString executablePath() const; @@ -51,16 +50,13 @@ public: signals: void started(); - void finished(); - void crashed(); + void done(); private: - void onStarted(); void onStandardOutputAvailable(); - void onFinished(); + void onDone(); void clearState(); - bool m_started = false; bool m_portAvailable = false; Utils::QtcProcess m_process; quint16 m_port = 0;