forked from qt-creator/qt-creator
ClangCodeModel: Move quickfix functionality to dedicated set of files
Change-Id: I7cc55afa7aa50ba584593457b6c1393794866c56 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -19,7 +19,7 @@ add_qtc_plugin(ClangCodeModel
|
||||
clangdclient.cpp clangdclient.h
|
||||
clangdfollowsymbol.cpp clangdfollowsymbol.h
|
||||
clangdiagnostictooltipwidget.cpp clangdiagnostictooltipwidget.h
|
||||
clangdquickfixfactory.cpp clangdquickfixfactory.h
|
||||
clangdquickfixes.cpp clangdquickfixes.h
|
||||
clangdqpropertyhighlighter.cpp clangdqpropertyhighlighter.h
|
||||
clangdsemantichighlighting.cpp clangdsemantichighlighting.h
|
||||
clangdswitchdecldef.cpp clangdswitchdecldef.h
|
||||
|
@@ -42,8 +42,8 @@ QtcPlugin {
|
||||
"clangdlocatorfilters.h",
|
||||
"clangdqpropertyhighlighter.cpp",
|
||||
"clangdqpropertyhighlighter.h",
|
||||
"clangdquickfixfactory.cpp",
|
||||
"clangdquickfixfactory.h",
|
||||
"clangdquickfixes.cpp",
|
||||
"clangdquickfixes.h",
|
||||
"clangdsemantichighlighting.cpp",
|
||||
"clangdsemantichighlighting.h",
|
||||
"clangdswitchdecldef.cpp",
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "clangdast.h"
|
||||
#include "clangdfollowsymbol.h"
|
||||
#include "clangdlocatorfilters.h"
|
||||
#include "clangdquickfixes.h"
|
||||
#include "clangdswitchdecldef.h"
|
||||
#include "clangpreprocessorassistproposalitem.h"
|
||||
#include "clangtextmark.h"
|
||||
@@ -65,7 +66,6 @@
|
||||
#include <languageclient/languageclienthoverhandler.h>
|
||||
#include <languageclient/languageclientinterface.h>
|
||||
#include <languageclient/languageclientmanager.h>
|
||||
#include <languageclient/languageclientquickfix.h>
|
||||
#include <languageclient/languageclientsymbolsupport.h>
|
||||
#include <languageclient/languageclientutils.h>
|
||||
#include <languageserverprotocol/clientcapabilities.h>
|
||||
@@ -775,71 +775,6 @@ private:
|
||||
ClangdClient * const m_client;
|
||||
};
|
||||
|
||||
class ClangdQuickFixProcessor : public LanguageClientQuickFixAssistProcessor
|
||||
{
|
||||
public:
|
||||
ClangdQuickFixProcessor(LanguageClient::Client *client)
|
||||
: LanguageClientQuickFixAssistProcessor(client)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(const AssistInterface *interface) override
|
||||
{
|
||||
m_interface = interface;
|
||||
|
||||
// Step 1: Collect clangd code actions asynchronously
|
||||
LanguageClientQuickFixAssistProcessor::perform(interface);
|
||||
|
||||
// Step 2: Collect built-in quickfixes synchronously
|
||||
m_builtinOps = CppEditor::quickFixOperations(interface);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TextEditor::GenericProposal *handleCodeActionResult(const CodeActionResult &result) override
|
||||
{
|
||||
auto toOperation =
|
||||
[=](const Utils::variant<Command, CodeAction> &item) -> QuickFixOperation * {
|
||||
if (auto action = Utils::get_if<CodeAction>(&item)) {
|
||||
const Utils::optional<QList<Diagnostic>> diagnostics = action->diagnostics();
|
||||
if (!diagnostics.has_value() || diagnostics->isEmpty())
|
||||
return new CodeActionQuickFixOperation(*action, client());
|
||||
}
|
||||
if (auto command = Utils::get_if<Command>(&item))
|
||||
return new CommandQuickFixOperation(*command, client());
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
if (auto list = Utils::get_if<QList<Utils::variant<Command, CodeAction>>>(&result)) {
|
||||
QuickFixOperations ops;
|
||||
for (const Utils::variant<Command, CodeAction> &item : *list) {
|
||||
if (QuickFixOperation *op = toOperation(item)) {
|
||||
op->setDescription("clangd: " + op->description());
|
||||
ops << op;
|
||||
}
|
||||
}
|
||||
return GenericProposal::createProposal(m_interface, ops + m_builtinOps);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QuickFixOperations m_builtinOps;
|
||||
const AssistInterface *m_interface = nullptr;
|
||||
};
|
||||
|
||||
class ClangdQuickFixProvider : public LanguageClientQuickFixProvider
|
||||
{
|
||||
public:
|
||||
ClangdQuickFixProvider(ClangdClient *client) : LanguageClientQuickFixProvider(client) {};
|
||||
|
||||
private:
|
||||
IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override
|
||||
{
|
||||
return new ClangdQuickFixProcessor(client());
|
||||
}
|
||||
};
|
||||
|
||||
static void addToCompilationDb(QJsonObject &cdb,
|
||||
const CppEditor::ProjectPart &projectPart,
|
||||
CppEditor::UsePrecompiledHeaders usePch,
|
||||
|
@@ -23,14 +23,16 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "clangdquickfixfactory.h"
|
||||
#include "clangdquickfixes.h"
|
||||
|
||||
#include "clangdclient.h"
|
||||
#include "clangmodelmanagersupport.h"
|
||||
|
||||
#include <languageclient/languageclientquickfix.h>
|
||||
#include <texteditor/codeassist/genericproposal.h>
|
||||
|
||||
using namespace LanguageClient;
|
||||
using namespace LanguageServerProtocol;
|
||||
using namespace TextEditor;
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
@@ -58,5 +60,66 @@ void ClangdQuickFixFactory::match(const CppEditor::Internal::CppQuickFixInterfac
|
||||
}
|
||||
}
|
||||
|
||||
class ClangdQuickFixProcessor : public LanguageClientQuickFixAssistProcessor
|
||||
{
|
||||
public:
|
||||
ClangdQuickFixProcessor(LanguageClient::Client *client)
|
||||
: LanguageClientQuickFixAssistProcessor(client)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(const AssistInterface *interface) override
|
||||
{
|
||||
m_interface = interface;
|
||||
|
||||
// Step 1: Collect clangd code actions asynchronously
|
||||
LanguageClientQuickFixAssistProcessor::perform(interface);
|
||||
|
||||
// Step 2: Collect built-in quickfixes synchronously
|
||||
m_builtinOps = CppEditor::quickFixOperations(interface);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TextEditor::GenericProposal *handleCodeActionResult(const CodeActionResult &result) override
|
||||
{
|
||||
auto toOperation =
|
||||
[=](const Utils::variant<Command, CodeAction> &item) -> QuickFixOperation * {
|
||||
if (auto action = Utils::get_if<CodeAction>(&item)) {
|
||||
const Utils::optional<QList<Diagnostic>> diagnostics = action->diagnostics();
|
||||
if (!diagnostics.has_value() || diagnostics->isEmpty())
|
||||
return new CodeActionQuickFixOperation(*action, client());
|
||||
}
|
||||
if (auto command = Utils::get_if<Command>(&item))
|
||||
return new CommandQuickFixOperation(*command, client());
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
if (auto list = Utils::get_if<QList<Utils::variant<Command, CodeAction>>>(&result)) {
|
||||
QuickFixOperations ops;
|
||||
for (const Utils::variant<Command, CodeAction> &item : *list) {
|
||||
if (QuickFixOperation *op = toOperation(item)) {
|
||||
op->setDescription("clangd: " + op->description());
|
||||
ops << op;
|
||||
}
|
||||
}
|
||||
return GenericProposal::createProposal(m_interface, ops + m_builtinOps);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QuickFixOperations m_builtinOps;
|
||||
const AssistInterface *m_interface = nullptr;
|
||||
};
|
||||
|
||||
ClangdQuickFixProvider::ClangdQuickFixProvider(ClangdClient *client)
|
||||
: LanguageClientQuickFixProvider(client) {}
|
||||
|
||||
IAssistProcessor *ClangdQuickFixProvider::createProcessor(const AssistInterface *) const
|
||||
{
|
||||
return new ClangdQuickFixProcessor(client());
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangCodeModel
|
@@ -26,9 +26,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <cppeditor/cppquickfix.h>
|
||||
#include <languageclient/languageclientquickfix.h>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
class ClangdClient;
|
||||
|
||||
class ClangdQuickFixFactory : public CppEditor::CppQuickFixFactory
|
||||
{
|
||||
@@ -39,5 +41,15 @@ public:
|
||||
QuickFixOperations &result) override;
|
||||
};
|
||||
|
||||
class ClangdQuickFixProvider : public LanguageClient::LanguageClientQuickFixProvider
|
||||
{
|
||||
public:
|
||||
ClangdQuickFixProvider(ClangdClient *client);
|
||||
|
||||
private:
|
||||
TextEditor::IAssistProcessor *createProcessor(
|
||||
const TextEditor::AssistInterface *) const override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangCodeModel
|
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "clangconstants.h"
|
||||
#include "clangdclient.h"
|
||||
#include "clangdquickfixfactory.h"
|
||||
#include "clangdquickfixes.h"
|
||||
#include "clangeditordocumentprocessor.h"
|
||||
#include "clangdlocatorfilters.h"
|
||||
#include "clangutils.h"
|
||||
|
Reference in New Issue
Block a user