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 "languageclientsettings.h"
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
using namespace LanguageServerProtocol;
|
||||
@@ -77,6 +75,13 @@ void BaseClientInterface::parseCurrentMessage()
|
||||
m_currentMessage = BaseMessage();
|
||||
}
|
||||
|
||||
StdIOClientInterface::StdIOClientInterface()
|
||||
: m_logFile("lspclient.XXXXXX.log")
|
||||
{
|
||||
m_logFile.setAutoRemove(false);
|
||||
m_logFile.open();
|
||||
}
|
||||
|
||||
StdIOClientInterface::~StdIOClientInterface()
|
||||
{
|
||||
delete m_process;
|
||||
@@ -96,10 +101,14 @@ void StdIOClientInterface::startImpl()
|
||||
this, &StdIOClientInterface::readOutput);
|
||||
connect(m_process, &QtcProcess::started, this, &StdIOClientInterface::started);
|
||||
connect(m_process, &QtcProcess::done, this, [this] {
|
||||
m_logFile.flush();
|
||||
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();
|
||||
});
|
||||
m_logFile.write(QString("Starting server: %1\nOutput:\n\n").arg(m_cmd.toUserOutput()).toUtf8());
|
||||
m_process->setCommand(m_cmd);
|
||||
m_process->setWorkingDirectory(m_workingDirectory);
|
||||
if (m_env.isValid())
|
||||
@@ -137,8 +146,12 @@ void StdIOClientInterface::sendData(const QByteArray &data)
|
||||
void StdIOClientInterface::readError()
|
||||
{
|
||||
QTC_ASSERT(m_process, return);
|
||||
|
||||
const QByteArray stdErr = m_process->readAllStandardError();
|
||||
m_logFile.write(stdErr);
|
||||
|
||||
qCDebug(LOGLSPCLIENTV) << "StdIOClient std err:\n";
|
||||
qCDebug(LOGLSPCLIENTV).noquote() << m_process->readAllStandardError();
|
||||
qCDebug(LOGLSPCLIENTV).noquote() << stdErr;
|
||||
}
|
||||
|
||||
void StdIOClientInterface::readOutput()
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/temporaryfile.h>
|
||||
|
||||
#include <QBuffer>
|
||||
|
||||
@@ -50,7 +51,7 @@ class LANGUAGECLIENT_EXPORT StdIOClientInterface : public BaseClientInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StdIOClientInterface() = default;
|
||||
StdIOClientInterface();
|
||||
~StdIOClientInterface() override;
|
||||
|
||||
StdIOClientInterface(const StdIOClientInterface &) = delete;
|
||||
@@ -75,6 +76,8 @@ protected:
|
||||
private:
|
||||
void readError();
|
||||
void readOutput();
|
||||
|
||||
Utils::TemporaryFile m_logFile;
|
||||
};
|
||||
|
||||
} // namespace LanguageClient
|
||||
|
Reference in New Issue
Block a user