forked from qt-creator/qt-creator
SymbolSearcher: Flatten class hierarchy
Don't make SymbolSearcher a pure virtual class as there is only one subclass. Change-Id: I85a9d0fd3574e29620c1e6bfdb3b3421e19a4f76 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -27,12 +27,12 @@ namespace CppEditor {
|
|||||||
|
|
||||||
static Q_LOGGING_CATEGORY(indexerLog, "qtc.cppeditor.indexer", QtWarningMsg)
|
static Q_LOGGING_CATEGORY(indexerLog, "qtc.cppeditor.indexer", QtWarningMsg)
|
||||||
|
|
||||||
SymbolSearcher::SymbolSearcher(QObject *parent)
|
SymbolSearcher::SymbolSearcher(const SymbolSearcher::Parameters ¶meters,
|
||||||
: QObject(parent)
|
const QSet<QString> &fileNames)
|
||||||
{
|
: m_snapshot(CppModelManager::instance()->snapshot())
|
||||||
}
|
, m_parameters(parameters)
|
||||||
|
, m_fileNames(fileNames)
|
||||||
SymbolSearcher::~SymbolSearcher() = default;
|
{}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -241,83 +241,64 @@ void parse(QFutureInterface<void> &indexingFuture, const ParseParams params)
|
|||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
void SymbolSearcher::runSearch(QFutureInterface<Core::SearchResultItem> &future)
|
||||||
class BuiltinSymbolSearcher: public SymbolSearcher
|
|
||||||
{
|
{
|
||||||
public:
|
future.setProgressRange(0, m_snapshot.size());
|
||||||
BuiltinSymbolSearcher(const CPlusPlus::Snapshot &snapshot,
|
future.setProgressValue(0);
|
||||||
const Parameters ¶meters, const QSet<QString> &fileNames)
|
int progress = 0;
|
||||||
: m_snapshot(snapshot)
|
|
||||||
, m_parameters(parameters)
|
|
||||||
, m_fileNames(fileNames)
|
|
||||||
{}
|
|
||||||
|
|
||||||
~BuiltinSymbolSearcher() override = default;
|
SearchSymbols search;
|
||||||
|
search.setSymbolsToSearchFor(m_parameters.types);
|
||||||
|
CPlusPlus::Snapshot::const_iterator it = m_snapshot.begin();
|
||||||
|
|
||||||
void runSearch(QFutureInterface<Core::SearchResultItem> &future) override
|
QString findString = (m_parameters.flags & Core::FindRegularExpression
|
||||||
{
|
? m_parameters.text : QRegularExpression::escape(m_parameters.text));
|
||||||
future.setProgressRange(0, m_snapshot.size());
|
if (m_parameters.flags & Core::FindWholeWords)
|
||||||
future.setProgressValue(0);
|
findString = QString::fromLatin1("\\b%1\\b").arg(findString);
|
||||||
int progress = 0;
|
QRegularExpression matcher(findString, (m_parameters.flags & Core::FindCaseSensitively
|
||||||
|
? QRegularExpression::NoPatternOption
|
||||||
SearchSymbols search;
|
: QRegularExpression::CaseInsensitiveOption));
|
||||||
search.setSymbolsToSearchFor(m_parameters.types);
|
matcher.optimize();
|
||||||
CPlusPlus::Snapshot::const_iterator it = m_snapshot.begin();
|
while (it != m_snapshot.end()) {
|
||||||
|
|
||||||
QString findString = (m_parameters.flags & Core::FindRegularExpression
|
|
||||||
? m_parameters.text : QRegularExpression::escape(m_parameters.text));
|
|
||||||
if (m_parameters.flags & Core::FindWholeWords)
|
|
||||||
findString = QString::fromLatin1("\\b%1\\b").arg(findString);
|
|
||||||
QRegularExpression matcher(findString, (m_parameters.flags & Core::FindCaseSensitively
|
|
||||||
? QRegularExpression::NoPatternOption
|
|
||||||
: QRegularExpression::CaseInsensitiveOption));
|
|
||||||
matcher.optimize();
|
|
||||||
while (it != m_snapshot.end()) {
|
|
||||||
if (future.isPaused())
|
|
||||||
future.waitForResume();
|
|
||||||
if (future.isCanceled())
|
|
||||||
break;
|
|
||||||
if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->filePath().path())) {
|
|
||||||
QVector<Core::SearchResultItem> resultItems;
|
|
||||||
auto filter = [&](const IndexItem::Ptr &info) -> IndexItem::VisitorResult {
|
|
||||||
if (matcher.match(info->symbolName()).hasMatch()) {
|
|
||||||
QString text = info->symbolName();
|
|
||||||
QString scope = info->symbolScope();
|
|
||||||
if (info->type() == IndexItem::Function) {
|
|
||||||
QString name;
|
|
||||||
info->unqualifiedNameAndScope(info->symbolName(), &name, &scope);
|
|
||||||
text = name + info->symbolType();
|
|
||||||
} else if (info->type() == IndexItem::Declaration){
|
|
||||||
text = info->representDeclaration();
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::SearchResultItem item;
|
|
||||||
item.setPath(scope.split(QLatin1String("::"), Qt::SkipEmptyParts));
|
|
||||||
item.setLineText(text);
|
|
||||||
item.setIcon(info->icon());
|
|
||||||
item.setUserData(QVariant::fromValue(info));
|
|
||||||
resultItems << item;
|
|
||||||
}
|
|
||||||
|
|
||||||
return IndexItem::Recurse;
|
|
||||||
};
|
|
||||||
search(it.value())->visitAllChildren(filter);
|
|
||||||
if (!resultItems.isEmpty())
|
|
||||||
future.reportResults(resultItems);
|
|
||||||
}
|
|
||||||
++it;
|
|
||||||
++progress;
|
|
||||||
future.setProgressValue(progress);
|
|
||||||
}
|
|
||||||
if (future.isPaused())
|
if (future.isPaused())
|
||||||
future.waitForResume();
|
future.waitForResume();
|
||||||
}
|
if (future.isCanceled())
|
||||||
|
break;
|
||||||
|
if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->filePath().path())) {
|
||||||
|
QVector<Core::SearchResultItem> resultItems;
|
||||||
|
auto filter = [&](const IndexItem::Ptr &info) -> IndexItem::VisitorResult {
|
||||||
|
if (matcher.match(info->symbolName()).hasMatch()) {
|
||||||
|
QString text = info->symbolName();
|
||||||
|
QString scope = info->symbolScope();
|
||||||
|
if (info->type() == IndexItem::Function) {
|
||||||
|
QString name;
|
||||||
|
info->unqualifiedNameAndScope(info->symbolName(), &name, &scope);
|
||||||
|
text = name + info->symbolType();
|
||||||
|
} else if (info->type() == IndexItem::Declaration){
|
||||||
|
text = info->representDeclaration();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
Core::SearchResultItem item;
|
||||||
const CPlusPlus::Snapshot m_snapshot;
|
item.setPath(scope.split(QLatin1String("::"), Qt::SkipEmptyParts));
|
||||||
const Parameters m_parameters;
|
item.setLineText(text);
|
||||||
const QSet<QString> m_fileNames;
|
item.setIcon(info->icon());
|
||||||
};
|
item.setUserData(QVariant::fromValue(info));
|
||||||
|
resultItems << item;
|
||||||
|
}
|
||||||
|
|
||||||
|
return IndexItem::Recurse;
|
||||||
|
};
|
||||||
|
search(it.value())->visitAllChildren(filter);
|
||||||
|
if (!resultItems.isEmpty())
|
||||||
|
future.reportResults(resultItems);
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
++progress;
|
||||||
|
future.setProgressValue(progress);
|
||||||
|
}
|
||||||
|
if (future.isPaused())
|
||||||
|
future.waitForResume();
|
||||||
|
}
|
||||||
|
|
||||||
CppIndexingSupport::CppIndexingSupport()
|
CppIndexingSupport::CppIndexingSupport()
|
||||||
{
|
{
|
||||||
@@ -356,7 +337,7 @@ QFuture<void> CppIndexingSupport::refreshSourceFiles(const QSet<QString> &source
|
|||||||
SymbolSearcher *CppIndexingSupport::createSymbolSearcher(
|
SymbolSearcher *CppIndexingSupport::createSymbolSearcher(
|
||||||
const SymbolSearcher::Parameters ¶meters, const QSet<QString> &fileNames)
|
const SymbolSearcher::Parameters ¶meters, const QSet<QString> &fileNames)
|
||||||
{
|
{
|
||||||
return new BuiltinSymbolSearcher(CppModelManager::instance()->snapshot(), parameters, fileNames);
|
return new SymbolSearcher(parameters, fileNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
@@ -7,11 +7,9 @@
|
|||||||
|
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
|
|
||||||
#include <coreplugin/find/textfindconstants.h>
|
|
||||||
#include <utils/futuresynchronizer.h>
|
#include <utils/futuresynchronizer.h>
|
||||||
|
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
namespace Core { class SearchResultItem; }
|
namespace Core { class SearchResultItem; }
|
||||||
|
|
||||||
@@ -45,11 +43,13 @@ public:
|
|||||||
SearchScope scope;
|
SearchScope scope;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SymbolSearcher(const SymbolSearcher::Parameters ¶meters, const QSet<QString> &fileNames);
|
||||||
|
void runSearch(QFutureInterface<Core::SearchResultItem> &future);
|
||||||
|
|
||||||
public:
|
private:
|
||||||
SymbolSearcher(QObject *parent = nullptr);
|
const CPlusPlus::Snapshot m_snapshot;
|
||||||
~SymbolSearcher() override = 0;
|
const Parameters m_parameters;
|
||||||
virtual void runSearch(QFutureInterface<Core::SearchResultItem> &future) = 0;
|
const QSet<QString> m_fileNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPPEDITOR_EXPORT CppIndexingSupport
|
class CPPEDITOR_EXPORT CppIndexingSupport
|
||||||
|
Reference in New Issue
Block a user