forked from qt-creator/qt-creator
CMakePM: Use ILocatorFilter::createRegExp for locator filter
This presets better results, and is in sync to what other locator filters are doing. Fixes: QTCREATORBUG-30452 Change-Id: Ia77d2a5f22b33b55aa081d09372ab5cf297bb065 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -35,8 +35,13 @@ static LocatorMatcherTasks cmakeMatchers(const BuildAcceptor &acceptor)
|
|||||||
|
|
||||||
const auto onSetup = [storage, acceptor] {
|
const auto onSetup = [storage, acceptor] {
|
||||||
const QString input = storage->input();
|
const QString input = storage->input();
|
||||||
|
const QRegularExpression regexp
|
||||||
|
= ILocatorFilter::createRegExp(input, ILocatorFilter::caseSensitivity(input));
|
||||||
|
if (!regexp.isValid())
|
||||||
|
return;
|
||||||
|
LocatorFilterEntries entries[int(ILocatorFilter::MatchLevel::Count)];
|
||||||
|
|
||||||
const QList<Project *> projects = ProjectManager::projects();
|
const QList<Project *> projects = ProjectManager::projects();
|
||||||
LocatorFilterEntries entries;
|
|
||||||
for (Project *project : projects) {
|
for (Project *project : projects) {
|
||||||
const auto cmakeProject = qobject_cast<const CMakeProject *>(project);
|
const auto cmakeProject = qobject_cast<const CMakeProject *>(project);
|
||||||
if (!cmakeProject || !cmakeProject->activeTarget())
|
if (!cmakeProject || !cmakeProject->activeTarget())
|
||||||
@@ -50,8 +55,8 @@ static LocatorMatcherTasks cmakeMatchers(const BuildAcceptor &acceptor)
|
|||||||
for (const CMakeBuildTarget &target : buildTargets) {
|
for (const CMakeBuildTarget &target : buildTargets) {
|
||||||
if (CMakeBuildSystem::filteredOutTarget(target))
|
if (CMakeBuildSystem::filteredOutTarget(target))
|
||||||
continue;
|
continue;
|
||||||
const int index = target.title.indexOf(input, 0, Qt::CaseInsensitive);
|
const QRegularExpressionMatch match = regexp.match(target.title);
|
||||||
if (index >= 0) {
|
if (match.hasMatch()) {
|
||||||
const FilePath projectPath = cmakeProject->projectFilePath();
|
const FilePath projectPath = cmakeProject->projectFilePath();
|
||||||
const QString displayName = target.title;
|
const QString displayName = target.title;
|
||||||
LocatorFilterEntry entry;
|
LocatorFilterEntry entry;
|
||||||
@@ -72,14 +77,21 @@ static LocatorMatcherTasks cmakeMatchers(const BuildAcceptor &acceptor)
|
|||||||
} else {
|
} else {
|
||||||
entry.extraInfo = projectPath.shortNativePath();
|
entry.extraInfo = projectPath.shortNativePath();
|
||||||
}
|
}
|
||||||
entry.highlightInfo = {index, int(input.length())};
|
entry.highlightInfo = ILocatorFilter::highlightInfo(match);
|
||||||
entry.filePath = cmakeProject->projectFilePath();
|
entry.filePath = cmakeProject->projectFilePath();
|
||||||
if (acceptor || realTarget)
|
if (acceptor || realTarget) {
|
||||||
entries.append(entry);
|
if (match.capturedStart() == 0)
|
||||||
|
entries[int(ILocatorFilter::MatchLevel::Best)].append(entry);
|
||||||
|
else if (match.lastCapturedIndex() == 1)
|
||||||
|
entries[int(ILocatorFilter::MatchLevel::Better)].append(entry);
|
||||||
|
else
|
||||||
|
entries[int(ILocatorFilter::MatchLevel::Good)].append(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
storage->reportOutput(entries);
|
}
|
||||||
|
storage->reportOutput(
|
||||||
|
std::accumulate(std::begin(entries), std::end(entries), LocatorFilterEntries()));
|
||||||
};
|
};
|
||||||
return {{Sync(onSetup), storage}};
|
return {{Sync(onSetup), storage}};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user