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;

View File

@@ -145,7 +145,7 @@ public:
void requestCodeActions(const LanguageServerProtocol::CodeActionRequest &request);
void handleCodeActionResponse(const LanguageServerProtocol::CodeActionRequest::Response &response,
const LanguageServerProtocol::DocumentUri &uri);
void executeCommand(const LanguageServerProtocol::Command &command);
virtual void executeCommand(const LanguageServerProtocol::Command &command);
// language support
void addAssistProcessor(TextEditor::IAssistProcessor *processor);

View File

@@ -561,13 +561,18 @@ Client *BaseSettings::createClient()
return nullptr;
BaseClientInterface *interface = createInterface();
QTC_ASSERT(interface, return nullptr);
auto *client = new Client(interface);
auto *client = createClient(interface);
client->setName(Utils::globalMacroExpander()->expand(m_name));
client->setSupportedLanguage(m_languageFilter);
client->setInitializationOptions(initializationOptions());
return client;
}
Client *BaseSettings::createClient(BaseClientInterface *interface) const
{
return new Client(interface);
}
QVariantMap BaseSettings::toMap() const
{
QVariantMap map;

View File

@@ -101,6 +101,7 @@ public:
protected:
virtual BaseClientInterface *createInterface() const { return nullptr; }
virtual Client *createClient(BaseClientInterface *interface) const;
BaseSettings(const BaseSettings &other) = default;
BaseSettings(BaseSettings &&other) = default;

View File

@@ -25,8 +25,10 @@
#pragma once
#include <languageserverprotocol/workspace.h>
#include "languageclient_global.h"
#include <languageserverprotocol/languagefeatures.h>
#include <languageserverprotocol/workspace.h>
#include <texteditor/refactoroverlay.h>
#include <utils/changeset.h>
@@ -44,13 +46,15 @@ class Client;
Utils::ChangeSet editsToChangeSet(const QList<LanguageServerProtocol::TextEdit> &edits,
const QTextDocument *doc);
bool applyWorkspaceEdit(const LanguageServerProtocol::WorkspaceEdit &edit);
bool applyTextDocumentEdit(const LanguageServerProtocol::TextDocumentEdit &edit);
bool applyTextEdits(const LanguageServerProtocol::DocumentUri &uri,
bool LANGUAGECLIENT_EXPORT applyWorkspaceEdit(const LanguageServerProtocol::WorkspaceEdit &edit);
bool LANGUAGECLIENT_EXPORT
applyTextDocumentEdit(const LanguageServerProtocol::TextDocumentEdit &edit);
bool LANGUAGECLIENT_EXPORT applyTextEdits(const LanguageServerProtocol::DocumentUri &uri,
const QList<LanguageServerProtocol::TextEdit> &edits);
void applyTextEdit(TextEditor::TextDocumentManipulatorInterface &manipulator,
void LANGUAGECLIENT_EXPORT applyTextEdit(TextEditor::TextDocumentManipulatorInterface &manipulator,
const LanguageServerProtocol::TextEdit &edit);
void updateCodeActionRefactoringMarker(Client *client,
void LANGUAGECLIENT_EXPORT
updateCodeActionRefactoringMarker(Client *client,
const LanguageServerProtocol::CodeAction &action,
const LanguageServerProtocol::DocumentUri &uri);
void updateEditorToolBar(Core::IEditor *editor);