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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user