diff --git a/src/plugins/cpptools/ModelManagerInterface.h b/src/plugins/cpptools/ModelManagerInterface.h index 4bb9aac7296d0338f391cdc9b5b871b987db0471..d4d1c9a0120d484ca1e5e65499214ce62a333ad4 100644 --- a/src/plugins/cpptools/ModelManagerInterface.h +++ b/src/plugins/cpptools/ModelManagerInterface.h @@ -221,7 +221,8 @@ public: virtual CppTools::CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0; virtual void setHighlightingSupportFactory(CppTools::CppHighlightingSupportFactory *highlightingFactory) = 0; - virtual void addIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0; + virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0; + virtual CppTools::CppIndexingSupport *indexingSupport() = 0; Q_SIGNALS: void documentUpdated(CPlusPlus::Document::Ptr doc); diff --git a/src/plugins/cpptools/builtinindexingsupport.cpp b/src/plugins/cpptools/builtinindexingsupport.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb03a799fb4aaa0fd08de16031b5e3b1858c06ac --- /dev/null +++ b/src/plugins/cpptools/builtinindexingsupport.cpp @@ -0,0 +1,216 @@ +#include "builtinindexingsupport.h" +#include "cppmodelmanager.h" +#include "searchsymbols.h" + +#include <coreplugin/icore.h> +#include <coreplugin/mimedatabase.h> +#include <coreplugin/progressmanager/progressmanager.h> +#include <utils/runextensions.h> + +#include <QCoreApplication> + +using namespace CppTools; +using namespace CppTools::Internal; + +namespace { + +static void parse(QFutureInterface<void> &future, + CppPreprocessor *preproc, + QStringList files, + const char *pp_configuration_file) +{ + if (files.isEmpty()) + return; + + const Core::MimeDatabase *mimeDb = Core::ICore::mimeDatabase(); + Core::MimeType cSourceTy = mimeDb->findByType(QLatin1String("text/x-csrc")); + Core::MimeType cppSourceTy = mimeDb->findByType(QLatin1String("text/x-c++src")); + Core::MimeType mSourceTy = mimeDb->findByType(QLatin1String("text/x-objcsrc")); + + QStringList sources; + QStringList headers; + + QStringList suffixes = cSourceTy.suffixes(); + suffixes += cppSourceTy.suffixes(); + suffixes += mSourceTy.suffixes(); + + foreach (const QString &file, files) { + QFileInfo info(file); + + preproc->snapshot.remove(file); + + if (suffixes.contains(info.suffix())) + sources.append(file); + else + headers.append(file); + } + + const int sourceCount = sources.size(); + files = sources; + files += headers; + + preproc->setTodo(files); + + future.setProgressRange(0, files.size()); + + QString conf = QLatin1String(pp_configuration_file); + + bool processingHeaders = false; + + for (int i = 0; i < files.size(); ++i) { + if (future.isPaused()) + future.waitForResume(); + + if (future.isCanceled()) + break; + + const QString fileName = files.at(i); + + const bool isSourceFile = i < sourceCount; + if (isSourceFile) + (void) preproc->run(conf); + + else if (! processingHeaders) { + (void) preproc->run(conf); + + processingHeaders = true; + } + + preproc->run(fileName); + + future.setProgressValue(files.size() - preproc->todo().size()); + + if (isSourceFile) + preproc->resetEnvironment(); + } + + future.setProgressValue(files.size()); + preproc->modelManager()->finishedRefreshingSourceFiles(files); + + delete preproc; +} + +class BuiltinSymbolSearcher: public SymbolSearcher +{ +public: + BuiltinSymbolSearcher(const CPlusPlus::Snapshot &snapshot, + Parameters parameters, QSet<QString> fileNames) + : m_snapshot(snapshot) + , m_parameters(parameters) + , m_fileNames(fileNames) + {} + + ~BuiltinSymbolSearcher() + {} + + void runSearch(QFutureInterface<Find::SearchResultItem> &future) + { + future.setProgressRange(0, m_snapshot.size()); + future.setProgressValue(0); + int progress = 0; + + SearchSymbols search; + search.setSymbolsToSearchFor(m_parameters.types); + search.setSeparateScope(true); + CPlusPlus::Snapshot::const_iterator it = m_snapshot.begin(); + + QString findString = (m_parameters.flags & Find::FindRegularExpression + ? m_parameters.text : QRegExp::escape(m_parameters.text)); + if (m_parameters.flags & Find::FindWholeWords) + findString = QString::fromLatin1("\\b%1\\b").arg(findString); + QRegExp matcher(findString, (m_parameters.flags & Find::FindCaseSensitively + ? Qt::CaseSensitive : Qt::CaseInsensitive)); + while (it != m_snapshot.end()) { + if (future.isPaused()) + future.waitForResume(); + if (future.isCanceled()) + break; + if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->fileName())) { + QVector<Find::SearchResultItem> resultItems; + QList<ModelItemInfo> modelInfos = search(it.value()); + foreach (const ModelItemInfo &info, modelInfos) { + int index = matcher.indexIn(info.symbolName); + if (index != -1) { + QStringList path = info.fullyQualifiedName.mid(0, + info.fullyQualifiedName.size() - 1); + Find::SearchResultItem item; + item.path = path; + item.text = info.symbolName; + item.textMarkPos = -1; + item.textMarkLength = 0; + item.icon = info.icon; + item.lineNumber = -1; + item.userData = qVariantFromValue(info); + resultItems << item; + } + } + if (!resultItems.isEmpty()) + future.reportResults(resultItems); + } + ++it; + ++progress; + future.setProgressValue(progress); + } + if (future.isPaused()) + future.waitForResume(); + } + +private: + const CPlusPlus::Snapshot m_snapshot; + const Parameters m_parameters; + const QSet<QString> m_fileNames; +}; + +} // anonymous namespace + +BuiltinIndexingSupport::BuiltinIndexingSupport(const char *pp_configuration_file) + : m_pp_configuration_file(pp_configuration_file) + , m_revision(0) +{ + m_synchronizer.setCancelOnWait(true); + m_dumpFileNameWhileParsing = !qgetenv("QTCREATOR_DUMP_FILENAME_WHILE_PARSING").isNull(); +} + +BuiltinIndexingSupport::~BuiltinIndexingSupport() +{} + +QFuture<void> BuiltinIndexingSupport::refreshSourceFiles(const QStringList &sourceFiles) +{ + CppModelManager *mgr = CppModelManager::instance(); + const WorkingCopy workingCopy = mgr->workingCopy(); + + CppPreprocessor *preproc = new CppPreprocessor(mgr, m_dumpFileNameWhileParsing); + preproc->setRevision(++m_revision); + preproc->setProjectFiles(mgr->projectFiles()); + preproc->setIncludePaths(mgr->includePaths()); + preproc->setFrameworkPaths(mgr->frameworkPaths()); + preproc->setWorkingCopy(workingCopy); + + QFuture<void> result = QtConcurrent::run(&parse, preproc, sourceFiles, m_pp_configuration_file); + + if (m_synchronizer.futures().size() > 10) { + QList<QFuture<void> > futures = m_synchronizer.futures(); + + m_synchronizer.clearFutures(); + + foreach (const QFuture<void> &future, futures) { + if (! (future.isFinished() || future.isCanceled())) + m_synchronizer.addFuture(future); + } + } + + m_synchronizer.addFuture(result); + + if (sourceFiles.count() > 1) { + Core::ICore::progressManager()->addTask(result, + QCoreApplication::translate("IndexingSupport", "Parsing"), + QLatin1String(CppTools::Constants::TASK_INDEX)); + } + + return result; +} + +SymbolSearcher *BuiltinIndexingSupport::createSymbolSearcher(SymbolSearcher::Parameters parameters, QSet<QString> fileNames) +{ + return new BuiltinSymbolSearcher(CppModelManager::instance()->snapshot(), parameters, fileNames); +} diff --git a/src/plugins/cpptools/builtinindexingsupport.h b/src/plugins/cpptools/builtinindexingsupport.h new file mode 100644 index 0000000000000000000000000000000000000000..cb3f9d5022bb3223637595ff1b5f9413d593ed87 --- /dev/null +++ b/src/plugins/cpptools/builtinindexingsupport.h @@ -0,0 +1,33 @@ +#ifndef BUILTININDEXINGSUPPORT_H +#define BUILTININDEXINGSUPPORT_H + +#include "cppindexingsupport.h" +#include "ModelManagerInterface.h" + +#include <QFutureSynchronizer> + +namespace CppTools { +namespace Internal { + +class BuiltinIndexingSupport: public CppIndexingSupport { +public: + typedef CPlusPlus::CppModelManagerInterface::WorkingCopy WorkingCopy; + +public: + BuiltinIndexingSupport(const char *m_pp_configuration_file); + ~BuiltinIndexingSupport(); + + virtual QFuture<void> refreshSourceFiles(const QStringList &sourceFiles); + virtual SymbolSearcher *createSymbolSearcher(SymbolSearcher::Parameters parameters, QSet<QString> fileNames); + +private: + const char *m_pp_configuration_file; + QFutureSynchronizer<void> m_synchronizer; + unsigned m_revision; + bool m_dumpFileNameWhileParsing; +}; + +} // namespace Internal +} // namespace CppTools + +#endif // BUILTININDEXINGSUPPORT_H diff --git a/src/plugins/cpptools/cppclassesfilter.cpp b/src/plugins/cpptools/cppclassesfilter.cpp index a66024377fc8cf522088c7e6c4273fbeefb9ca81..bef718bd8bc22cb7d025bcd4fe32a8383e148607 100644 --- a/src/plugins/cpptools/cppclassesfilter.cpp +++ b/src/plugins/cpptools/cppclassesfilter.cpp @@ -38,7 +38,7 @@ CppClassesFilter::CppClassesFilter(CppModelManager *manager) setShortcutString(QLatin1String("c")); setIncludedByDefault(false); - search.setSymbolsToSearchFor(SearchSymbols::Classes); + search.setSymbolsToSearchFor(SymbolSearcher::Classes); search.setSeparateScope(true); } diff --git a/src/plugins/cpptools/cppcurrentdocumentfilter.cpp b/src/plugins/cpptools/cppcurrentdocumentfilter.cpp index d06fe6a8397e175b52630764a6fd2cc43373f072..867ab9e8e545c41bdc7f58bdacb26bf86147fddb 100644 --- a/src/plugins/cpptools/cppcurrentdocumentfilter.cpp +++ b/src/plugins/cpptools/cppcurrentdocumentfilter.cpp @@ -43,10 +43,10 @@ CppCurrentDocumentFilter::CppCurrentDocumentFilter(CppModelManager *manager, Cor setShortcutString(QString(QLatin1Char('.'))); setIncludedByDefault(false); - search.setSymbolsToSearchFor(SearchSymbols::Declarations | - SearchSymbols::Enums | - SearchSymbols::Functions | - SearchSymbols::Classes); + search.setSymbolsToSearchFor(SymbolSearcher::Declarations | + SymbolSearcher::Enums | + SymbolSearcher::Functions | + SymbolSearcher::Classes); search.setSeparateScope(true); diff --git a/src/plugins/cpptools/cppfunctionsfilter.cpp b/src/plugins/cpptools/cppfunctionsfilter.cpp index b47c870115a5206f078f513900c4ceffaa6e3153..138a1ed65f960397aacb6bbad2d62eb6fb4f1c53 100644 --- a/src/plugins/cpptools/cppfunctionsfilter.cpp +++ b/src/plugins/cpptools/cppfunctionsfilter.cpp @@ -37,7 +37,7 @@ CppFunctionsFilter::CppFunctionsFilter(CppModelManager *manager) setShortcutString(QString(QLatin1Char('m'))); setIncludedByDefault(false); - search.setSymbolsToSearchFor(SearchSymbols::Functions); + search.setSymbolsToSearchFor(SymbolSearcher::Functions); search.setSeparateScope(true); } diff --git a/src/plugins/cpptools/cppindexingsupport.cpp b/src/plugins/cpptools/cppindexingsupport.cpp index 475e9aefff806b0cc326c62a9bbda9932887cfd7..e7d118d283e7f770727d6b60b0efa0667ef78edd 100644 --- a/src/plugins/cpptools/cppindexingsupport.cpp +++ b/src/plugins/cpptools/cppindexingsupport.cpp @@ -36,4 +36,12 @@ CppIndexingSupport::~CppIndexingSupport() { } +SymbolSearcher::SymbolSearcher(QObject *parent) + : QObject(parent) +{ +} + +SymbolSearcher::~SymbolSearcher() +{} + } // namespace CppTools diff --git a/src/plugins/cpptools/cppindexingsupport.h b/src/plugins/cpptools/cppindexingsupport.h index 0740ace5e4c066609fe5af6b20dc0aeb81919379..6766fb2de9fa954803d439f0a74836460c9665ad 100644 --- a/src/plugins/cpptools/cppindexingsupport.h +++ b/src/plugins/cpptools/cppindexingsupport.h @@ -32,19 +32,62 @@ #include "cpptools_global.h" +#include <find/searchresultwindow.h> +#include <find/textfindconstants.h> + #include <QFuture> #include <QStringList> namespace CppTools { +class SymbolSearcher: public QObject +{ + Q_OBJECT + +public: + enum SymbolType { + Classes = 0x1, + Functions = 0x2, + Enums = 0x4, + Declarations = 0x8 + }; + + Q_DECLARE_FLAGS(SymbolTypes, SymbolType) + + enum SearchScope { + SearchProjectsOnly, + SearchGlobal + }; + + struct Parameters + { + QString text; + Find::FindFlags flags; + SymbolTypes types; + SearchScope scope; + }; + + +public: + SymbolSearcher(QObject *parent = 0); + virtual ~SymbolSearcher() = 0; + virtual void runSearch(QFutureInterface<Find::SearchResultItem> &future) = 0; +}; + + class CPPTOOLS_EXPORT CppIndexingSupport { public: virtual ~CppIndexingSupport() = 0; virtual QFuture<void> refreshSourceFiles(const QStringList &sourceFiles) = 0; + virtual SymbolSearcher *createSymbolSearcher(SymbolSearcher::Parameters parameters, QSet<QString> fileNames) = 0; }; } // namespace CppTools +Q_DECLARE_METATYPE(CppTools::SymbolSearcher::SearchScope) +Q_DECLARE_METATYPE(CppTools::SymbolSearcher::Parameters) +Q_DECLARE_METATYPE(CppTools::SymbolSearcher::SymbolTypes) + #endif // CPPTOOLS_CPPINDEXINGSUPPORT_H diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index b01c8ae4207f0bde8c0eeef48b90625e282189d7..f56b5a35b7d022703733d05037ab96f29a8f8888 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -30,6 +30,7 @@ #include <cplusplus/pp.h> #include <cplusplus/Overview.h> +#include "builtinindexingsupport.h" #include "cppmodelmanager.h" #include "cppcompletionassist.h" #include "cpphighlightingsupport.h" @@ -662,144 +663,6 @@ void CppModelManager::updateModifiedSourceFiles() updateSourceFiles(sourceFiles); } -namespace { - -class IndexingSupport: public CppIndexingSupport { -public: - typedef CppModelManagerInterface::WorkingCopy WorkingCopy; - -public: - IndexingSupport() - : m_revision(0) - { - m_synchronizer.setCancelOnWait(true); - m_dumpFileNameWhileParsing = !qgetenv("QTCREATOR_DUMP_FILENAME_WHILE_PARSING").isNull(); - } - - ~IndexingSupport() - {} - - QFuture<void> refreshSourceFiles(const QStringList &sourceFiles) - { - CppModelManager *mgr = CppModelManager::instance(); - const WorkingCopy workingCopy = mgr->workingCopy(); - - CppPreprocessor *preproc = new CppPreprocessor(mgr, m_dumpFileNameWhileParsing); - preproc->setRevision(++m_revision); - preproc->setProjectFiles(mgr->projectFiles()); - preproc->setIncludePaths(mgr->includePaths()); - preproc->setFrameworkPaths(mgr->frameworkPaths()); - preproc->setWorkingCopy(workingCopy); - - QFuture<void> result = QtConcurrent::run(&parse, preproc, sourceFiles); - - if (m_synchronizer.futures().size() > 10) { - QList<QFuture<void> > futures = m_synchronizer.futures(); - - m_synchronizer.clearFutures(); - - foreach (const QFuture<void> &future, futures) { - if (! (future.isFinished() || future.isCanceled())) - m_synchronizer.addFuture(future); - } - } - - m_synchronizer.addFuture(result); - - if (sourceFiles.count() > 1) { - Core::ICore::progressManager()->addTask(result, - QCoreApplication::translate("IndexingSupport", "Parsing"), - QLatin1String(CppTools::Constants::TASK_INDEX)); - } - - return result; - } - -private: - static void parse(QFutureInterface<void> &future, - CppPreprocessor *preproc, - QStringList files) - { - if (files.isEmpty()) - return; - - const Core::MimeDatabase *mimeDb = Core::ICore::mimeDatabase(); - Core::MimeType cSourceTy = mimeDb->findByType(QLatin1String("text/x-csrc")); - Core::MimeType cppSourceTy = mimeDb->findByType(QLatin1String("text/x-c++src")); - Core::MimeType mSourceTy = mimeDb->findByType(QLatin1String("text/x-objcsrc")); - - QStringList sources; - QStringList headers; - - QStringList suffixes = cSourceTy.suffixes(); - suffixes += cppSourceTy.suffixes(); - suffixes += mSourceTy.suffixes(); - - foreach (const QString &file, files) { - QFileInfo info(file); - - preproc->snapshot.remove(file); - - if (suffixes.contains(info.suffix())) - sources.append(file); - else - headers.append(file); - } - - const int sourceCount = sources.size(); - files = sources; - files += headers; - - preproc->setTodo(files); - - future.setProgressRange(0, files.size()); - - QString conf = QLatin1String(pp_configuration_file); - - bool processingHeaders = false; - - for (int i = 0; i < files.size(); ++i) { - if (future.isPaused()) - future.waitForResume(); - - if (future.isCanceled()) - break; - - const QString fileName = files.at(i); - - const bool isSourceFile = i < sourceCount; - if (isSourceFile) - (void) preproc->run(conf); - - else if (! processingHeaders) { - (void) preproc->run(conf); - - processingHeaders = true; - } - - preproc->run(fileName); - - future.setProgressValue(files.size() - preproc->todo().size()); - - if (isSourceFile) - preproc->resetEnvironment(); - } - - future.setProgressValue(files.size()); - preproc->modelManager()->finishedRefreshingSourceFiles(files); - - delete preproc; - } - -private: - QFutureSynchronizer<void> m_synchronizer; - unsigned m_revision; - bool m_dumpFileNameWhileParsing; -}; - - -} // anonymous namespace - /*! \class CppTools::CppModelManager \brief The CppModelManager keeps track of one CppCodeModel instance @@ -825,6 +688,9 @@ CppModelManager *CppModelManager::instance() CppModelManager::CppModelManager(QObject *parent) : CppModelManagerInterface(parent) + , m_completionAssistProvider(0) + , m_highlightingFactory(0) + , m_indexingSupporter(0) { m_findReferences = new CppFindReferences(this); m_indexerEnabled = qgetenv("QTCREATOR_NO_CODE_INDEXER").isNull(); @@ -872,7 +738,7 @@ CppModelManager::CppModelManager(QObject *parent) ExtensionSystem::PluginManager::addObject(m_completionAssistProvider); m_highlightingFallback = new CppHighlightingSupportInternalFactory; m_highlightingFactory = m_highlightingFallback; - m_internalIndexingSupport = new IndexingSupport; + m_internalIndexingSupport = new BuiltinIndexingSupport(pp_configuration_file); } CppModelManager::~CppModelManager() @@ -1073,9 +939,8 @@ QFuture<void> CppModelManager::updateSourceFiles(const QStringList &sourceFiles) if (sourceFiles.isEmpty() || !m_indexerEnabled) return QFuture<void>(); - foreach (CppIndexingSupport *indexer, m_indexingSupporters) - indexer->refreshSourceFiles(sourceFiles); - + if (m_indexingSupporter) + m_indexingSupporter->refreshSourceFiles(sourceFiles); return m_internalIndexingSupport->refreshSourceFiles(sourceFiles); } @@ -1450,10 +1315,15 @@ void CppModelManager::setHighlightingSupportFactory(CppHighlightingSupportFactor m_highlightingFactory = m_highlightingFallback; } -void CppModelManager::addIndexingSupport(CppIndexingSupport *indexingSupport) +void CppModelManager::setIndexingSupport(CppIndexingSupport *indexingSupport) { if (indexingSupport) - m_indexingSupporters.append(indexingSupport); + m_indexingSupporter = indexingSupport; +} + +CppIndexingSupport *CppModelManager::indexingSupport() +{ + return m_indexingSupporter ? m_indexingSupporter : m_internalIndexingSupport; } void CppModelManager::setExtraDiagnostics(const QString &fileName, int kind, diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index fdc06e8bc04b8cb8e91cba8d5e37099025b71042..557d1ffa6a94c9273654f2f3a76d126ee0557b67 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -131,7 +131,8 @@ public: virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const; virtual void setHighlightingSupportFactory(CppHighlightingSupportFactory *highlightingFactory); - virtual void addIndexingSupport(CppIndexingSupport *indexingSupport); + virtual void setIndexingSupport(CppIndexingSupport *indexingSupport); + virtual CppIndexingSupport *indexingSupport(); QStringList projectFiles() { @@ -243,7 +244,7 @@ private: CppCompletionAssistProvider *m_completionFallback; CppHighlightingSupportFactory *m_highlightingFactory; CppHighlightingSupportFactory *m_highlightingFallback; - QList<CppIndexingSupport *> m_indexingSupporters; + CppIndexingSupport *m_indexingSupporter; CppIndexingSupport *m_internalIndexingSupport; }; diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 7c49e5e521d7e9637799af18175c5c845bb0aa43..5cb5f21749105eadf149c284f5f68cbfe565ae64 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -47,7 +47,8 @@ HEADERS += completionsettingspage.h \ cppcompletionassistprovider.h \ ModelManagerInterface.h \ TypeHierarchyBuilder.h \ - cppindexingsupport.h + cppindexingsupport.h \ + builtinindexingsupport.h SOURCES += completionsettingspage.cpp \ cppclassesfilter.cpp \ @@ -87,7 +88,8 @@ SOURCES += completionsettingspage.cpp \ cppcompletionassistprovider.cpp \ ModelManagerInterface.cpp \ TypeHierarchyBuilder.cpp \ - cppindexingsupport.cpp + cppindexingsupport.cpp \ + builtinindexingsupport.cpp FORMS += completionsettingspage.ui \ cppfilesettingspage.ui \ diff --git a/src/plugins/cpptools/searchsymbols.cpp b/src/plugins/cpptools/searchsymbols.cpp index d710c968f7d31414af2ec2e8e69545ab9f1c9ccf..75976b42a60e7ff678e0f40b904cbf515392378b 100644 --- a/src/plugins/cpptools/searchsymbols.cpp +++ b/src/plugins/cpptools/searchsymbols.cpp @@ -39,13 +39,13 @@ using namespace CPlusPlus; using namespace CppTools; SearchSymbols::SymbolTypes SearchSymbols::AllTypes = - SearchSymbols::Classes - | SearchSymbols::Functions - | SearchSymbols::Enums - | SearchSymbols::Declarations; + SymbolSearcher::Classes + | SymbolSearcher::Functions + | SymbolSearcher::Enums + | SymbolSearcher::Declarations; SearchSymbols::SearchSymbols(): - symbolsToSearchFor(Classes | Functions | Enums), + symbolsToSearchFor(SymbolSearcher::Classes | SymbolSearcher::Functions | SymbolSearcher::Enums), separateScope(false) { } @@ -84,7 +84,7 @@ QString SearchSymbols::switchScope(const QString &scope) bool SearchSymbols::visit(Enum *symbol) { - if (!(symbolsToSearchFor & Enums)) + if (!(symbolsToSearchFor & SymbolSearcher::Enums)) return false; QString name = symbolName(symbol); @@ -102,7 +102,7 @@ bool SearchSymbols::visit(Enum *symbol) bool SearchSymbols::visit(Function *symbol) { - if (!(symbolsToSearchFor & Functions)) + if (!(symbolsToSearchFor & SymbolSearcher::Functions)) return false; QString extraScope; @@ -139,7 +139,7 @@ bool SearchSymbols::visit(Namespace *symbol) bool SearchSymbols::visit(Declaration *symbol) { - if (!(symbolsToSearchFor & Declarations)) + if (!(symbolsToSearchFor & SymbolSearcher::Declarations)) return false; QString name = symbolName(symbol); @@ -157,7 +157,7 @@ bool SearchSymbols::visit(Class *symbol) QString name = symbolName(symbol); QString scopedName = scopedSymbolName(name); QString previousScope = switchScope(scopedName); - if (symbolsToSearchFor & Classes) { + if (symbolsToSearchFor & SymbolSearcher::Classes) { appendItem(separateScope ? name : scopedName, separateScope ? previousScope : QString(), ModelItemInfo::Class, symbol); diff --git a/src/plugins/cpptools/searchsymbols.h b/src/plugins/cpptools/searchsymbols.h index aaf77bfa456122fcd22dd6ed0f6737c97cb9f6a3..dae0ebe03752106d10d2d7b9203f66656ab5d2c9 100644 --- a/src/plugins/cpptools/searchsymbols.h +++ b/src/plugins/cpptools/searchsymbols.h @@ -32,6 +32,8 @@ #include "cpptools_global.h" +#include "cppindexingsupport.h" + #include <cplusplus/CppDocument.h> #include <cplusplus/Icons.h> #include <cplusplus/Overview.h> @@ -101,14 +103,7 @@ class SearchSymbols: public std::unary_function<CPlusPlus::Document::Ptr, QList< protected CPlusPlus::SymbolVisitor { public: - enum SymbolType { - Classes = 0x1, - Functions = 0x2, - Enums = 0x4, - Declarations = 0x8 - }; - - Q_DECLARE_FLAGS(SymbolTypes, SymbolType) + typedef SymbolSearcher::SymbolTypes SymbolTypes; static SymbolTypes AllTypes; @@ -181,7 +176,6 @@ private: } // namespace CppTools Q_DECLARE_OPERATORS_FOR_FLAGS(CppTools::SearchSymbols::SymbolTypes) -Q_DECLARE_METATYPE(CppTools::SearchSymbols::SymbolTypes) Q_DECLARE_METATYPE(CppTools::ModelItemInfo) #endif // SEARCHSYMBOLS_H diff --git a/src/plugins/cpptools/symbolsfindfilter.cpp b/src/plugins/cpptools/symbolsfindfilter.cpp index 2ea320ef46dcf5ece1b3226887acf4107cd10a9c..e102d0e619b751d202d40f343299a5bda5c39978 100644 --- a/src/plugins/cpptools/symbolsfindfilter.cpp +++ b/src/plugins/cpptools/symbolsfindfilter.cpp @@ -55,67 +55,13 @@ namespace { const char * const SETTINGS_GROUP = "CppSymbols"; const char * const SETTINGS_SYMBOLTYPES = "SymbolsToSearchFor"; const char * const SETTINGS_SEARCHSCOPE = "SearchScope"; - - void runSearch(QFutureInterface<Find::SearchResultItem> &future, - SymbolsFindParameters parameters, CPlusPlus::Snapshot snapshot, - QSet<QString> fileNames) - { - future.setProgressRange(0, snapshot.size()); - future.setProgressValue(0); - int progress = 0; - - SearchSymbols search; - search.setSymbolsToSearchFor(parameters.types); - search.setSeparateScope(true); - CPlusPlus::Snapshot::const_iterator it = snapshot.begin(); - - QString findString = (parameters.flags & Find::FindRegularExpression - ? parameters.text : QRegExp::escape(parameters.text)); - if (parameters.flags & Find::FindWholeWords) - findString = QString::fromLatin1("\\b%1\\b").arg(findString); - QRegExp matcher(findString, (parameters.flags & Find::FindCaseSensitively - ? Qt::CaseSensitive : Qt::CaseInsensitive)); - while (it != snapshot.end()) { - if (future.isPaused()) - future.waitForResume(); - if (future.isCanceled()) - break; - if (fileNames.isEmpty() || fileNames.contains(it.value()->fileName())) { - QVector<Find::SearchResultItem> resultItems; - QList<ModelItemInfo> modelInfos = search(it.value()); - foreach (const ModelItemInfo &info, modelInfos) { - int index = matcher.indexIn(info.symbolName); - if (index != -1) { - QStringList path = info.fullyQualifiedName.mid(0, - info.fullyQualifiedName.size() - 1); - Find::SearchResultItem item; - item.path = path; - item.text = info.symbolName; - item.textMarkPos = -1; - item.textMarkLength = 0; - item.icon = info.icon; - item.lineNumber = -1; - item.userData = qVariantFromValue(info); - resultItems << item; - } - } - if (!resultItems.isEmpty()) - future.reportResults(resultItems); - } - ++it; - ++progress; - future.setProgressValue(progress); - } - if (future.isPaused()) - future.waitForResume(); - } -} //namespace +} // anonymous namespace SymbolsFindFilter::SymbolsFindFilter(CppModelManager *manager) : m_manager(manager), m_enabled(true), m_symbolsToSearch(SearchSymbols::AllTypes), - m_scope(SearchProjectsOnly) + m_scope(SymbolSearcher::SearchProjectsOnly) { // for disabling while parser is running connect(Core::ICore::progressManager(), SIGNAL(taskStarted(QString)), @@ -176,7 +122,7 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags) connect(this, SIGNAL(enabledChanged(bool)), search, SLOT(setSearchAgainEnabled(bool))); window->popup(Core::IOutputPane::ModeSwitch | Core::IOutputPane::WithFocus); - SymbolsFindParameters parameters; + SymbolSearcher::Parameters parameters; parameters.text = txt; parameters.flags = findFlags; parameters.types = m_symbolsToSearch; @@ -187,9 +133,9 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags) void SymbolsFindFilter::startSearch(Find::SearchResult *search) { - SymbolsFindParameters parameters = search->userData().value<SymbolsFindParameters>(); + SymbolSearcher::Parameters parameters = search->userData().value<SymbolSearcher::Parameters>(); QSet<QString> projectFileNames; - if (parameters.scope == SymbolsFindFilter::SearchProjectsOnly) { + if (parameters.scope == SymbolSearcher::SearchProjectsOnly) { foreach (ProjectExplorer::Project *project, ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projects()) { projectFileNames += project->files(ProjectExplorer::Project::AllFiles).toSet(); @@ -202,9 +148,10 @@ void SymbolsFindFilter::startSearch(Find::SearchResult *search) this, SLOT(finish())); connect(watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(addResults(int,int))); - watcher->setFuture(QtConcurrent::run<Find::SearchResultItem, SymbolsFindParameters, - CPlusPlus::Snapshot, QSet<QString> >(runSearch, parameters, - m_manager->snapshot(), projectFileNames)); + SymbolSearcher *symbolSearcher = m_manager->indexingSupport()->createSymbolSearcher(parameters, projectFileNames); + connect(watcher, SIGNAL(finished()), + symbolSearcher, SLOT(deleteLater())); + watcher->setFuture(QtConcurrent::run(&SymbolSearcher::runSearch, symbolSearcher)); Core::FutureProgress *progress = Core::ICore::progressManager()->addTask(watcher->future(), tr("Searching"), QLatin1String(Find::Constants::TASK_SEARCH)); @@ -267,7 +214,7 @@ void SymbolsFindFilter::readSettings(QSettings *settings) m_symbolsToSearch = (SearchSymbols::SymbolTypes)settings->value(QLatin1String(SETTINGS_SYMBOLTYPES), (int)SearchSymbols::AllTypes).toInt(); m_scope = (SearchScope)settings->value(QLatin1String(SETTINGS_SEARCHSCOPE), - (int)SearchProjectsOnly).toInt(); + (int)SymbolSearcher::SearchProjectsOnly).toInt(); settings->endGroup(); emit symbolsToSearchChanged(); } @@ -304,16 +251,16 @@ QString SymbolsFindFilter::label() const QString SymbolsFindFilter::toolTip(Find::FindFlags findFlags) const { QStringList types; - if (m_symbolsToSearch & SearchSymbols::Classes) + if (m_symbolsToSearch & SymbolSearcher::Classes) types.append(tr("Classes")); - if (m_symbolsToSearch & SearchSymbols::Functions) + if (m_symbolsToSearch & SymbolSearcher::Functions) types.append(tr("Methods")); - if (m_symbolsToSearch & SearchSymbols::Enums) + if (m_symbolsToSearch & SymbolSearcher::Enums) types.append(tr("Enums")); - if (m_symbolsToSearch & SearchSymbols::Declarations) + if (m_symbolsToSearch & SymbolSearcher::Declarations) types.append(tr("Declarations")); return tr("Scope: %1\nTypes: %2\nFlags: %3") - .arg(searchScope() == SearchGlobal ? tr("All") : tr("Projects")) + .arg(searchScope() == SymbolSearcher::SearchGlobal ? tr("All") : tr("Projects")) .arg(types.join(tr(", "))) .arg(Find::IFindFilter::descriptionForFindFlags(findFlags)); } @@ -374,31 +321,31 @@ SymbolsFindFilterConfigWidget::SymbolsFindFilterConfigWidget(SymbolsFindFilter * void SymbolsFindFilterConfigWidget::getState() { SearchSymbols::SymbolTypes symbols = m_filter->symbolsToSearch(); - m_typeClasses->setChecked(symbols & SearchSymbols::Classes); - m_typeMethods->setChecked(symbols & SearchSymbols::Functions); - m_typeEnums->setChecked(symbols & SearchSymbols::Enums); - m_typeDeclarations->setChecked(symbols & SearchSymbols::Declarations); + m_typeClasses->setChecked(symbols & SymbolSearcher::Classes); + m_typeMethods->setChecked(symbols & SymbolSearcher::Functions); + m_typeEnums->setChecked(symbols & SymbolSearcher::Enums); + m_typeDeclarations->setChecked(symbols & SymbolSearcher::Declarations); SymbolsFindFilter::SearchScope scope = m_filter->searchScope(); - m_searchProjectsOnly->setChecked(scope == SymbolsFindFilter::SearchProjectsOnly); - m_searchGlobal->setChecked(scope == SymbolsFindFilter::SearchGlobal); + m_searchProjectsOnly->setChecked(scope == SymbolSearcher::SearchProjectsOnly); + m_searchGlobal->setChecked(scope == SymbolSearcher::SearchGlobal); } void SymbolsFindFilterConfigWidget::setState() const { SearchSymbols::SymbolTypes symbols; if (m_typeClasses->isChecked()) - symbols |= SearchSymbols::Classes; + symbols |= SymbolSearcher::Classes; if (m_typeMethods->isChecked()) - symbols |= SearchSymbols::Functions; + symbols |= SymbolSearcher::Functions; if (m_typeEnums->isChecked()) - symbols |= SearchSymbols::Enums; + symbols |= SymbolSearcher::Enums; if (m_typeDeclarations->isChecked()) - symbols |= SearchSymbols::Declarations; + symbols |= SymbolSearcher::Declarations; m_filter->setSymbolsToSearch(symbols); if (m_searchProjectsOnly->isChecked()) - m_filter->setSearchScope(SymbolsFindFilter::SearchProjectsOnly); + m_filter->setSearchScope(SymbolSearcher::SearchProjectsOnly); else - m_filter->setSearchScope(SymbolsFindFilter::SearchGlobal); + m_filter->setSearchScope(SymbolSearcher::SearchGlobal); } diff --git a/src/plugins/cpptools/symbolsfindfilter.h b/src/plugins/cpptools/symbolsfindfilter.h index f6288eb7db72a1b7e465bd79b746ab04dab2a7c4..90bdf0128f8ded2ac5eafaf05f77d5b5adc364d2 100644 --- a/src/plugins/cpptools/symbolsfindfilter.h +++ b/src/plugins/cpptools/symbolsfindfilter.h @@ -50,12 +50,11 @@ class CppModelManager; class SymbolsFindFilter : public Find::IFindFilter { Q_OBJECT + public: - enum SearchScope { - SearchProjectsOnly, - SearchGlobal - }; + typedef SymbolSearcher::SearchScope SearchScope; +public: explicit SymbolsFindFilter(CppModelManager *manager); QString id() const; @@ -102,15 +101,6 @@ private: SearchScope m_scope; }; -class SymbolsFindParameters -{ -public: - QString text; - Find::FindFlags flags; - SearchSymbols::SymbolTypes types; - SymbolsFindFilter::SearchScope scope; -}; - class SymbolsFindFilterConfigWidget : public QWidget { Q_OBJECT @@ -137,7 +127,4 @@ private: } // Internal } // CppTools -Q_DECLARE_METATYPE(CppTools::Internal::SymbolsFindFilter::SearchScope) -Q_DECLARE_METATYPE(CppTools::Internal::SymbolsFindParameters) - #endif // SYMBOLSFINDFILTER_H