forked from qt-creator/qt-creator
LSP: Do not sort completion items if none sets sortText
It is unclear if and how the client should order completion items, but at least haskell-language-server provides a sensibly sorted list (not alphabetically) and doesn't set a "sortText". Sorting the items alphabetically by label messes up the prioritization of "best" matches that the server correctly does. Only sort, if any item has a sortText. Task-number: QTCREATORBUG-26114 Change-Id: I55a966763e21ba8b85085a087c37e6005438d4e3 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -73,6 +73,7 @@ public:
|
|||||||
quint64 hash() const override;
|
quint64 hash() const override;
|
||||||
|
|
||||||
const QString &sortText() const;
|
const QString &sortText() const;
|
||||||
|
bool hasSortText() const;
|
||||||
|
|
||||||
bool operator <(const LanguageClientCompletionItem &other) const;
|
bool operator <(const LanguageClientCompletionItem &other) const;
|
||||||
|
|
||||||
@@ -208,6 +209,11 @@ const QString &LanguageClientCompletionItem::sortText() const
|
|||||||
return m_sortText;
|
return m_sortText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LanguageClientCompletionItem::hasSortText() const
|
||||||
|
{
|
||||||
|
return m_item.sortText().has_value();
|
||||||
|
}
|
||||||
|
|
||||||
QString LanguageClientCompletionItem::filterText() const
|
QString LanguageClientCompletionItem::filterText() const
|
||||||
{
|
{
|
||||||
if (m_filterText.isEmpty()) {
|
if (m_filterText.isEmpty()) {
|
||||||
@@ -249,7 +255,7 @@ class LanguageClientCompletionModel : public GenericProposalModel
|
|||||||
public:
|
public:
|
||||||
// GenericProposalModel interface
|
// GenericProposalModel interface
|
||||||
bool containsDuplicates() const override { return false; }
|
bool containsDuplicates() const override { return false; }
|
||||||
bool isSortable(const QString &/*prefix*/) const override { return true; }
|
bool isSortable(const QString &/*prefix*/) const override;
|
||||||
void sort(const QString &/*prefix*/) override;
|
void sort(const QString &/*prefix*/) override;
|
||||||
bool supportsPrefixExpansion() const override { return false; }
|
bool supportsPrefixExpansion() const override { return false; }
|
||||||
|
|
||||||
@@ -257,6 +263,11 @@ public:
|
|||||||
{ return Utils::static_container_cast<LanguageClientCompletionItem *>(m_currentItems); }
|
{ return Utils::static_container_cast<LanguageClientCompletionItem *>(m_currentItems); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool LanguageClientCompletionModel::isSortable(const QString &) const
|
||||||
|
{
|
||||||
|
return Utils::anyOf(items(), &LanguageClientCompletionItem::hasSortText);
|
||||||
|
}
|
||||||
|
|
||||||
void LanguageClientCompletionModel::sort(const QString &/*prefix*/)
|
void LanguageClientCompletionModel::sort(const QString &/*prefix*/)
|
||||||
{
|
{
|
||||||
std::sort(m_currentItems.begin(), m_currentItems.end(),
|
std::sort(m_currentItems.begin(), m_currentItems.end(),
|
||||||
|
Reference in New Issue
Block a user