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

@@ -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