diff options
author | David Schulz <david.schulz@qt.io> | 2023-08-11 14:13:07 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2023-08-11 12:38:08 +0000 |
commit | 28754ba08a63eca4b836c7b11892444aeeff5c88 (patch) | |
tree | e36690a15c9fbd022f27565b762bf39bcc0156e1 | |
parent | 49da6d897e539545c04f05eed0d20bd270ac3e05 (diff) |
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 <christian.kandeler@qt.io>
-rw-r--r-- | src/plugins/languageclient/languageclientcompletionassist.cpp | 24 |
1 files 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: |