forked from qt-creator/qt-creator
Java: use a temporary directory for the workspace
Change-Id: Ie8fc01f680393f141f099f57b98eb16a10b37d7e Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -28,9 +28,11 @@
|
|||||||
#include "androidconstants.h"
|
#include "androidconstants.h"
|
||||||
|
|
||||||
#include <languageclient/client.h>
|
#include <languageclient/client.h>
|
||||||
|
#include <languageclient/languageclientinterface.h>
|
||||||
#include <languageclient/languageclientutils.h>
|
#include <languageclient/languageclientutils.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
|
#include <utils/temporarydirectory.h>
|
||||||
#include <utils/variablechooser.h>
|
#include <utils/variablechooser.h>
|
||||||
|
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
@@ -67,7 +69,6 @@ JLSSettingsWidget::JLSSettingsWidget(const JLSSettings *settings, QWidget *paren
|
|||||||
, m_name(new QLineEdit(settings->m_name, this))
|
, m_name(new QLineEdit(settings->m_name, this))
|
||||||
, m_java(new PathChooser(this))
|
, m_java(new PathChooser(this))
|
||||||
, m_ls(new PathChooser(this))
|
, m_ls(new PathChooser(this))
|
||||||
, m_workspace(new PathChooser(this))
|
|
||||||
{
|
{
|
||||||
int row = 0;
|
int row = 0;
|
||||||
auto *mainLayout = new QGridLayout;
|
auto *mainLayout = new QGridLayout;
|
||||||
@@ -88,11 +89,6 @@ JLSSettingsWidget::JLSSettingsWidget(const JLSSettings *settings, QWidget *paren
|
|||||||
m_ls->setPath(QDir::toNativeSeparators(settings->m_languageServer));
|
m_ls->setPath(QDir::toNativeSeparators(settings->m_languageServer));
|
||||||
mainLayout->addWidget(m_ls, row, 1);
|
mainLayout->addWidget(m_ls, row, 1);
|
||||||
|
|
||||||
mainLayout->addWidget(new QLabel(tr("Workspace:")), ++row, 0);
|
|
||||||
m_workspace->setExpectedKind(Utils::PathChooser::Directory);
|
|
||||||
m_workspace->setPath(QDir::toNativeSeparators(settings->m_workspace));
|
|
||||||
mainLayout->addWidget(m_workspace, row, 1);
|
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,9 +113,6 @@ bool JLSSettings::applyFromSettingsWidget(QWidget *widget)
|
|||||||
changed |= m_languageServer != jlswidget->languageServer();
|
changed |= m_languageServer != jlswidget->languageServer();
|
||||||
m_languageServer = jlswidget->languageServer();
|
m_languageServer = jlswidget->languageServer();
|
||||||
|
|
||||||
changed |= m_workspace != jlswidget->workspace();
|
|
||||||
m_workspace = jlswidget->workspace();
|
|
||||||
|
|
||||||
changed |= m_executable != jlswidget->java();
|
changed |= m_executable != jlswidget->java();
|
||||||
m_executable = jlswidget->java();
|
m_executable = jlswidget->java();
|
||||||
|
|
||||||
@@ -130,8 +123,7 @@ bool JLSSettings::applyFromSettingsWidget(QWidget *widget)
|
|||||||
"-noverify "
|
"-noverify "
|
||||||
"-Xmx1G "
|
"-Xmx1G "
|
||||||
"-jar \"%1\" "
|
"-jar \"%1\" "
|
||||||
"-configuration \"%2\" "
|
"-configuration \"%2\"";
|
||||||
"-data \"%3\"";
|
|
||||||
|
|
||||||
QFileInfo languageServerFileInfo(m_languageServer);
|
QFileInfo languageServerFileInfo(m_languageServer);
|
||||||
QDir configDir = languageServerFileInfo.absoluteDir();
|
QDir configDir = languageServerFileInfo.absoluteDir();
|
||||||
@@ -145,7 +137,7 @@ bool JLSSettings::applyFromSettingsWidget(QWidget *widget)
|
|||||||
configDir.cd("config_mac");
|
configDir.cd("config_mac");
|
||||||
}
|
}
|
||||||
if (configDir.exists()) {
|
if (configDir.exists()) {
|
||||||
arguments = arguments.arg(m_languageServer, configDir.absolutePath(), m_workspace);
|
arguments = arguments.arg(m_languageServer, configDir.absolutePath());
|
||||||
changed |= m_arguments != arguments;
|
changed |= m_arguments != arguments;
|
||||||
m_arguments = arguments;
|
m_arguments = arguments;
|
||||||
}
|
}
|
||||||
@@ -159,14 +151,13 @@ QWidget *JLSSettings::createSettingsWidget(QWidget *parent) const
|
|||||||
|
|
||||||
bool JLSSettings::isValid() const
|
bool JLSSettings::isValid() const
|
||||||
{
|
{
|
||||||
return StdIOSettings::isValid() && !m_languageServer.isEmpty() && !m_workspace.isEmpty();
|
return StdIOSettings::isValid() && !m_languageServer.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap JLSSettings::toMap() const
|
QVariantMap JLSSettings::toMap() const
|
||||||
{
|
{
|
||||||
QVariantMap map = StdIOSettings::toMap();
|
QVariantMap map = StdIOSettings::toMap();
|
||||||
map.insert(languageServerKey, m_languageServer);
|
map.insert(languageServerKey, m_languageServer);
|
||||||
map.insert(workspaceKey, m_workspace);
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +165,6 @@ void JLSSettings::fromMap(const QVariantMap &map)
|
|||||||
{
|
{
|
||||||
StdIOSettings::fromMap(map);
|
StdIOSettings::fromMap(map);
|
||||||
m_languageServer = map[languageServerKey].toString();
|
m_languageServer = map[languageServerKey].toString();
|
||||||
m_workspace = map[workspaceKey].toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LanguageClient::BaseSettings *JLSSettings::copy() const
|
LanguageClient::BaseSettings *JLSSettings::copy() const
|
||||||
@@ -182,6 +172,27 @@ LanguageClient::BaseSettings *JLSSettings::copy() const
|
|||||||
return new JLSSettings(*this);
|
return new JLSSettings(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class JLSInterface : public LanguageClient::StdIOClientInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
JLSInterface() = default;
|
||||||
|
|
||||||
|
QString workspaceDir() const { return m_workspaceDir.path(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
TemporaryDirectory m_workspaceDir = TemporaryDirectory("QtCreator-jls-XXXXXX");
|
||||||
|
};
|
||||||
|
|
||||||
|
LanguageClient::BaseClientInterface *JLSSettings::createInterface() const
|
||||||
|
{
|
||||||
|
auto interface = new JLSInterface();
|
||||||
|
interface->setExecutable(m_executable);
|
||||||
|
QString arguments = this->arguments();
|
||||||
|
arguments += QString(" -data \"%1\"").arg(interface->workspaceDir());
|
||||||
|
interface->setArguments(arguments);
|
||||||
|
return interface;
|
||||||
|
}
|
||||||
|
|
||||||
class JLSClient : public LanguageClient::Client
|
class JLSClient : public LanguageClient::Client
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -42,9 +42,9 @@ public:
|
|||||||
void fromMap(const QVariantMap &map) final;
|
void fromMap(const QVariantMap &map) final;
|
||||||
LanguageClient::BaseSettings *copy() const final;
|
LanguageClient::BaseSettings *copy() const final;
|
||||||
LanguageClient::Client *createClient(LanguageClient::BaseClientInterface *interface) const final;
|
LanguageClient::Client *createClient(LanguageClient::BaseClientInterface *interface) const final;
|
||||||
|
LanguageClient::BaseClientInterface *createInterface() const override;
|
||||||
|
|
||||||
QString m_languageServer;
|
QString m_languageServer;
|
||||||
QString m_workspace;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JLSSettings(const JLSSettings &other) = default;
|
JLSSettings(const JLSSettings &other) = default;
|
||||||
|
@@ -89,9 +89,7 @@ void BaseClientInterface::parseData(const QByteArray &data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StdIOClientInterface::StdIOClientInterface(const QString &executable, const QString &arguments)
|
StdIOClientInterface::StdIOClientInterface()
|
||||||
: m_executable(executable)
|
|
||||||
, m_arguments(arguments)
|
|
||||||
{
|
{
|
||||||
connect(&m_process, &QProcess::readyReadStandardError,
|
connect(&m_process, &QProcess::readyReadStandardError,
|
||||||
this, &StdIOClientInterface::readError);
|
this, &StdIOClientInterface::readError);
|
||||||
@@ -99,9 +97,6 @@ StdIOClientInterface::StdIOClientInterface(const QString &executable, const QStr
|
|||||||
this, &StdIOClientInterface::readOutput);
|
this, &StdIOClientInterface::readOutput);
|
||||||
connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||||
this, &StdIOClientInterface::onProcessFinished);
|
this, &StdIOClientInterface::onProcessFinished);
|
||||||
|
|
||||||
m_process.setArguments(Utils::QtcProcess::splitArgs(m_arguments));
|
|
||||||
m_process.setProgram(m_executable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StdIOClientInterface::~StdIOClientInterface()
|
StdIOClientInterface::~StdIOClientInterface()
|
||||||
@@ -109,11 +104,6 @@ StdIOClientInterface::~StdIOClientInterface()
|
|||||||
Utils::SynchronousProcess::stopProcess(m_process);
|
Utils::SynchronousProcess::stopProcess(m_process);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StdIOClientInterface::needsRestart(const StdIOSettings *settings) const
|
|
||||||
{
|
|
||||||
return m_executable != settings->m_executable || m_arguments != settings->arguments();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StdIOClientInterface::start()
|
bool StdIOClientInterface::start()
|
||||||
{
|
{
|
||||||
m_process.start();
|
m_process.start();
|
||||||
@@ -124,6 +114,16 @@ bool StdIOClientInterface::start()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StdIOClientInterface::setExecutable(const QString &executable)
|
||||||
|
{
|
||||||
|
m_process.setProgram(executable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StdIOClientInterface::setArguments(const QString &arguments)
|
||||||
|
{
|
||||||
|
m_process.setArguments(Utils::QtcProcess::splitArgs(arguments));
|
||||||
|
}
|
||||||
|
|
||||||
void StdIOClientInterface::setWorkingDirectory(const QString &workingDirectory)
|
void StdIOClientInterface::setWorkingDirectory(const QString &workingDirectory)
|
||||||
{
|
{
|
||||||
m_process.setWorkingDirectory(workingDirectory);
|
m_process.setWorkingDirectory(workingDirectory);
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "languageclient_global.h"
|
||||||
|
|
||||||
#include <languageserverprotocol/basemessage.h>
|
#include <languageserverprotocol/basemessage.h>
|
||||||
|
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
@@ -34,13 +36,13 @@ namespace LanguageClient {
|
|||||||
|
|
||||||
class StdIOSettings;
|
class StdIOSettings;
|
||||||
|
|
||||||
class BaseClientInterface : public QObject
|
class LANGUAGECLIENT_EXPORT BaseClientInterface : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
BaseClientInterface();
|
BaseClientInterface();
|
||||||
|
|
||||||
virtual ~BaseClientInterface();
|
~BaseClientInterface() override;
|
||||||
|
|
||||||
void sendMessage(const LanguageServerProtocol::BaseMessage &message);
|
void sendMessage(const LanguageServerProtocol::BaseMessage &message);
|
||||||
virtual bool start() { return true; }
|
virtual bool start() { return true; }
|
||||||
@@ -61,23 +63,23 @@ private:
|
|||||||
LanguageServerProtocol::BaseMessage m_currentMessage;
|
LanguageServerProtocol::BaseMessage m_currentMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StdIOClientInterface : public BaseClientInterface
|
class LANGUAGECLIENT_EXPORT StdIOClientInterface : public BaseClientInterface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
StdIOClientInterface(const QString &executable, const QString &arguments);
|
StdIOClientInterface();
|
||||||
~StdIOClientInterface() override;
|
~StdIOClientInterface() override;
|
||||||
|
|
||||||
StdIOClientInterface() = delete;
|
|
||||||
StdIOClientInterface(const StdIOClientInterface &) = delete;
|
StdIOClientInterface(const StdIOClientInterface &) = delete;
|
||||||
StdIOClientInterface(StdIOClientInterface &&) = delete;
|
StdIOClientInterface(StdIOClientInterface &&) = delete;
|
||||||
StdIOClientInterface &operator=(const StdIOClientInterface &) = delete;
|
StdIOClientInterface &operator=(const StdIOClientInterface &) = delete;
|
||||||
StdIOClientInterface &operator=(StdIOClientInterface &&) = delete;
|
StdIOClientInterface &operator=(StdIOClientInterface &&) = delete;
|
||||||
|
|
||||||
bool needsRestart(const StdIOSettings *settings) const;
|
|
||||||
|
|
||||||
bool start() override;
|
bool start() override;
|
||||||
|
|
||||||
|
// These functions only have an effect if they are called before start
|
||||||
|
void setExecutable(const QString &executable);
|
||||||
|
void setArguments(const QString &arguments);
|
||||||
void setWorkingDirectory(const QString &workingDirectory);
|
void setWorkingDirectory(const QString &workingDirectory);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -88,9 +90,6 @@ private:
|
|||||||
void readError();
|
void readError();
|
||||||
void readOutput();
|
void readOutput();
|
||||||
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
|
|
||||||
const QString m_executable;
|
|
||||||
const QString m_arguments;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LanguageClient
|
} // namespace LanguageClient
|
||||||
|
@@ -722,7 +722,10 @@ Utils::CommandLine StdIOSettings::command() const
|
|||||||
|
|
||||||
BaseClientInterface *StdIOSettings::createInterface() const
|
BaseClientInterface *StdIOSettings::createInterface() const
|
||||||
{
|
{
|
||||||
return new StdIOClientInterface(m_executable, arguments());
|
auto interface = new StdIOClientInterface;
|
||||||
|
interface->setExecutable(m_executable);
|
||||||
|
interface->setArguments(arguments());
|
||||||
|
return interface;
|
||||||
}
|
}
|
||||||
|
|
||||||
class JsonTreeItemDelegate : public QStyledItemDelegate
|
class JsonTreeItemDelegate : public QStyledItemDelegate
|
||||||
|
Reference in New Issue
Block a user