summaryrefslogtreecommitdiff
path: root/src/plugins/languageclient/languageclientfunctionhint.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2020-02-12 14:06:45 +0100
committerDavid Schulz <david.schulz@qt.io>2020-02-20 12:59:55 +0000
commit552ccd6a616b7f74f7948457b861a1124e2bf6cc (patch)
tree8b04cc5ddb52f1a019ae8bba077569f66a8f0d30 /src/plugins/languageclient/languageclientfunctionhint.cpp
parent86fae567fa38097d0075dc8c145c48b11a9182fc (diff)
downloadqt-creator-552ccd6a616b7f74f7948457b861a1124e2bf6cc.tar.gz
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>
Diffstat (limited to 'src/plugins/languageclient/languageclientfunctionhint.cpp')
-rw-r--r--src/plugins/languageclient/languageclientfunctionhint.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/plugins/languageclient/languageclientfunctionhint.cpp b/src/plugins/languageclient/languageclientfunctionhint.cpp
index 5e711adec6..3361864973 100644
--- a/src/plugins/languageclient/languageclientfunctionhint.cpp
+++ b/src/plugins/languageclient/languageclientfunctionhint.cpp
@@ -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(