forked from qt-creator/qt-creator
ILocatorFilter: Refactor ILocatorFilter::matchers() function
Introduce LocatorStorage::storage() method, to be used from the bodies of locator task handlers. Replace the return value of ILocatorFilter::matchers() with a list of ExecutableItems. Change-Id: I467bb9f217465af74a017095d4fffdf74c4ba7bd Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -15,34 +15,35 @@
|
||||
|
||||
#include <solutions/tasking/tasktree.h>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Autotest::Internal {
|
||||
|
||||
static void linkAcceptor(const Utils::Link &link)
|
||||
static void linkAcceptor(const Link &link)
|
||||
{
|
||||
if (link.hasValidTarget())
|
||||
Core::EditorManager::openEditorAt(link);
|
||||
EditorManager::openEditorAt(link);
|
||||
}
|
||||
|
||||
using LinkAcceptor = std::function<void(const Utils::Link &)>;
|
||||
using LinkAcceptor = std::function<void(const Link &)>;
|
||||
|
||||
static Core::LocatorMatcherTasks dataTagMatchers(const LinkAcceptor &acceptor)
|
||||
static LocatorMatcherTasks dataTagMatchers(const LinkAcceptor &acceptor)
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<Core::LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage, acceptor] {
|
||||
const QString input = storage->input();
|
||||
const auto onSetup = [acceptor] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
const QString input = storage.input();
|
||||
const TestTreeItem *qtTestRoot = theQtTestFramework().rootNode();
|
||||
if (!qtTestRoot)
|
||||
return;
|
||||
|
||||
Core::LocatorFilterEntries entries;
|
||||
LocatorFilterEntries entries;
|
||||
qtTestRoot->forAllChildItems([&entries, &input, acceptor = acceptor](TestTreeItem *it) {
|
||||
if (it->type() != TestTreeItem::TestDataTag)
|
||||
return;
|
||||
if (it->name().contains(input)) {
|
||||
Core::LocatorFilterEntry entry;
|
||||
LocatorFilterEntry entry;
|
||||
entry.displayName = it->data(0, Qt::DisplayRole).toString();
|
||||
{
|
||||
const TestTreeItem *parent = it->parentItem();
|
||||
@@ -52,18 +53,18 @@ static Core::LocatorMatcherTasks dataTagMatchers(const LinkAcceptor &acceptor)
|
||||
entry.displayExtra = grandParent->name() + "::" + parent->name();
|
||||
}
|
||||
}
|
||||
entry.linkForEditor = std::make_optional(it->data(0, LinkRole).value<Utils::Link>());
|
||||
entry.linkForEditor = std::make_optional(it->data(0, LinkRole).value<Link>());
|
||||
entry.acceptor = [link = entry.linkForEditor, acceptor = acceptor] {
|
||||
if (link)
|
||||
acceptor(*link);
|
||||
return Core::AcceptResult();
|
||||
return AcceptResult();
|
||||
};
|
||||
entries.append(entry);
|
||||
}
|
||||
});
|
||||
storage->reportOutput(entries);
|
||||
storage.reportOutput(entries);
|
||||
};
|
||||
return {{Sync(onSetup), storage}};
|
||||
return {Sync(onSetup)};
|
||||
}
|
||||
|
||||
DataTagLocatorFilter::DataTagLocatorFilter()
|
||||
@@ -79,7 +80,7 @@ DataTagLocatorFilter::DataTagLocatorFilter()
|
||||
setEnabled(ProjectManager::startupProject());
|
||||
}
|
||||
|
||||
Core::LocatorMatcherTasks DataTagLocatorFilter::matchers()
|
||||
LocatorMatcherTasks DataTagLocatorFilter::matchers()
|
||||
{
|
||||
return dataTagMatchers(&linkAcceptor);
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ using namespace Core;
|
||||
using namespace LanguageClient;
|
||||
using namespace LanguageServerProtocol;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Tasking;
|
||||
using namespace TextEditor;
|
||||
using namespace Utils;
|
||||
|
||||
@@ -173,29 +174,23 @@ static void filterCurrentResults(QPromise<void> &promise, const LocatorStorage &
|
||||
|
||||
static LocatorMatcherTask currentDocumentMatcher()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
Storage<CurrentDocumentSymbolsData> resultStorage;
|
||||
|
||||
const auto onQuerySetup = [=](CurrentDocumentSymbolsRequest &request) {
|
||||
Q_UNUSED(request)
|
||||
};
|
||||
const auto onQueryDone = [resultStorage](const CurrentDocumentSymbolsRequest &request) {
|
||||
*resultStorage = request.currentDocumentSymbolsData();
|
||||
};
|
||||
|
||||
const auto onFilterSetup = [=](Async<void> &async) {
|
||||
async.setConcurrentCallData(filterCurrentResults, *storage, *resultStorage,
|
||||
const auto onFilterSetup = [resultStorage](Async<void> &async) {
|
||||
async.setConcurrentCallData(filterCurrentResults, *LocatorStorage::storage(), *resultStorage,
|
||||
TextDocument::currentTextDocument()->plainText());
|
||||
};
|
||||
|
||||
const Group root {
|
||||
resultStorage,
|
||||
CurrentDocumentSymbolsRequestTask(onQuerySetup, onQueryDone, CallDoneIf::Success),
|
||||
CurrentDocumentSymbolsRequestTask({}, onQueryDone, CallDoneIf::Success),
|
||||
AsyncTask<void>(onFilterSetup)
|
||||
};
|
||||
return {root, storage};
|
||||
return root;
|
||||
}
|
||||
|
||||
LocatorMatcherTasks ClangdCurrentDocumentFilter::matchers()
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
using namespace Core;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace CMakeProjectManager::Internal {
|
||||
@@ -29,12 +30,9 @@ using BuildAcceptor = std::function<void(const BuildSystem *, const QString &)>;
|
||||
|
||||
static LocatorMatcherTasks cmakeMatchers(const BuildAcceptor &acceptor)
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage, acceptor] {
|
||||
const QString input = storage->input();
|
||||
const auto onSetup = [acceptor] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
const QString input = storage.input();
|
||||
const QRegularExpression regexp
|
||||
= ILocatorFilter::createRegExp(input, ILocatorFilter::caseSensitivity(input));
|
||||
if (!regexp.isValid())
|
||||
@@ -90,10 +88,10 @@ static LocatorMatcherTasks cmakeMatchers(const BuildAcceptor &acceptor)
|
||||
}
|
||||
}
|
||||
}
|
||||
storage->reportOutput(
|
||||
storage.reportOutput(
|
||||
std::accumulate(std::begin(entries), std::end(entries), LocatorFilterEntries()));
|
||||
};
|
||||
return {{Sync(onSetup), storage}};
|
||||
return {Sync(onSetup)};
|
||||
}
|
||||
|
||||
static void setupFilter(ILocatorFilter *filter)
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include <QtConcurrent>
|
||||
#include <QTextDocument>
|
||||
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
static const char lastTriggeredC[] = "LastTriggeredActions";
|
||||
@@ -174,11 +175,7 @@ static void matches(QPromise<void> &promise, const LocatorStorage &storage,
|
||||
|
||||
LocatorMatcherTasks ActionsFilter::matchers()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [this, storage](Async<void> &async) {
|
||||
const auto onSetup = [this](Async<void> &async) {
|
||||
m_entries.clear();
|
||||
m_indexes.clear();
|
||||
QList<const QMenu *> processedMenus;
|
||||
@@ -186,15 +183,16 @@ LocatorMatcherTasks ActionsFilter::matchers()
|
||||
for (QAction* action : menuBarActions())
|
||||
collectEntriesForAction(action, {}, processedMenus);
|
||||
collectEntriesForCommands();
|
||||
if (storage->input().simplified().isEmpty()) {
|
||||
storage->reportOutput(m_entries);
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
if (storage.input().simplified().isEmpty()) {
|
||||
storage.reportOutput(m_entries);
|
||||
return SetupResult::StopWithSuccess;
|
||||
}
|
||||
async.setConcurrentCallData(matches, *storage, m_entries);
|
||||
async.setConcurrentCallData(matches, storage, m_entries);
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
|
||||
return {{AsyncTask<void>(onSetup), storage}};
|
||||
return {AsyncTask<void>(onSetup)};
|
||||
}
|
||||
|
||||
LocatorFilterEntry::Acceptor ActionsFilter::acceptor(const ActionFilterEntryData &data) const
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include <QAction>
|
||||
#include <QPointer>
|
||||
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Core {
|
||||
@@ -25,12 +26,9 @@ CommandLocator::CommandLocator(Id id, const QString &displayName, const QString
|
||||
|
||||
LocatorMatcherTasks CommandLocator::matchers()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage, commands = m_commands] {
|
||||
const QString input = storage->input();
|
||||
const auto onSetup = [commands = m_commands] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
const QString input = storage.input();
|
||||
const Qt::CaseSensitivity inputCaseSensitivity = caseSensitivity(input);
|
||||
LocatorFilterEntries goodEntries;
|
||||
LocatorFilterEntries betterEntries;
|
||||
@@ -63,9 +61,9 @@ LocatorMatcherTasks CommandLocator::matchers()
|
||||
goodEntries.append(entry);
|
||||
}
|
||||
}
|
||||
storage->reportOutput(betterEntries + goodEntries);
|
||||
storage.reportOutput(betterEntries + goodEntries);
|
||||
};
|
||||
return {{Sync(onSetup), storage}};
|
||||
return {Sync(onSetup)};
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QMessageBox>
|
||||
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Core::Internal {
|
||||
@@ -40,12 +41,9 @@ ExecuteFilter::~ExecuteFilter()
|
||||
|
||||
LocatorMatcherTasks ExecuteFilter::matchers()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [this, storage] {
|
||||
const QString input = storage->input();
|
||||
const auto onSetup = [this] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
const QString input = storage.input();
|
||||
LocatorFilterEntries entries;
|
||||
if (!input.isEmpty()) { // avoid empty entry
|
||||
LocatorFilterEntry entry;
|
||||
@@ -69,9 +67,9 @@ LocatorMatcherTasks ExecuteFilter::matchers()
|
||||
others.append(entry);
|
||||
}
|
||||
}
|
||||
storage->reportOutput(entries + others);
|
||||
storage.reportOutput(entries + others);
|
||||
};
|
||||
return {{Sync(onSetup), storage}};
|
||||
return {Sync(onSetup)};
|
||||
}
|
||||
|
||||
void ExecuteFilter::acceptCommand(const QString &cmd)
|
||||
|
@@ -13,6 +13,8 @@
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
using namespace Tasking;
|
||||
|
||||
namespace Core::Internal {
|
||||
|
||||
ExternalToolsFilter::ExternalToolsFilter()
|
||||
@@ -27,12 +29,9 @@ ExternalToolsFilter::ExternalToolsFilter()
|
||||
|
||||
LocatorMatcherTasks ExternalToolsFilter::matchers()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage] {
|
||||
const QString input = storage->input();
|
||||
const auto onSetup = [] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
const QString input = storage.input();
|
||||
|
||||
LocatorFilterEntries bestEntries;
|
||||
LocatorFilterEntries betterEntries;
|
||||
@@ -77,10 +76,10 @@ LocatorMatcherTasks ExternalToolsFilter::matchers()
|
||||
return AcceptResult();
|
||||
};
|
||||
|
||||
storage->reportOutput(bestEntries + betterEntries + goodEntries
|
||||
storage.reportOutput(bestEntries + betterEntries + goodEntries
|
||||
+ LocatorFilterEntries{configEntry});
|
||||
};
|
||||
return {{Sync(onSetup), storage}};
|
||||
return {Sync(onSetup)};
|
||||
}
|
||||
|
||||
} // Core::Internal
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QStyle>
|
||||
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Core::Internal {
|
||||
@@ -304,17 +305,13 @@ static void matches(QPromise<void> &promise, const LocatorStorage &storage,
|
||||
|
||||
LocatorMatcherTasks FileSystemFilter::matchers()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage, includeHidden = m_includeHidden, shortcut = shortcutString()]
|
||||
const auto onSetup = [includeHidden = m_includeHidden, shortcut = shortcutString()]
|
||||
(Async<void> &async) {
|
||||
async.setConcurrentCallData(matches, *storage, shortcut,
|
||||
async.setConcurrentCallData(matches, *LocatorStorage::storage(), shortcut,
|
||||
DocumentManager::fileDialogInitialDirectory(), includeHidden);
|
||||
};
|
||||
|
||||
return {{AsyncTask<void>(onSetup), storage}};
|
||||
return {AsyncTask<void>(onSetup)};
|
||||
}
|
||||
|
||||
class FileSystemFilterOptions : public QDialog
|
||||
|
@@ -291,6 +291,14 @@ void LocatorStorage::reportOutput(const LocatorFilterEntries &outputData) const
|
||||
d->reportOutput(outputData);
|
||||
}
|
||||
|
||||
// Please note the thread_local keyword below guarantees a separate instance per thread.
|
||||
static thread_local Storage<LocatorStorage> s_locatorStorage = {};
|
||||
|
||||
Storage<LocatorStorage> &LocatorStorage::storage()
|
||||
{
|
||||
return s_locatorStorage;
|
||||
}
|
||||
|
||||
void LocatorStorage::finalize() const
|
||||
{
|
||||
QTC_ASSERT(d, return);
|
||||
@@ -366,16 +374,16 @@ void LocatorMatcher::start()
|
||||
|
||||
const auto onTaskTreeSetup = [iterator, input = d->m_input, collectorStorage](TaskTree &taskTree) {
|
||||
const std::shared_ptr<ResultsDeduplicator> deduplicator = collectorStorage->m_deduplicator;
|
||||
const Storage<LocatorStorage> storage = iterator->storage;
|
||||
const auto onSetup = [storage, input, index = iterator.iteration(), deduplicator] {
|
||||
*storage = std::make_shared<LocatorStoragePrivate>(input, index, deduplicator);
|
||||
const auto onSetup = [input, index = iterator.iteration(), deduplicator] {
|
||||
*LocatorStorage::storage()
|
||||
= std::make_shared<LocatorStoragePrivate>(input, index, deduplicator);
|
||||
};
|
||||
taskTree.setRecipe({
|
||||
finishAllAndSuccess,
|
||||
storage,
|
||||
LocatorStorage::storage(),
|
||||
onGroupSetup(onSetup),
|
||||
iterator->task,
|
||||
onGroupDone([storage] { storage->finalize(); })
|
||||
*iterator,
|
||||
onGroupDone([] { LocatorStorage::storage()->finalize(); })
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1359,10 +1367,9 @@ static void filter(QPromise<LocatorFileCachePrivate> &promise, const LocatorStor
|
||||
*/
|
||||
LocatorMatcherTask LocatorFileCache::matcher() const
|
||||
{
|
||||
Storage<LocatorStorage> storage;
|
||||
std::weak_ptr<LocatorFileCachePrivate> weak = d;
|
||||
|
||||
const auto onSetup = [storage, weak](Async<LocatorFileCachePrivate> &async) {
|
||||
const auto onSetup = [weak](Async<LocatorFileCachePrivate> &async) {
|
||||
auto that = weak.lock();
|
||||
if (!that) // LocatorMatcher is running after *this LocatorFileCache was destructed.
|
||||
return SetupResult::StopWithSuccess;
|
||||
@@ -1372,7 +1379,7 @@ LocatorMatcherTask LocatorFileCache::matcher() const
|
||||
// no provider is set or it returned empty generator
|
||||
that->bumpExecutionId();
|
||||
|
||||
async.setConcurrentCallData(&filter, *storage, *that);
|
||||
async.setConcurrentCallData(&filter, *LocatorStorage::storage(), *that);
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
const auto onDone = [weak](const Async<LocatorFileCachePrivate> &async) {
|
||||
@@ -1392,7 +1399,7 @@ LocatorMatcherTask LocatorFileCache::matcher() const
|
||||
that->update(async.result());
|
||||
};
|
||||
|
||||
return {AsyncTask<LocatorFileCachePrivate>(onSetup, onDone, CallDoneIf::Success), storage};
|
||||
return AsyncTask<LocatorFileCachePrivate>(onSetup, onDone, CallDoneIf::Success);
|
||||
}
|
||||
|
||||
} // Core
|
||||
|
@@ -126,6 +126,8 @@ public:
|
||||
LocatorStorage() = default;
|
||||
QString input() const;
|
||||
void reportOutput(const LocatorFilterEntries &outputData) const;
|
||||
// Only use it from inside the bodies of Task handlers.
|
||||
static Tasking::Storage<LocatorStorage> &storage();
|
||||
|
||||
private:
|
||||
friend class LocatorMatcher;
|
||||
@@ -134,17 +136,7 @@ private:
|
||||
std::shared_ptr<LocatorStoragePrivate> d;
|
||||
};
|
||||
|
||||
class CORE_EXPORT LocatorMatcherTask final
|
||||
{
|
||||
public:
|
||||
// The main task. Initial data (searchTerm) should be taken from storage.input().
|
||||
// Results reporting is done via the storage.reportOutput().
|
||||
Tasking::GroupItem task = Tasking::Group{};
|
||||
|
||||
// When constructing the task, don't place the storage inside the task above.
|
||||
Tasking::Storage<LocatorStorage> storage;
|
||||
};
|
||||
|
||||
using LocatorMatcherTask = Tasking::GroupItem;
|
||||
using LocatorMatcherTasks = QList<LocatorMatcherTask>;
|
||||
using LocatorMatcherTaskCreator = std::function<LocatorMatcherTasks()>;
|
||||
class LocatorMatcherPrivate;
|
||||
|
@@ -366,15 +366,15 @@ JavaScriptFilter::~JavaScriptFilter() = default;
|
||||
|
||||
LocatorMatcherTasks JavaScriptFilter::matchers()
|
||||
{
|
||||
Storage<LocatorStorage> storage;
|
||||
if (!m_javaScriptEngine)
|
||||
m_javaScriptEngine.reset(new JavaScriptEngine);
|
||||
QPointer<JavaScriptEngine> engine = m_javaScriptEngine.get();
|
||||
|
||||
const auto onSetup = [storage, engine] {
|
||||
const auto onSetup = [engine] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
if (!engine)
|
||||
return SetupResult::StopWithError;
|
||||
if (storage->input().trimmed().isEmpty()) {
|
||||
if (storage.input().trimmed().isEmpty()) {
|
||||
LocatorFilterEntry entry;
|
||||
entry.displayName = Tr::tr("Reset Engine");
|
||||
entry.acceptor = [engine] {
|
||||
@@ -385,21 +385,22 @@ LocatorMatcherTasks JavaScriptFilter::matchers()
|
||||
}
|
||||
return AcceptResult();
|
||||
};
|
||||
storage->reportOutput({entry});
|
||||
storage.reportOutput({entry});
|
||||
return SetupResult::StopWithSuccess;
|
||||
}
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
|
||||
const auto onJavaScriptSetup = [storage, engine](JavaScriptRequest &request) {
|
||||
const auto onJavaScriptSetup = [engine](JavaScriptRequest &request) {
|
||||
request.setEngine(engine);
|
||||
request.setEvaluateData(storage->input());
|
||||
request.setEvaluateData(LocatorStorage::storage()->input());
|
||||
};
|
||||
const auto onJavaScriptDone = [storage](const JavaScriptRequest &request, DoneWith result) {
|
||||
const auto onJavaScriptDone = [](const JavaScriptRequest &request, DoneWith result) {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
if (result != DoneWith::Success) {
|
||||
LocatorFilterEntry entry;
|
||||
entry.displayName = request.output().m_output;
|
||||
storage->reportOutput({entry});
|
||||
storage.reportOutput({entry});
|
||||
return;
|
||||
}
|
||||
const auto acceptor = [](const QString &clipboardContents) {
|
||||
@@ -408,7 +409,7 @@ LocatorMatcherTasks JavaScriptFilter::matchers()
|
||||
return AcceptResult();
|
||||
};
|
||||
};
|
||||
const QString input = storage->input();
|
||||
const QString input = storage.input();
|
||||
const QString output = request.output().m_output;
|
||||
const QString expression = input + " = " + output;
|
||||
|
||||
@@ -423,7 +424,7 @@ LocatorMatcherTasks JavaScriptFilter::matchers()
|
||||
copyExpressionEntry.displayName = Tr::tr("Copy to clipboard: %1").arg(expression);
|
||||
copyExpressionEntry.acceptor = acceptor(expression);
|
||||
|
||||
storage->reportOutput({entry, copyResultEntry, copyExpressionEntry});
|
||||
storage.reportOutput({entry, copyResultEntry, copyExpressionEntry});
|
||||
};
|
||||
|
||||
const Group root {
|
||||
@@ -431,7 +432,7 @@ LocatorMatcherTasks JavaScriptFilter::matchers()
|
||||
JavaScriptRequestTask(onJavaScriptSetup, onJavaScriptDone)
|
||||
};
|
||||
|
||||
return {{root, storage}};
|
||||
return {root};
|
||||
}
|
||||
|
||||
} // namespace Core::Internal
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Core::Internal {
|
||||
@@ -26,12 +27,9 @@ LocatorFiltersFilter::LocatorFiltersFilter():
|
||||
|
||||
LocatorMatcherTasks LocatorFiltersFilter::matchers()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage, icon = m_icon] {
|
||||
if (!storage->input().isEmpty())
|
||||
const auto onSetup = [icon = m_icon] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
if (!storage.input().isEmpty())
|
||||
return;
|
||||
|
||||
QMap<QString, ILocatorFilter *> uniqueFilters;
|
||||
@@ -60,9 +58,9 @@ LocatorMatcherTasks LocatorFiltersFilter::matchers()
|
||||
entries.append(entry);
|
||||
}
|
||||
}
|
||||
storage->reportOutput(entries);
|
||||
storage.reportOutput(entries);
|
||||
};
|
||||
return {{Sync(onSetup), storage}};
|
||||
return {Sync(onSetup)};
|
||||
}
|
||||
|
||||
} // Core::Internal
|
||||
|
@@ -70,15 +70,13 @@ static void matchEditors(QPromise<void> &promise, const LocatorStorage &storage,
|
||||
|
||||
LocatorMatcherTasks OpenDocumentsFilter::matchers()
|
||||
{
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage](Async<void> &async) {
|
||||
const auto onSetup = [](Async<void> &async) {
|
||||
const QList<Entry> editorsData = Utils::transform(DocumentModel::entries(),
|
||||
[](const DocumentModel::Entry *e) { return Entry{e->filePath(), e->displayName()}; });
|
||||
async.setConcurrentCallData(matchEditors, *storage, editorsData);
|
||||
async.setConcurrentCallData(matchEditors, *LocatorStorage::storage(), editorsData);
|
||||
};
|
||||
|
||||
return {{AsyncTask<void>(onSetup), storage}};
|
||||
return {AsyncTask<void>(onSetup)};
|
||||
}
|
||||
|
||||
} // namespace Core::Internal
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QRegularExpression>
|
||||
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Core::Internal {
|
||||
@@ -176,16 +177,12 @@ static void matches(QPromise<void> &promise,
|
||||
|
||||
LocatorMatcherTasks SpotlightLocatorFilter::matchers()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage,
|
||||
command = m_command,
|
||||
const auto onSetup = [command = m_command,
|
||||
insensArgs = m_arguments,
|
||||
sensArgs = m_caseSensitiveArguments,
|
||||
sortResults = m_sortResults](Async<void> &async) {
|
||||
const Link link = Link::fromString(storage->input(), true);
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
const Link link = Link::fromString(storage.input(), true);
|
||||
const FilePath input = link.targetFilePath;
|
||||
if (input.isEmpty())
|
||||
return SetupResult::StopWithSuccess;
|
||||
@@ -196,11 +193,11 @@ LocatorMatcherTasks SpotlightLocatorFilter::matchers()
|
||||
? insensArgs : sensArgs;
|
||||
const CommandLine cmd(FilePath::fromString(command), expander->expand(args),
|
||||
CommandLine::Raw);
|
||||
async.setConcurrentCallData(matches, *storage, cmd, sortResults);
|
||||
async.setConcurrentCallData(matches, storage, cmd, sortResults);
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
|
||||
return {{AsyncTask<void>(onSetup), storage}};
|
||||
return {AsyncTask<void>(onSetup)};
|
||||
}
|
||||
|
||||
bool SpotlightLocatorFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace Core {
|
||||
@@ -163,12 +164,9 @@ UrlLocatorFilter::UrlLocatorFilter(const QString &displayName, Id id)
|
||||
|
||||
LocatorMatcherTasks UrlLocatorFilter::matchers()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage, urls = remoteUrls()] {
|
||||
const QString input = storage->input();
|
||||
const auto onSetup = [urls = remoteUrls()] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
const QString input = storage.input();
|
||||
LocatorFilterEntries entries;
|
||||
for (const QString &url : urls) {
|
||||
const QString name = url.arg(input);
|
||||
@@ -182,9 +180,9 @@ LocatorMatcherTasks UrlLocatorFilter::matchers()
|
||||
entry.highlightInfo = {int(name.lastIndexOf(input)), int(input.length())};
|
||||
entries.append(entry);
|
||||
}
|
||||
storage->reportOutput(entries);
|
||||
storage.reportOutput(entries);
|
||||
};
|
||||
return {{Sync(onSetup), storage}};
|
||||
return {Sync(onSetup)};
|
||||
}
|
||||
|
||||
const char kDisplayNameKey[] = "displayName";
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
using namespace Core;
|
||||
using namespace CPlusPlus;
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace CppEditor {
|
||||
@@ -101,14 +102,10 @@ void matchesFor(QPromise<void> &promise, const LocatorStorage &storage,
|
||||
|
||||
LocatorMatcherTask locatorMatcher(IndexItem::ItemType type, const EntryFromIndex &converter)
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [=](Async<void> &async) {
|
||||
async.setConcurrentCallData(matchesFor, *storage, type, converter);
|
||||
const auto onSetup = [type, converter](Async<void> &async) {
|
||||
async.setConcurrentCallData(matchesFor, *LocatorStorage::storage(), type, converter);
|
||||
};
|
||||
return {AsyncTask<void>(onSetup), storage};
|
||||
return AsyncTask<void>(onSetup);
|
||||
}
|
||||
|
||||
LocatorMatcherTask allSymbolsMatcher()
|
||||
@@ -298,14 +295,10 @@ FilePath currentFileName()
|
||||
|
||||
LocatorMatcherTask currentDocumentMatcher()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [=](Async<void> &async) {
|
||||
async.setConcurrentCallData(matchesForCurrentDocument, *storage, currentFileName());
|
||||
const auto onSetup = [](Async<void> &async) {
|
||||
async.setConcurrentCallData(matchesForCurrentDocument, *LocatorStorage::storage(), currentFileName());
|
||||
};
|
||||
return {AsyncTask<void>(onSetup), storage};
|
||||
return AsyncTask<void>(onSetup);
|
||||
}
|
||||
|
||||
using MatcherCreator = std::function<Core::LocatorMatcherTask()>;
|
||||
|
@@ -82,9 +82,7 @@ static void matches(QPromise<QStringList> &promise, const LocatorStorage &storag
|
||||
|
||||
LocatorMatcherTasks HelpIndexFilter::matchers()
|
||||
{
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [this, storage](Async<QStringList> &async) {
|
||||
const auto onSetup = [this](Async<QStringList> &async) {
|
||||
if (m_needsUpdate) {
|
||||
m_needsUpdate = false;
|
||||
LocalHelpManager::setupGuiHelpEngine();
|
||||
@@ -92,18 +90,19 @@ LocatorMatcherTasks HelpIndexFilter::matchers()
|
||||
m_lastIndicesCache.clear();
|
||||
m_lastEntry.clear();
|
||||
}
|
||||
const QStringList cache = m_lastEntry.isEmpty() || !storage->input().contains(m_lastEntry)
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
const QStringList cache = m_lastEntry.isEmpty() || !storage.input().contains(m_lastEntry)
|
||||
? m_allIndicesCache : m_lastIndicesCache;
|
||||
async.setConcurrentCallData(matches, *storage, cache, m_icon);
|
||||
async.setConcurrentCallData(matches, storage, cache, m_icon);
|
||||
};
|
||||
const auto onDone = [this, storage](const Async<QStringList> &async) {
|
||||
const auto onDone = [this](const Async<QStringList> &async) {
|
||||
if (async.isResultAvailable()) {
|
||||
m_lastIndicesCache = async.result();
|
||||
m_lastEntry = storage->input();
|
||||
m_lastEntry = LocatorStorage::storage()->input();
|
||||
}
|
||||
};
|
||||
|
||||
return {{AsyncTask<QStringList>(onSetup, onDone, CallDoneIf::Success), storage}};
|
||||
return {AsyncTask<QStringList>(onSetup, onDone, CallDoneIf::Success)};
|
||||
}
|
||||
|
||||
void HelpIndexFilter::invalidateCache()
|
||||
|
@@ -15,6 +15,7 @@
|
||||
|
||||
using namespace Core;
|
||||
using namespace LanguageServerProtocol;
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace LanguageClient {
|
||||
@@ -44,15 +45,12 @@ void filterResults(QPromise<void> &promise, const LocatorStorage &storage, Clien
|
||||
LocatorMatcherTask locatorMatcher(Client *client, int maxResultCount,
|
||||
const QList<SymbolKind> &filter)
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
Storage<QList<SymbolInformation>> resultStorage;
|
||||
|
||||
const auto onQuerySetup = [storage, client, maxResultCount](ClientWorkspaceSymbolRequest &request) {
|
||||
const auto onQuerySetup = [client, maxResultCount](ClientWorkspaceSymbolRequest &request) {
|
||||
request.setClient(client);
|
||||
WorkspaceSymbolParams params;
|
||||
params.setQuery(storage->input());
|
||||
params.setQuery(LocatorStorage::storage()->input());
|
||||
if (maxResultCount > 0)
|
||||
params.setLimit(maxResultCount);
|
||||
request.setParams(params);
|
||||
@@ -64,11 +62,12 @@ LocatorMatcherTask locatorMatcher(Client *client, int maxResultCount,
|
||||
*resultStorage = result->toList();
|
||||
};
|
||||
|
||||
const auto onFilterSetup = [storage, resultStorage, client, filter](Async<void> &async) {
|
||||
const auto onFilterSetup = [resultStorage, client, filter](Async<void> &async) {
|
||||
const QList<SymbolInformation> results = *resultStorage;
|
||||
if (results.isEmpty())
|
||||
return SetupResult::StopWithSuccess;
|
||||
async.setConcurrentCallData(filterResults, *storage, client, results, filter);
|
||||
async.setConcurrentCallData(filterResults, *LocatorStorage::storage(), client, results,
|
||||
filter);
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
|
||||
@@ -77,7 +76,7 @@ LocatorMatcherTask locatorMatcher(Client *client, int maxResultCount,
|
||||
ClientWorkspaceSymbolRequestTask(onQuerySetup, onQueryDone, CallDoneIf::Success),
|
||||
AsyncTask<void>(onFilterSetup)
|
||||
};
|
||||
return {root, storage};
|
||||
return root;
|
||||
}
|
||||
|
||||
LocatorMatcherTask allSymbolsMatcher(Client *client, int maxResultCount)
|
||||
@@ -114,28 +113,23 @@ static void filterCurrentResults(QPromise<void> &promise, const LocatorStorage &
|
||||
|
||||
LocatorMatcherTask currentDocumentMatcher()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
Storage<CurrentDocumentSymbolsData> resultStorage;
|
||||
|
||||
const auto onQuerySetup = [](CurrentDocumentSymbolsRequest &request) {
|
||||
Q_UNUSED(request)
|
||||
};
|
||||
const auto onQueryDone = [resultStorage](const CurrentDocumentSymbolsRequest &request) {
|
||||
*resultStorage = request.currentDocumentSymbolsData();
|
||||
};
|
||||
|
||||
const auto onFilterSetup = [storage, resultStorage](Async<void> &async) {
|
||||
async.setConcurrentCallData(filterCurrentResults, *storage, *resultStorage);
|
||||
const auto onFilterSetup = [resultStorage](Async<void> &async) {
|
||||
async.setConcurrentCallData(filterCurrentResults, *LocatorStorage::storage(),
|
||||
*resultStorage);
|
||||
};
|
||||
|
||||
const Group root {
|
||||
resultStorage,
|
||||
CurrentDocumentSymbolsRequestTask(onQuerySetup, onQueryDone, CallDoneIf::Success),
|
||||
CurrentDocumentSymbolsRequestTask({}, onQueryDone, CallDoneIf::Success),
|
||||
AsyncTask<void>(onFilterSetup)
|
||||
};
|
||||
return {root, storage};
|
||||
return root;
|
||||
}
|
||||
|
||||
using MatcherCreator = std::function<Core::LocatorMatcherTask(Client *, int)>;
|
||||
|
@@ -14,6 +14,7 @@
|
||||
using namespace Core;
|
||||
using namespace Macros;
|
||||
using namespace Macros::Internal;
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
MacroLocatorFilter::MacroLocatorFilter()
|
||||
@@ -28,12 +29,9 @@ MacroLocatorFilter::MacroLocatorFilter()
|
||||
|
||||
LocatorMatcherTasks MacroLocatorFilter::matchers()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage, icon = m_icon] {
|
||||
const QString input = storage->input();
|
||||
const auto onSetup = [icon = m_icon] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
const QString input = storage.input();
|
||||
const Qt::CaseSensitivity entryCaseSensitivity = caseSensitivity(input);
|
||||
const QMap<QString, Macro *> ¯os = MacroManager::macros();
|
||||
LocatorFilterEntries goodEntries;
|
||||
@@ -69,7 +67,7 @@ LocatorMatcherTasks MacroLocatorFilter::matchers()
|
||||
goodEntries.append(filterEntry);
|
||||
}
|
||||
}
|
||||
storage->reportOutput(betterEntries + goodEntries);
|
||||
storage.reportOutput(betterEntries + goodEntries);
|
||||
};
|
||||
return {{Sync(onSetup), storage}};
|
||||
return {Sync(onSetup)};
|
||||
}
|
||||
|
@@ -4253,14 +4253,13 @@ static RunConfiguration *runConfigurationForDisplayName(const QString &displayNa
|
||||
});
|
||||
}
|
||||
|
||||
static LocatorMatcherTasks runConfigurationMatchers(const RunAcceptor &acceptor)
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage, acceptor] {
|
||||
const QString input = storage->input();
|
||||
static LocatorMatcherTasks runConfigurationMatchers(const RunAcceptor &acceptor)
|
||||
{
|
||||
const auto onSetup = [acceptor] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
const QString input = storage.input();
|
||||
const Target *target = ProjectManager::startupTarget();
|
||||
if (!target)
|
||||
return;
|
||||
@@ -4280,9 +4279,9 @@ static LocatorMatcherTasks runConfigurationMatchers(const RunAcceptor &acceptor)
|
||||
entries.append(entry);
|
||||
}
|
||||
}
|
||||
storage->reportOutput(entries);
|
||||
storage.reportOutput(entries);
|
||||
};
|
||||
return {{Sync(onSetup), storage}};
|
||||
return {Sync(onSetup)};
|
||||
}
|
||||
|
||||
static void runAcceptor(RunConfiguration *config)
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
using namespace Core;
|
||||
using namespace QmlJSTools::Internal;
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
Q_DECLARE_METATYPE(LocatorData::Entry)
|
||||
@@ -74,13 +75,9 @@ static void matches(QPromise<void> &promise, const LocatorStorage &storage,
|
||||
|
||||
LocatorMatcherTasks QmlJSFunctionsFilter::matchers()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage, entries = m_data->entries()](Async<void> &async) {
|
||||
async.setConcurrentCallData(matches, *storage, entries);
|
||||
const auto onSetup = [entries = m_data->entries()](Async<void> &async) {
|
||||
async.setConcurrentCallData(matches, *LocatorStorage::storage(), entries);
|
||||
};
|
||||
|
||||
return {{AsyncTask<void>(onSetup), storage}};
|
||||
return {AsyncTask<void>(onSetup)};
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace TextEditor::Internal {
|
||||
@@ -36,12 +37,11 @@ private:
|
||||
|
||||
LocatorMatcherTasks BookmarkFilter::matchers()
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [this, storage] { storage->reportOutput(match(storage->input())); };
|
||||
return {{Sync(onSetup), storage}};
|
||||
const auto onSetup = [this] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
storage.reportOutput(match(storage.input()));
|
||||
};
|
||||
return {Sync(onSetup)};
|
||||
}
|
||||
|
||||
LocatorFilterEntries BookmarkFilter::match(const QString &input) const
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace TextEditor::Internal {
|
||||
@@ -29,12 +30,9 @@ public:
|
||||
private:
|
||||
LocatorMatcherTasks matchers() final
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
Storage<LocatorStorage> storage;
|
||||
|
||||
const auto onSetup = [storage] {
|
||||
const QStringList lineAndColumn = storage->input().split(':');
|
||||
const auto onSetup = [] {
|
||||
const LocatorStorage &storage = *LocatorStorage::storage();
|
||||
const QStringList lineAndColumn = storage.input().split(':');
|
||||
int sectionCount = lineAndColumn.size();
|
||||
int line = 0;
|
||||
int column = 0;
|
||||
@@ -64,10 +62,10 @@ private:
|
||||
EditorManager::activateEditor(editor);
|
||||
return AcceptResult();
|
||||
};
|
||||
storage->reportOutput({entry});
|
||||
storage.reportOutput({entry});
|
||||
}
|
||||
};
|
||||
return {{Sync(onSetup), storage}};
|
||||
return {Sync(onSetup)};
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user