forked from qt-creator/qt-creator
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:
@@ -65,14 +65,15 @@ class FunctionHintProcessor : public IAssistProcessor
|
||||
public:
|
||||
explicit FunctionHintProcessor(Client *client) : m_client(client) {}
|
||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
||||
bool running() override { return m_running; }
|
||||
bool running() override { return m_currentRequest.isValid(); }
|
||||
bool needsRestart() const override { return true; }
|
||||
void cancel() override;
|
||||
|
||||
private:
|
||||
void handleSignatureResponse(const SignatureHelpRequest::Response &response);
|
||||
|
||||
QPointer<Client> m_client;
|
||||
bool m_running = false;
|
||||
MessageId m_currentRequest;
|
||||
int m_pos = -1;
|
||||
};
|
||||
|
||||
@@ -87,13 +88,21 @@ IAssistProposal *FunctionHintProcessor::perform(const AssistInterface *interface
|
||||
request.setParams(TextDocumentPositionParams(TextDocumentIdentifier(uri), Position(cursor)));
|
||||
request.setResponseCallback([this](auto response) { this->handleSignatureResponse(response); });
|
||||
m_client->sendContent(request);
|
||||
m_running = true;
|
||||
m_currentRequest = request.id();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void FunctionHintProcessor::cancel()
|
||||
{
|
||||
if (running()) {
|
||||
m_client->cancelRequest(m_currentRequest);
|
||||
m_currentRequest = MessageId();
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionHintProcessor::handleSignatureResponse(const SignatureHelpRequest::Response &response)
|
||||
{
|
||||
m_running = false;
|
||||
m_currentRequest = MessageId();
|
||||
if (auto error = response.error())
|
||||
m_client->log(error.value());
|
||||
FunctionHintProposalModelPtr model(
|
||||
|
||||
Reference in New Issue
Block a user