forked from qt-creator/qt-creator
CppLocatorFilter: Simplify priority handling
Change-Id: I612e0cc5e56a50bd6830ae2f25291aaed571ae67 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
86c4416af6
commit
56948e75d8
@@ -33,6 +33,7 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
using namespace CppTools::Internal;
|
using namespace CppTools::Internal;
|
||||||
@@ -68,16 +69,14 @@ void CppLocatorFilter::refresh(QFutureInterface<void> &future)
|
|||||||
QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
|
QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
|
||||||
QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry)
|
QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry)
|
||||||
{
|
{
|
||||||
QList<Core::LocatorFilterEntry> normalEntries;
|
enum { Best = 0, Better, Good, Normal, EntryNumber };
|
||||||
QList<Core::LocatorFilterEntry> goodEntries;
|
QList<Core::LocatorFilterEntry> entries[EntryNumber];
|
||||||
QList<Core::LocatorFilterEntry> betterEntries;
|
|
||||||
QList<Core::LocatorFilterEntry> bestEntries;
|
|
||||||
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
|
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
|
||||||
const IndexItem::ItemType wanted = matchTypes();
|
const IndexItem::ItemType wanted = matchTypes();
|
||||||
|
|
||||||
const QRegularExpression regexp = createRegExp(entry);
|
const QRegularExpression regexp = createRegExp(entry);
|
||||||
if (!regexp.isValid())
|
if (!regexp.isValid())
|
||||||
return goodEntries;
|
return {};
|
||||||
const bool hasColonColon = entry.contains("::");
|
const bool hasColonColon = entry.contains("::");
|
||||||
const QRegularExpression shortRegexp =
|
const QRegularExpression shortRegexp =
|
||||||
hasColonColon ? createRegExp(entry.mid(entry.lastIndexOf("::") + 2)) : regexp;
|
hasColonColon ? createRegExp(entry.mid(entry.lastIndexOf("::") + 2)) : regexp;
|
||||||
@@ -114,13 +113,13 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (matchInParameterList)
|
if (matchInParameterList)
|
||||||
normalEntries.append(filterEntry);
|
entries[Normal].append(filterEntry);
|
||||||
else if (filterEntry.displayName.startsWith(entry, caseSensitivityForPrefix))
|
else if (filterEntry.displayName.startsWith(entry, caseSensitivityForPrefix))
|
||||||
bestEntries.append(filterEntry);
|
entries[Best].append(filterEntry);
|
||||||
else if (filterEntry.displayName.contains(entry, caseSensitivityForPrefix))
|
else if (filterEntry.displayName.contains(entry, caseSensitivityForPrefix))
|
||||||
betterEntries.append(filterEntry);
|
entries[Better].append(filterEntry);
|
||||||
else
|
else
|
||||||
goodEntries.append(filterEntry);
|
entries[Good].append(filterEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,19 +129,12 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
|
|||||||
return IndexItem::Recurse;
|
return IndexItem::Recurse;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (normalEntries.size() < 1000)
|
for (auto &entry : entries) {
|
||||||
Utils::sort(normalEntries, Core::LocatorFilterEntry::compareLexigraphically);
|
if (entry.size() < 1000)
|
||||||
if (goodEntries.size() < 1000)
|
Utils::sort(entry, Core::LocatorFilterEntry::compareLexigraphically);
|
||||||
Utils::sort(goodEntries, Core::LocatorFilterEntry::compareLexigraphically);
|
}
|
||||||
if (betterEntries.size() < 1000)
|
|
||||||
Utils::sort(betterEntries, Core::LocatorFilterEntry::compareLexigraphically);
|
|
||||||
if (bestEntries.size() < 1000)
|
|
||||||
Utils::sort(bestEntries, Core::LocatorFilterEntry::compareLexigraphically);
|
|
||||||
|
|
||||||
bestEntries += betterEntries;
|
return std::accumulate(std::begin(entries), std::end(entries), QList<Core::LocatorFilterEntry>());
|
||||||
bestEntries += goodEntries;
|
|
||||||
bestEntries += normalEntries;
|
|
||||||
return bestEntries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppLocatorFilter::accept(Core::LocatorFilterEntry selection,
|
void CppLocatorFilter::accept(Core::LocatorFilterEntry selection,
|
||||||
|
Reference in New Issue
Block a user