diff --git a/src/plugins/coreplugin/locator/opendocumentsfilter.cpp b/src/plugins/coreplugin/locator/opendocumentsfilter.cpp index aa94c5f5f58..4a510ad83f7 100644 --- a/src/plugins/coreplugin/locator/opendocumentsfilter.cpp +++ b/src/plugins/coreplugin/locator/opendocumentsfilter.cpp @@ -3,11 +3,13 @@ #include "opendocumentsfilter.h" +#include "../coreplugin.h" #include "../coreplugintr.h" +#include +#include #include #include -#include #include #include @@ -25,6 +27,7 @@ OpenDocumentsFilter::OpenDocumentsFilter() setDefaultShortcutString("o"); setPriority(High); setDefaultIncludedByDefault(true); + // TODO: Remove the refresh recipe setRefreshRecipe(Tasking::Sync([this] { refreshInternally(); return true; })); connect(DocumentModel::model(), &QAbstractItemModel::dataChanged, @@ -35,6 +38,56 @@ OpenDocumentsFilter::OpenDocumentsFilter() this, &OpenDocumentsFilter::slotRowsRemoved); } +static void matchEditors(QPromise &promise, const LocatorStorage &storage, + const QList &editorsData) +{ + const Link link = Link::fromString(storage.input(), true); + const QRegularExpression regexp = ILocatorFilter::createRegExp(link.targetFilePath.toString()); + if (!regexp.isValid()) + return; + + LocatorFilterEntries goodEntries; + LocatorFilterEntries betterEntries; + + for (const OpenDocumentsFilter::Entry &editorData : editorsData) { + if (promise.isCanceled()) + return; + if (editorData.fileName.isEmpty()) + continue; + const QRegularExpressionMatch match = regexp.match(editorData.displayName); + if (match.hasMatch()) { + LocatorFilterEntry filterEntry; + filterEntry.displayName = editorData.displayName; + filterEntry.filePath = editorData.fileName; + filterEntry.extraInfo = filterEntry.filePath.shortNativePath(); + filterEntry.highlightInfo = ILocatorFilter::highlightInfo(match); + filterEntry.linkForEditor = Link(filterEntry.filePath, link.targetLine, + link.targetColumn); + if (match.capturedStart() == 0) + betterEntries.append(filterEntry); + else + goodEntries.append(filterEntry); + } + } + storage.reportOutput(betterEntries + goodEntries); +} + +LocatorMatcherTasks OpenDocumentsFilter::matchers() +{ + using namespace Tasking; + + TreeStorage storage; + + const auto onSetup = [storage](AsyncTask &async) { + const QList editorsData = Utils::transform(DocumentModel::entries(), + [](const DocumentModel::Entry *e) { return Entry{e->filePath(), e->displayName()}; }); + async.setFutureSynchronizer(CorePlugin::futureSynchronizer()); + async.setConcurrentCallData(matchEditors, *storage, editorsData); + }; + + return {{Async(onSetup), storage}}; +} + void OpenDocumentsFilter::slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { diff --git a/src/plugins/coreplugin/locator/opendocumentsfilter.h b/src/plugins/coreplugin/locator/opendocumentsfilter.h index 7bbd98698fa..c75c4da1db7 100644 --- a/src/plugins/coreplugin/locator/opendocumentsfilter.h +++ b/src/plugins/coreplugin/locator/opendocumentsfilter.h @@ -20,13 +20,7 @@ public: OpenDocumentsFilter(); QList matchesFor(QFutureInterface &future, const QString &entry) override; -public slots: - void slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, - const QVector &roles); - void slotRowsInserted(const QModelIndex &, int first, int last); - void slotRowsRemoved(const QModelIndex &, int first, int last); - -private: + // TODO: Move to cpp when matchesFor() is removed class Entry { public: @@ -34,6 +28,14 @@ private: QString displayName; }; +public slots: + void slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, + const QVector &roles); + void slotRowsInserted(const QModelIndex &, int first, int last); + void slotRowsRemoved(const QModelIndex &, int first, int last); + +private: + LocatorMatcherTasks matchers() final; QList editors() const; void refreshInternally();