forked from qt-creator/qt-creator
ClangCodeModel: Fix sorting of includes when auto-completing
... by treating the directory separator specially. Fixes: QTCREATORBUG-21490 Change-Id: Iad6f51f39516a88bd14ba1eddcf2c6656490ee5b Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -60,6 +60,7 @@
|
|||||||
#include <utils/textutils.h>
|
#include <utils/textutils.h>
|
||||||
|
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
|
#include <QPair>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel {
|
||||||
@@ -512,11 +513,17 @@ bool ClangCompletionAssistProcessor::completeInclude(const QTextCursor &cursor)
|
|||||||
completeIncludePath(realPath, suffixes);
|
completeIncludePath(realPath, suffixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto includesCompare = [](AssistProposalItemInterface *first,
|
QList<QPair<AssistProposalItemInterface *, QString>> completionsForSorting;
|
||||||
AssistProposalItemInterface *second) {
|
for (AssistProposalItemInterface * const item : qAsConst(m_completions)) {
|
||||||
return first->text() < second->text();
|
QString s = item->text();
|
||||||
};
|
s.replace('/', QChar(0)); // The dir separator should compare less than anything else.
|
||||||
std::sort(m_completions.begin(), m_completions.end(), includesCompare);
|
completionsForSorting << qMakePair(item, s);
|
||||||
|
}
|
||||||
|
Utils::sort(completionsForSorting, [](const auto &left, const auto &right) {
|
||||||
|
return left.second < right.second;
|
||||||
|
});
|
||||||
|
for (int i = 0; i < completionsForSorting.count(); ++i)
|
||||||
|
m_completions[i] = completionsForSorting[i].first;
|
||||||
|
|
||||||
return !m_completions.isEmpty();
|
return !m_completions.isEmpty();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user