forked from qt-creator/qt-creator
Editor: move ownership of assist interface to processor
This way the base class can manage the lifetime of the interface object and it doesn't need to be done in each implementation of perform. Change-Id: Ie1ce742e31b688a337533ee6c57d376146e25ace Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -46,7 +46,7 @@ public:
|
||||
unsigned completionOperator, CustomAssistMode mode);
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(AssistInterface *interface) override;
|
||||
IAssistProposal *perform() override;
|
||||
|
||||
AssistProposalItemInterface *createItem(const QString &text, const QIcon &icon) const;
|
||||
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
~ClangdCompletionAssistProcessor();
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(AssistInterface *interface) override;
|
||||
IAssistProposal *perform() override;
|
||||
QList<AssistProposalItemInterface *> generateCompletionItems(
|
||||
const QList<LanguageServerProtocol::CompletionItem> &items) const override;
|
||||
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
ClangdFunctionHintProcessor(ClangdClient *client);
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(AssistInterface *interface) override;
|
||||
IAssistProposal *perform() override;
|
||||
|
||||
ClangdClient * const m_client;
|
||||
};
|
||||
@@ -152,11 +152,7 @@ IAssistProcessor *ClangdCompletionAssistProvider::createProcessor(
|
||||
if (contextAnalyzer.completionAction()
|
||||
!= ClangCompletionContextAnalyzer::CompleteIncludePath) {
|
||||
class NoOpProcessor : public IAssistProcessor {
|
||||
IAssistProposal *perform(AssistInterface *interface) override
|
||||
{
|
||||
delete interface;
|
||||
return nullptr;
|
||||
}
|
||||
IAssistProposal *perform() override { return nullptr; }
|
||||
};
|
||||
return new NoOpProcessor;
|
||||
}
|
||||
@@ -406,7 +402,7 @@ CustomAssistProcessor::CustomAssistProcessor(ClangdClient *client, int position,
|
||||
, m_mode(mode)
|
||||
{}
|
||||
|
||||
IAssistProposal *CustomAssistProcessor::perform(AssistInterface *interface)
|
||||
IAssistProposal *CustomAssistProcessor::perform()
|
||||
{
|
||||
QList<AssistProposalItemInterface *> completions;
|
||||
switch (m_mode) {
|
||||
@@ -422,21 +418,20 @@ IAssistProposal *CustomAssistProcessor::perform(AssistInterface *interface)
|
||||
: CppCompletionAssistProcessor::preprocessorCompletions()) {
|
||||
completions << createItem(completion, macroIcon);
|
||||
}
|
||||
if (ProjectFile::isObjC(interface->filePath().toString()))
|
||||
if (ProjectFile::isObjC(interface()->filePath().toString()))
|
||||
completions << createItem("import", macroIcon);
|
||||
break;
|
||||
}
|
||||
case CustomAssistMode::IncludePath: {
|
||||
HeaderPaths headerPaths;
|
||||
const ProjectPart::ConstPtr projectPart
|
||||
= projectPartForFile(interface->filePath().toString());
|
||||
= projectPartForFile(interface()->filePath().toString());
|
||||
if (projectPart)
|
||||
headerPaths = projectPart->headerPaths;
|
||||
completions = completeInclude(m_endPos, m_completionOperator, interface, headerPaths);
|
||||
completions = completeInclude(m_endPos, m_completionOperator, interface(), headerPaths);
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete interface;
|
||||
GenericProposalModelPtr model(new GenericProposalModel);
|
||||
model->loadContent(completions);
|
||||
const auto proposal = new GenericProposal(m_position, model);
|
||||
@@ -572,14 +567,14 @@ ClangdCompletionAssistProcessor::~ClangdCompletionAssistProcessor()
|
||||
<< "ClangdCompletionAssistProcessor took: " << m_timer.elapsed() << " ms";
|
||||
}
|
||||
|
||||
IAssistProposal *ClangdCompletionAssistProcessor::perform(AssistInterface *interface)
|
||||
IAssistProposal *ClangdCompletionAssistProcessor::perform()
|
||||
{
|
||||
if (m_client->testingEnabled()) {
|
||||
setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal) {
|
||||
emit m_client->proposalReady(proposal);
|
||||
});
|
||||
}
|
||||
return LanguageClientCompletionAssistProcessor::perform(interface);
|
||||
return LanguageClientCompletionAssistProcessor::perform();
|
||||
}
|
||||
|
||||
QList<AssistProposalItemInterface *> ClangdCompletionAssistProcessor::generateCompletionItems(
|
||||
@@ -618,14 +613,14 @@ ClangdFunctionHintProcessor::ClangdFunctionHintProcessor(ClangdClient *client)
|
||||
, m_client(client)
|
||||
{}
|
||||
|
||||
IAssistProposal *ClangdFunctionHintProcessor::perform(AssistInterface *interface)
|
||||
IAssistProposal *ClangdFunctionHintProcessor::perform()
|
||||
{
|
||||
if (m_client->testingEnabled()) {
|
||||
setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal) {
|
||||
emit m_client->proposalReady(proposal);
|
||||
});
|
||||
}
|
||||
return FunctionHintProcessor::perform(interface);
|
||||
return FunctionHintProcessor::perform();
|
||||
}
|
||||
|
||||
ClangdCompletionCapabilities::ClangdCompletionCapabilities(const JsonObject &object)
|
||||
|
||||
@@ -42,9 +42,8 @@ public:
|
||||
void resetData(bool resetFollowSymbolData);
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(AssistInterface *interface) override
|
||||
IAssistProposal *perform() override
|
||||
{
|
||||
delete interface;
|
||||
return createProposal(false);
|
||||
}
|
||||
|
||||
@@ -61,7 +60,7 @@ public:
|
||||
: m_followSymbol(followSymbol) {}
|
||||
|
||||
private:
|
||||
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
||||
IAssistProcessor *createProcessor(const AssistInterface *interface) const override;
|
||||
|
||||
const QPointer<ClangdFollowSymbol> m_followSymbol;
|
||||
};
|
||||
|
||||
@@ -47,15 +47,13 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(AssistInterface *interface) override
|
||||
IAssistProposal *perform() override
|
||||
{
|
||||
m_interface = interface;
|
||||
|
||||
// Step 1: Collect clangd code actions asynchronously
|
||||
LanguageClientQuickFixAssistProcessor::perform(interface);
|
||||
LanguageClientQuickFixAssistProcessor::perform();
|
||||
|
||||
// Step 2: Collect built-in quickfixes synchronously
|
||||
m_builtinOps = CppEditor::quickFixOperations(interface);
|
||||
m_builtinOps = CppEditor::quickFixOperations(interface());
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -82,13 +80,12 @@ private:
|
||||
ops << op;
|
||||
}
|
||||
}
|
||||
return GenericProposal::createProposal(m_interface, ops + m_builtinOps);
|
||||
return GenericProposal::createProposal(interface(), ops + m_builtinOps);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QuickFixOperations m_builtinOps;
|
||||
const AssistInterface *m_interface = nullptr;
|
||||
};
|
||||
|
||||
ClangdQuickFixProvider::ClangdQuickFixProvider(ClangdClient *client)
|
||||
|
||||
Reference in New Issue
Block a user