JLS: add special java client that can execute jls commands

the java language server uses special "java.apply.workspaceEdit"
commands that already contain the workspace edit that should be applied
when triggering the command.

Change-Id: If7c53b9b097aaeca289e3958a39be37a9725d395
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2021-02-12 14:05:10 +01:00
parent 49ae9b5b30
commit 94ee80b222
9 changed files with 57 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
add_qtc_plugin(Android
DEPENDS QtcSsh QmlDebug Qt5::Xml
DEPENDS QtcSsh QmlDebug Qt5::Xml LanguageServerProtocol
PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport LanguageClient
SOURCES
adbcommandswidget.cpp adbcommandswidget.h adbcommandswidget.ui

View File

@@ -8,6 +8,7 @@ Project {
Depends { name: "Core" }
Depends { name: "Debugger" }
Depends { name: "LanguageClient" }
Depends { name: "LanguageServerProtocol" }
Depends { name: "ProParser" }
Depends { name: "ProjectExplorer" }
Depends { name: "QmlDebug" }

View File

@@ -9,6 +9,7 @@ QTC_PLUGIN_DEPENDS += \
QTC_LIB_DEPENDS += \
extensionsystem \
languageserverprotocol \
qmldebug \
ssh \
utils

View File

@@ -27,6 +27,8 @@
#include "androidconstants.h"
#include <languageclient/client.h>
#include <languageclient/languageclientutils.h>
#include <utils/environment.h>
#include <utils/pathchooser.h>
#include <utils/variablechooser.h>
@@ -180,5 +182,34 @@ LanguageClient::BaseSettings *JLSSettings::copy() const
return new JLSSettings(*this);
}
class JLSClient : public LanguageClient::Client
{
public:
using Client::Client;
void executeCommand(const LanguageServerProtocol::Command &command) override;
};
void JLSClient::executeCommand(const LanguageServerProtocol::Command &command)
{
if (command.command() == "java.apply.workspaceEdit") {
const QJsonArray arguments = command.arguments().value_or(QJsonArray());
for (const QJsonValue &argument : arguments) {
if (!argument.isObject())
continue;
LanguageServerProtocol::WorkspaceEdit edit(argument.toObject());
if (edit.isValid(nullptr))
LanguageClient::applyWorkspaceEdit(edit);
}
} else {
Client::executeCommand(command);
}
}
LanguageClient::Client *JLSSettings::createClient(LanguageClient::BaseClientInterface *interface) const
{
return new JLSClient(interface);
}
} // namespace Internal
} // namespace Android

View File

@@ -41,6 +41,7 @@ public:
QVariantMap toMap() const final;
void fromMap(const QVariantMap &map) final;
LanguageClient::BaseSettings *copy() const final;
LanguageClient::Client *createClient(LanguageClient::BaseClientInterface *interface) const final;
QString m_languageServer;
QString m_workspace;