forked from qt-creator/qt-creator
QmlJSToolsPlugin: Reimplement matchers()
Change-Id: If6767b4dc62eddddce0285b7b766f44241f3367e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -5,12 +5,16 @@
|
|||||||
#include "qmljslocatordata.h"
|
#include "qmljslocatordata.h"
|
||||||
#include "qmljstoolstr.h"
|
#include "qmljstoolstr.h"
|
||||||
|
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/asynctask.h>
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace QmlJSTools::Internal;
|
using namespace QmlJSTools::Internal;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(LocatorData::Entry)
|
Q_DECLARE_METATYPE(LocatorData::Entry)
|
||||||
|
|
||||||
@@ -25,7 +29,66 @@ FunctionFilter::FunctionFilter(LocatorData *data, QObject *parent)
|
|||||||
setDefaultIncludedByDefault(false);
|
setDefaultIncludedByDefault(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionFilter::~FunctionFilter() = default;
|
static void matches(QPromise<void> &promise, const LocatorStorage &storage,
|
||||||
|
const QHash<FilePath, QList<LocatorData::Entry>> &locatorEntries)
|
||||||
|
{
|
||||||
|
const QString input = storage.input();
|
||||||
|
const Qt::CaseSensitivity caseSensitivityForPrefix = ILocatorFilter::caseSensitivity(input);
|
||||||
|
const QRegularExpression regexp = ILocatorFilter::createRegExp(input);
|
||||||
|
if (!regexp.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
LocatorFilterEntries entries[int(ILocatorFilter::MatchLevel::Count)];
|
||||||
|
for (const QList<LocatorData::Entry> &items : locatorEntries) {
|
||||||
|
for (const LocatorData::Entry &info : items) {
|
||||||
|
if (promise.isCanceled())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (info.type != LocatorData::Function)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const QRegularExpressionMatch match = regexp.match(info.symbolName);
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
LocatorFilterEntry filterEntry;
|
||||||
|
filterEntry.displayName = info.displayName;
|
||||||
|
filterEntry.linkForEditor = {info.fileName, info.line, info.column};
|
||||||
|
filterEntry.extraInfo = info.extraInfo;
|
||||||
|
filterEntry.highlightInfo = ILocatorFilter::highlightInfo(match);
|
||||||
|
|
||||||
|
if (filterEntry.displayName.startsWith(input, caseSensitivityForPrefix))
|
||||||
|
entries[int(ILocatorFilter::MatchLevel::Best)].append(filterEntry);
|
||||||
|
else if (filterEntry.displayName.contains(input, caseSensitivityForPrefix))
|
||||||
|
entries[int(ILocatorFilter::MatchLevel::Better)].append(filterEntry);
|
||||||
|
else
|
||||||
|
entries[int(ILocatorFilter::MatchLevel::Good)].append(filterEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &entry : entries) {
|
||||||
|
if (promise.isCanceled())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (entry.size() < 1000)
|
||||||
|
Utils::sort(entry, LocatorFilterEntry::compareLexigraphically);
|
||||||
|
}
|
||||||
|
storage.reportOutput(std::accumulate(std::begin(entries), std::end(entries),
|
||||||
|
LocatorFilterEntries()));
|
||||||
|
}
|
||||||
|
|
||||||
|
LocatorMatcherTasks FunctionFilter::matchers()
|
||||||
|
{
|
||||||
|
using namespace Tasking;
|
||||||
|
|
||||||
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
|
const auto onSetup = [storage, entries = m_data->entries()](AsyncTask<void> &async) {
|
||||||
|
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
||||||
|
async.setConcurrentCallData(matches, *storage, entries);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {{Async<void>(onSetup), storage}};
|
||||||
|
}
|
||||||
|
|
||||||
QList<LocatorFilterEntry> FunctionFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future,
|
QList<LocatorFilterEntry> FunctionFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future,
|
||||||
const QString &entry)
|
const QString &entry)
|
||||||
|
|||||||
@@ -16,11 +16,12 @@ class FunctionFilter : public Core::ILocatorFilter
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FunctionFilter(LocatorData *data, QObject *parent = nullptr);
|
explicit FunctionFilter(LocatorData *data, QObject *parent = nullptr);
|
||||||
~FunctionFilter() override;
|
|
||||||
|
|
||||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||||
const QString &entry) override;
|
const QString &entry) override;
|
||||||
private:
|
private:
|
||||||
|
Core::LocatorMatcherTasks matchers() final;
|
||||||
|
|
||||||
LocatorData *m_data = nullptr;
|
LocatorData *m_data = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user