From 8937d9d142831612ce5622ad57e71ac1efcbd466 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 15 Nov 2024 11:12:42 +0100 Subject: [PATCH] LanguageClient: fix hasItemsToPropose check in completion model Prefilter the candidates before checking whether the item is a perfect match allows to ignore items that are part of the inserted code to complete. In the example of QTCREATORBUG-32013 tex matched against x and returned a perfect match in that case. If the model reports a perfect match the completion widget is not shown by default but needs to be triggered explicitly. Fixes: QTCREATORBUG-32013 Change-Id: Icd1da6163f0bee2ff09a37456dd51b350fd4fe10 Reviewed-by: Christian Stenger --- .../languageclient/languageclientcompletionassist.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/languageclient/languageclientcompletionassist.cpp b/src/plugins/languageclient/languageclientcompletionassist.cpp index 7919de0de81..7b2d4b02d45 100644 --- a/src/plugins/languageclient/languageclientcompletionassist.cpp +++ b/src/plugins/languageclient/languageclientcompletionassist.cpp @@ -347,11 +347,16 @@ public: {} // IAssistProposal interface - bool hasItemsToPropose(const QString &/*text*/, AssistReason reason) const override + bool hasItemsToPropose(const QString &prefix, AssistReason reason) const override { if (m_model->size() <= 0 || m_document.isNull()) return false; + if (!prefix.isEmpty()) { + m_model->filter(prefix); + m_model->setPrefilterPrefix(prefix); + } + return m_model->keepPerfectMatch(reason) || !Utils::anyOf(m_model->items(), [this](AssistProposalItemInterface *item){ if (const auto lcItem = dynamic_cast(item))