forked from qt-creator/qt-creator
LanguageClient: move relevant snippets to the front
If a snippet starts with the current prefix move it to the front of the proposed completions. Fixes: QTCREATORBUG-27566 Change-Id: I568d34e4da596a8cf4f08eb88eb1ee865edbed70 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -233,7 +233,7 @@ public:
|
|||||||
// GenericProposalModel interface
|
// GenericProposalModel interface
|
||||||
bool containsDuplicates() const override { return false; }
|
bool containsDuplicates() const override { return false; }
|
||||||
bool isSortable(const QString &/*prefix*/) const override;
|
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; }
|
||||||
|
|
||||||
QList<AssistProposalItemInterface *> items() const { return m_currentItems; }
|
QList<AssistProposalItemInterface *> items() const { return m_currentItems; }
|
||||||
@@ -247,19 +247,21 @@ bool LanguageClientCompletionModel::isSortable(const QString &) const
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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(),
|
||||||
[] (AssistProposalItemInterface *a, AssistProposalItemInterface *b){
|
[&prefix] (AssistProposalItemInterface *a, AssistProposalItemInterface *b){
|
||||||
const auto lca = dynamic_cast<LanguageClientCompletionItem *>(a);
|
const auto lca = dynamic_cast<LanguageClientCompletionItem *>(a);
|
||||||
const auto lcb = dynamic_cast<LanguageClientCompletionItem *>(b);
|
const auto lcb = dynamic_cast<LanguageClientCompletionItem *>(b);
|
||||||
if (!lca && !lcb)
|
if (!lca && !lcb)
|
||||||
return a->text() < b->text();
|
return a->text() < b->text();
|
||||||
if (lca && lcb)
|
if (lca && lcb)
|
||||||
return *lca < *lcb;
|
return *lca < *lcb;
|
||||||
if (lca && !lcb)
|
if (prefix.isEmpty())
|
||||||
return true;
|
return lca && !lcb;
|
||||||
return false;
|
if (!lca)
|
||||||
|
return a->text().toLower().startsWith(prefix.toLower());
|
||||||
|
return !b->text().toLower().startsWith(prefix.toLower());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user