2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2018-07-13 12:33:46 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-06-22 14:47:30 +02:00
|
|
|
#include "languageclient_global.h"
|
|
|
|
|
|
2019-01-29 13:20:58 +01:00
|
|
|
#include <texteditor/codeassist/iassistprovider.h>
|
2022-01-31 13:10:28 +01:00
|
|
|
#include <texteditor/codeassist/iassistprocessor.h>
|
2021-06-22 14:47:30 +02:00
|
|
|
#include <texteditor/quickfix.h>
|
|
|
|
|
|
|
|
|
|
#include <languageserverprotocol/languagefeatures.h>
|
|
|
|
|
|
|
|
|
|
#include <QPointer>
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2022-05-13 14:57:08 +02:00
|
|
|
namespace TextEditor {
|
|
|
|
|
class IAssistProposal;
|
|
|
|
|
class GenericProposal;
|
|
|
|
|
} // namespace TextEditor
|
2022-01-31 13:10:28 +01:00
|
|
|
|
2018-07-13 12:33:46 +02:00
|
|
|
namespace LanguageClient {
|
|
|
|
|
|
2019-01-31 12:15:43 +01:00
|
|
|
class Client;
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2021-06-22 14:47:30 +02:00
|
|
|
class LANGUAGECLIENT_EXPORT CodeActionQuickFixOperation : public TextEditor::QuickFixOperation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CodeActionQuickFixOperation(const LanguageServerProtocol::CodeAction &action, Client *client);
|
|
|
|
|
void perform() override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
LanguageServerProtocol::CodeAction m_action;
|
|
|
|
|
QPointer<Client> m_client;
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-13 14:57:08 +02:00
|
|
|
class LANGUAGECLIENT_EXPORT CommandQuickFixOperation : public TextEditor::QuickFixOperation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CommandQuickFixOperation(const LanguageServerProtocol::Command &command, Client *client);
|
|
|
|
|
void perform() override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
LanguageServerProtocol::Command m_command;
|
|
|
|
|
QPointer<Client> m_client;
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-22 14:47:30 +02:00
|
|
|
class LANGUAGECLIENT_EXPORT LanguageClientQuickFixProvider : public TextEditor::IAssistProvider
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2019-01-29 13:20:58 +01:00
|
|
|
explicit LanguageClientQuickFixProvider(Client *client);
|
2021-09-15 07:04:12 +02:00
|
|
|
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2022-01-31 13:10:28 +01:00
|
|
|
protected:
|
|
|
|
|
Client *client() const { return m_client; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Client *m_client = nullptr; // not owned
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class LANGUAGECLIENT_EXPORT LanguageClientQuickFixAssistProcessor
|
|
|
|
|
: public TextEditor::IAssistProcessor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit LanguageClientQuickFixAssistProcessor(Client *client) : m_client(client) {}
|
|
|
|
|
bool running() override { return m_currentRequest.has_value(); }
|
2022-11-09 15:38:22 +01:00
|
|
|
TextEditor::IAssistProposal *perform(TextEditor::AssistInterface *interface) override;
|
2022-01-31 13:10:28 +01:00
|
|
|
void cancel() override;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void setOnlyKinds(const QList<LanguageServerProtocol::CodeActionKind> &only);
|
2022-05-13 14:57:08 +02:00
|
|
|
Client *client() { return m_client; }
|
2022-01-31 13:10:28 +01:00
|
|
|
|
2018-07-13 12:33:46 +02:00
|
|
|
private:
|
2022-05-13 14:57:08 +02:00
|
|
|
void handleCodeActionResponse(
|
|
|
|
|
const LanguageServerProtocol::CodeActionRequest::Response &response);
|
|
|
|
|
virtual TextEditor::GenericProposal *handleCodeActionResult(
|
|
|
|
|
const LanguageServerProtocol::CodeActionResult &result);
|
2022-01-31 13:10:28 +01:00
|
|
|
|
|
|
|
|
QSharedPointer<const TextEditor::AssistInterface> m_assistInterface;
|
2019-01-29 13:20:58 +01:00
|
|
|
Client *m_client = nullptr; // not owned
|
2022-08-26 10:30:00 +02:00
|
|
|
std::optional<LanguageServerProtocol::MessageId> m_currentRequest;
|
2018-07-13 12:33:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace LanguageClient
|