LSP: fix codeassists running check

Since MessageId is always valid (needs to be fixed separately)
use an optional to store whether we have a request running.

Change-Id: I7a1f136a09d776b33509bc914247d11076abeaa5
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2020-05-14 08:15:39 +02:00
parent 32d29f5a11
commit f3407bb0ca
3 changed files with 18 additions and 16 deletions

View File

@@ -57,7 +57,9 @@ private:
QString FunctionHintProposalModel::text(int index) const
{
return m_sigis.signatures().size() > index ? m_sigis.signatures().at(index).label() : QString();
if (index < 0 || m_sigis.signatures().size() >= index)
return {};
return m_sigis.signatures().at(index).label();
}
class FunctionHintProcessor : public IAssistProcessor
@@ -65,7 +67,7 @@ class FunctionHintProcessor : public IAssistProcessor
public:
explicit FunctionHintProcessor(Client *client) : m_client(client) {}
IAssistProposal *perform(const AssistInterface *interface) override;
bool running() override { return m_currentRequest.isValid(); }
bool running() override { return m_currentRequest.has_value(); }
bool needsRestart() const override { return true; }
void cancel() override;
@@ -73,7 +75,7 @@ private:
void handleSignatureResponse(const SignatureHelpRequest::Response &response);
QPointer<Client> m_client;
MessageId m_currentRequest;
Utils::optional<MessageId> m_currentRequest;
int m_pos = -1;
};
@@ -95,15 +97,15 @@ IAssistProposal *FunctionHintProcessor::perform(const AssistInterface *interface
void FunctionHintProcessor::cancel()
{
if (running()) {
m_client->cancelRequest(m_currentRequest);
m_client->cancelRequest(m_currentRequest.value());
m_client->removeAssistProcessor(this);
m_currentRequest = MessageId();
m_currentRequest.reset();
}
}
void FunctionHintProcessor::handleSignatureResponse(const SignatureHelpRequest::Response &response)
{
m_currentRequest = MessageId();
m_currentRequest.reset();
if (auto error = response.error())
m_client->log(error.value());
m_client->removeAssistProcessor(this);