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:
@@ -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,
|
||||
|
Reference in New Issue
Block a user