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 <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2024-11-15 11:12:42 +01:00
parent 1dd900f9f5
commit 8937d9d142

View File

@@ -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<LanguageClientCompletionItem *>(item))