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 add_qtc_plugin(Android
DEPENDS QtcSsh QmlDebug Qt5::Xml DEPENDS QtcSsh QmlDebug Qt5::Xml LanguageServerProtocol
PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport LanguageClient PLUGIN_DEPENDS Core Debugger ProjectExplorer QtSupport LanguageClient
SOURCES SOURCES
adbcommandswidget.cpp adbcommandswidget.h adbcommandswidget.ui adbcommandswidget.cpp adbcommandswidget.h adbcommandswidget.ui

View File

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

View File

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

View File

@@ -27,6 +27,8 @@
#include "androidconstants.h" #include "androidconstants.h"
#include <languageclient/client.h>
#include <languageclient/languageclientutils.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/variablechooser.h> #include <utils/variablechooser.h>
@@ -180,5 +182,34 @@ LanguageClient::BaseSettings *JLSSettings::copy() const
return new JLSSettings(*this); 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 Internal
} // namespace Android } // namespace Android

View File

@@ -41,6 +41,7 @@ public:
QVariantMap toMap() const final; QVariantMap toMap() const final;
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;
QString m_languageServer; QString m_languageServer;
QString m_workspace; QString m_workspace;

View File

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

View File

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

View File

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

View File

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