forked from qt-creator/qt-creator
languageclient: Write errors to log file
Helps the user to better understand why his language server might have a problem. Change-Id: I9440a28cb5d0d35808b497bcdcd545d7b10597a0 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#include "languageclientinterface.h"
|
#include "languageclientinterface.h"
|
||||||
|
|
||||||
#include "languageclientsettings.h"
|
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
|
|
||||||
using namespace LanguageServerProtocol;
|
using namespace LanguageServerProtocol;
|
||||||
@@ -77,6 +75,13 @@ void BaseClientInterface::parseCurrentMessage()
|
|||||||
m_currentMessage = BaseMessage();
|
m_currentMessage = BaseMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StdIOClientInterface::StdIOClientInterface()
|
||||||
|
: m_logFile("lspclient.XXXXXX.log")
|
||||||
|
{
|
||||||
|
m_logFile.setAutoRemove(false);
|
||||||
|
m_logFile.open();
|
||||||
|
}
|
||||||
|
|
||||||
StdIOClientInterface::~StdIOClientInterface()
|
StdIOClientInterface::~StdIOClientInterface()
|
||||||
{
|
{
|
||||||
delete m_process;
|
delete m_process;
|
||||||
@@ -96,10 +101,14 @@ void StdIOClientInterface::startImpl()
|
|||||||
this, &StdIOClientInterface::readOutput);
|
this, &StdIOClientInterface::readOutput);
|
||||||
connect(m_process, &QtcProcess::started, this, &StdIOClientInterface::started);
|
connect(m_process, &QtcProcess::started, this, &StdIOClientInterface::started);
|
||||||
connect(m_process, &QtcProcess::done, this, [this] {
|
connect(m_process, &QtcProcess::done, this, [this] {
|
||||||
|
m_logFile.flush();
|
||||||
if (m_process->result() != ProcessResult::FinishedWithSuccess)
|
if (m_process->result() != ProcessResult::FinishedWithSuccess)
|
||||||
emit error(m_process->exitMessage());
|
emit error(QString("%1 (see logs in \"%2\")")
|
||||||
|
.arg(m_process->exitMessage())
|
||||||
|
.arg(m_logFile.fileName()));
|
||||||
emit finished();
|
emit finished();
|
||||||
});
|
});
|
||||||
|
m_logFile.write(QString("Starting server: %1\nOutput:\n\n").arg(m_cmd.toUserOutput()).toUtf8());
|
||||||
m_process->setCommand(m_cmd);
|
m_process->setCommand(m_cmd);
|
||||||
m_process->setWorkingDirectory(m_workingDirectory);
|
m_process->setWorkingDirectory(m_workingDirectory);
|
||||||
if (m_env.isValid())
|
if (m_env.isValid())
|
||||||
@@ -137,8 +146,12 @@ void StdIOClientInterface::sendData(const QByteArray &data)
|
|||||||
void StdIOClientInterface::readError()
|
void StdIOClientInterface::readError()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_process, return);
|
QTC_ASSERT(m_process, return);
|
||||||
|
|
||||||
|
const QByteArray stdErr = m_process->readAllStandardError();
|
||||||
|
m_logFile.write(stdErr);
|
||||||
|
|
||||||
qCDebug(LOGLSPCLIENTV) << "StdIOClient std err:\n";
|
qCDebug(LOGLSPCLIENTV) << "StdIOClient std err:\n";
|
||||||
qCDebug(LOGLSPCLIENTV).noquote() << m_process->readAllStandardError();
|
qCDebug(LOGLSPCLIENTV).noquote() << stdErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StdIOClientInterface::readOutput()
|
void StdIOClientInterface::readOutput()
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
|
#include <utils/temporaryfile.h>
|
||||||
|
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ class LANGUAGECLIENT_EXPORT StdIOClientInterface : public BaseClientInterface
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
StdIOClientInterface() = default;
|
StdIOClientInterface();
|
||||||
~StdIOClientInterface() override;
|
~StdIOClientInterface() override;
|
||||||
|
|
||||||
StdIOClientInterface(const StdIOClientInterface &) = delete;
|
StdIOClientInterface(const StdIOClientInterface &) = delete;
|
||||||
@@ -75,6 +76,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void readError();
|
void readError();
|
||||||
void readOutput();
|
void readOutput();
|
||||||
|
|
||||||
|
Utils::TemporaryFile m_logFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LanguageClient
|
} // namespace LanguageClient
|
||||||
|
Reference in New Issue
Block a user