CodeAssistant: add cancel to asynchronous processors

Fixes crash when the processor reports a result after the code assistant
was destroyed.

Change-Id: I8588d3d6acad69f1ec6302e8ba09d642ebbb77f1
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2020-02-12 14:06:45 +01:00
parent 86fae567fa
commit 552ccd6a61
6 changed files with 52 additions and 16 deletions

View File

@@ -84,15 +84,16 @@ class LanguageClientQuickFixAssistProcessor : public IAssistProcessor
{
public:
explicit LanguageClientQuickFixAssistProcessor(Client *client) : m_client(client) {}
bool running() override { return m_running; }
bool running() override { return m_currentRequest.isValid(); }
IAssistProposal *perform(const AssistInterface *interface) override;
void cancel() override;
private:
void handleCodeActionResponse(const CodeActionRequest::Response &response);
QSharedPointer<const AssistInterface> m_assistInterface;
Client *m_client = nullptr; // not owned
bool m_running = false;
MessageId m_currentRequest;
};
IAssistProposal *LanguageClientQuickFixAssistProcessor::perform(const AssistInterface *interface)
@@ -123,14 +124,22 @@ IAssistProposal *LanguageClientQuickFixAssistProcessor::perform(const AssistInte
});
m_client->requestCodeActions(request);
m_running = true;
m_currentRequest = request.id();
return nullptr;
}
void LanguageClientQuickFixAssistProcessor::cancel()
{
if (running()) {
m_client->cancelRequest(m_currentRequest);
m_currentRequest = MessageId();
}
}
void LanguageClientQuickFixAssistProcessor::handleCodeActionResponse(
const CodeActionRequest::Response &response)
{
m_running = false;
m_currentRequest = MessageId();
if (const Utils::optional<CodeActionRequest::Response::Error> &error = response.error())
m_client->log(*error);
QuickFixOperations ops;