2018-07-13 12:33:46 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|
IAssistProvider::RunType runType() const override;
|
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(); }
|
|
|
|
|
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
|
|
|
|
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-01-31 13:10:28 +01:00
|
|
|
Utils::optional<LanguageServerProtocol::MessageId> m_currentRequest;
|
2018-07-13 12:33:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace LanguageClient
|