forked from qt-creator/qt-creator
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:
@@ -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
|
||||||
|
@@ -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" }
|
||||||
|
@@ -9,6 +9,7 @@ QTC_PLUGIN_DEPENDS += \
|
|||||||
|
|
||||||
QTC_LIB_DEPENDS += \
|
QTC_LIB_DEPENDS += \
|
||||||
extensionsystem \
|
extensionsystem \
|
||||||
|
languageserverprotocol \
|
||||||
qmldebug \
|
qmldebug \
|
||||||
ssh \
|
ssh \
|
||||||
utils
|
utils
|
||||||
|
@@ -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
|
||||||
|
@@ -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;
|
||||||
|
@@ -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);
|
||||||
|
@@ -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;
|
||||||
|
@@ -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;
|
||||||
|
@@ -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,13 +46,15 @@ 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);
|
||||||
|
bool LANGUAGECLIENT_EXPORT applyTextEdits(const LanguageServerProtocol::DocumentUri &uri,
|
||||||
const QList<LanguageServerProtocol::TextEdit> &edits);
|
const QList<LanguageServerProtocol::TextEdit> &edits);
|
||||||
void applyTextEdit(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
void LANGUAGECLIENT_EXPORT applyTextEdit(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
||||||
const LanguageServerProtocol::TextEdit &edit);
|
const LanguageServerProtocol::TextEdit &edit);
|
||||||
void updateCodeActionRefactoringMarker(Client *client,
|
void LANGUAGECLIENT_EXPORT
|
||||||
|
updateCodeActionRefactoringMarker(Client *client,
|
||||||
const LanguageServerProtocol::CodeAction &action,
|
const LanguageServerProtocol::CodeAction &action,
|
||||||
const LanguageServerProtocol::DocumentUri &uri);
|
const LanguageServerProtocol::DocumentUri &uri);
|
||||||
void updateEditorToolBar(Core::IEditor *editor);
|
void updateEditorToolBar(Core::IEditor *editor);
|
||||||
|
Reference in New Issue
Block a user