HelpIndexFilter: Reimplement matchers()

Change-Id: I47bf8eee25b91ac5ae7d8fd2c06a34370d5d433f
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2023-04-18 00:25:35 +02:00
parent 72d72251d8
commit b19b4482c1
4 changed files with 84 additions and 4 deletions

View File

@@ -11,7 +11,7 @@
#include <coreplugin/helpmanager.h>
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/tasktree.h>
#include <utils/asynctask.h>
#include <utils/utilsicons.h>
#include <QHelpEngine>
@@ -21,6 +21,7 @@
using namespace Core;
using namespace Help;
using namespace Help::Internal;
using namespace Utils;
HelpIndexFilter::HelpIndexFilter()
{
@@ -42,6 +43,73 @@ HelpIndexFilter::HelpIndexFilter()
this, &HelpIndexFilter::invalidateCache);
}
static void matches(QPromise<QStringList> &promise, const LocatorStorage &storage,
const QStringList &cache, const QIcon &icon)
{
const QString input = storage.input();
const Qt::CaseSensitivity cs = ILocatorFilter::caseSensitivity(input);
QStringList bestKeywords;
QStringList worseKeywords;
bestKeywords.reserve(cache.size());
worseKeywords.reserve(cache.size());
for (const QString &keyword : cache) {
if (promise.isCanceled())
return;
if (keyword.startsWith(input, cs))
bestKeywords.append(keyword);
else if (keyword.contains(input, cs))
worseKeywords.append(keyword);
}
const QStringList lastIndicesCache = bestKeywords + worseKeywords;
LocatorFilterEntries entries;
for (const QString &key : lastIndicesCache) {
if (promise.isCanceled())
return;
const int index = key.indexOf(input, 0, cs);
LocatorFilterEntry filterEntry;
filterEntry.displayName = key;
filterEntry.acceptor = [key] {
HelpPlugin::showLinksInCurrentViewer(LocalHelpManager::linksForKeyword(key), key);
return AcceptResult();
};
filterEntry.displayIcon = icon;
filterEntry.highlightInfo = {index, int(input.length())};
entries.append(filterEntry);
}
storage.reportOutput(entries);
promise.addResult(lastIndicesCache);
}
LocatorMatcherTasks HelpIndexFilter::matchers()
{
using namespace Tasking;
TreeStorage<LocatorStorage> storage;
const auto onSetup = [this, storage](AsyncTask<QStringList> &async) {
if (m_needsUpdate) {
m_needsUpdate = false;
LocalHelpManager::setupGuiHelpEngine();
m_allIndicesCache = LocalHelpManager::filterEngine()->indices({});
m_lastIndicesCache.clear();
m_lastEntry.clear();
}
const QStringList cache = m_lastEntry.isEmpty() || !storage->input().contains(m_lastEntry)
? m_allIndicesCache : m_lastIndicesCache;
async.setFutureSynchronizer(HelpPlugin::futureSynchronizer());
async.setConcurrentCallData(matches, *storage, cache, m_icon);
};
const auto onDone = [this, storage](const AsyncTask<QStringList> &async) {
if (async.isResultAvailable()) {
m_lastIndicesCache = async.result();
m_lastEntry = storage->input();
}
};
return {{Async<QStringList>(onSetup, onDone), storage}};
}
void HelpIndexFilter::prepareSearch(const QString &entry)
{
Q_UNUSED(entry)

View File

@@ -19,6 +19,7 @@ public:
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
const QString &entry) override;
private:
Core::LocatorMatcherTasks matchers() final;
void invalidateCache();
QStringList m_allIndicesCache;

View File

@@ -43,6 +43,7 @@
#include <texteditor/texteditorconstants.h>
#include <utils/algorithm.h>
#include <utils/futuresynchronizer.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
@@ -97,7 +98,7 @@ class HelpPluginPrivate : public QObject
public:
HelpPluginPrivate();
void modeChanged(Utils::Id mode, Utils::Id old);
void modeChanged(Id mode, Id old);
void requestContextHelp();
void showContextHelp(const HelpItem &contextHelp);
@@ -142,6 +143,7 @@ public:
LocalHelpManager m_localHelpManager;
HelpIndexFilter helpIndexFilter;
FutureSynchronizer m_futureSynchronizer;
};
static HelpPluginPrivate *dd = nullptr;
@@ -395,6 +397,12 @@ HelpWidget *HelpPlugin::modeHelpWidget()
return dd->m_centralWidget;
}
FutureSynchronizer *HelpPlugin::futureSynchronizer()
{
QTC_ASSERT(dd, return nullptr);
return &dd->m_futureSynchronizer;
}
void HelpPluginPrivate::showLinksInCurrentViewer(const QMultiMap<QString, QUrl> &links, const QString &key)
{
if (links.size() < 1)
@@ -403,7 +411,7 @@ void HelpPluginPrivate::showLinksInCurrentViewer(const QMultiMap<QString, QUrl>
widget->showLinks(links, key);
}
void HelpPluginPrivate::modeChanged(Utils::Id mode, Utils::Id old)
void HelpPluginPrivate::modeChanged(Id mode, Id old)
{
Q_UNUSED(old)
if (mode == m_mode.id()) {
@@ -503,7 +511,7 @@ HelpViewer *HelpPluginPrivate::viewerForContextHelp()
void HelpPluginPrivate::requestContextHelp()
{
// Find out what to show
const QVariant tipHelpValue = Utils::ToolTip::contextHelp();
const QVariant tipHelpValue = ToolTip::contextHelp();
const HelpItem tipHelp = tipHelpValue.canConvert<HelpItem>()
? tipHelpValue.value<HelpItem>()
: HelpItem(tipHelpValue.toString());

View File

@@ -10,6 +10,8 @@ QT_BEGIN_NAMESPACE
class QUrl;
QT_END_NAMESPACE
namespace Utils { class FutureSynchronizer; }
namespace Help {
namespace Internal {
@@ -30,6 +32,7 @@ public:
const QString &key);
static HelpViewer *createHelpViewer();
static HelpWidget *modeHelpWidget();
static Utils::FutureSynchronizer *futureSynchronizer();
private:
void initialize() final;