forked from qt-creator/qt-creator
Made symbol searching plug-able through indexing support.
The indexing support for the built-in code model is moved to its own file. Symbol searching will now call for a searcher through that support interface, which will create a fully configured and ready-to-go searcher that can be started in the/a future. Change-Id: Idc3ee1c7c789a69fa05ee1d42415313dcea94cf8 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
216
src/plugins/cpptools/builtinindexingsupport.cpp
Normal file
216
src/plugins/cpptools/builtinindexingsupport.cpp
Normal file
@@ -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);
|
||||
}
|
||||
33
src/plugins/cpptools/builtinindexingsupport.h
Normal file
33
src/plugins/cpptools/builtinindexingsupport.h
Normal file
@@ -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
|
||||
@@ -38,7 +38,7 @@ CppClassesFilter::CppClassesFilter(CppModelManager *manager)
|
||||
setShortcutString(QLatin1String("c"));
|
||||
setIncludedByDefault(false);
|
||||
|
||||
search.setSymbolsToSearchFor(SearchSymbols::Classes);
|
||||
search.setSymbolsToSearchFor(SymbolSearcher::Classes);
|
||||
search.setSeparateScope(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,4 +36,12 @@ CppIndexingSupport::~CppIndexingSupport()
|
||||
{
|
||||
}
|
||||
|
||||
SymbolSearcher::SymbolSearcher(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
SymbolSearcher::~SymbolSearcher()
|
||||
{}
|
||||
|
||||
} // namespace CppTools
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -50,12 +50,11 @@ class CppModelManager;
|
||||
class SymbolsFindFilter : public Find::IFindFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum SearchScope {
|
||||
SearchProjectsOnly,
|
||||
SearchGlobal
|
||||
};
|
||||
|
||||
public:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user