From 28754ba08a63eca4b836c7b11892444aeeff5c88 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 11 Aug 2023 14:13:07 +0200 Subject: LanguageClient: fix showing obsolete proposals When receiving a null proposal and the processor is not running after updating a proposal we need to make sure the previous visible proposal widget gets closed. Change-Id: Icb0a7293698e603df3ba8cab34a08c10fe6784da Reviewed-by: Christian Kandeler --- .../languageclientcompletionassist.cpp | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/plugins/languageclient/languageclientcompletionassist.cpp b/src/plugins/languageclient/languageclientcompletionassist.cpp index c5c86122fc..62daa1457c 100644 --- a/src/plugins/languageclient/languageclientcompletionassist.cpp +++ b/src/plugins/languageclient/languageclientcompletionassist.cpp @@ -287,8 +287,13 @@ public: void setProposal(IAssistProposal *proposal, const QString &prefix) { - if (!proposal) + if (!proposal) { + // Close the proposal if we have no running processor otherwise ignore the empty + // proposal and wait for the processor to finish + if (!m_processor || !m_processor->running()) + closeProposal(); return; + } if (proposal->id() != TextEditor::Constants::GENERIC_PROPOSAL_ID) { // We received something else than a generic proposal so we cannot update the model closeProposal(); @@ -305,13 +310,14 @@ public: GenericProposalWidget::updateProposal(std::move(interface)); return; } - auto processor = m_provider->createProcessor(interface.get()); - QTC_ASSERT(processor, return); + m_processor = m_provider->createProcessor(interface.get()); + QTC_ASSERT(m_processor, return); const QString prefix = interface->textAt(m_basePosition, interface->position() - m_basePosition); - processor->setAsyncCompletionAvailableHandler([this, processor, prefix](IAssistProposal *proposal) { + m_processor->setAsyncCompletionAvailableHandler([this, processor = m_processor, prefix]( + IAssistProposal *proposal) { QTC_ASSERT(processor == m_processor, return); if (!processor->running()) { // do not delete this processor directly since this function is called from within the processor @@ -324,11 +330,11 @@ public: setProposal(proposal, prefix); }); - setProposal(processor->start(std::move(interface)), prefix); - if (processor->running()) - m_processor = processor; - else - delete processor; + setProposal(m_processor->start(std::move(interface)), prefix); + if (!m_processor->running()) { + delete m_processor; + m_processor = nullptr; + } } private: -- cgit v1.2.3