From 536ccc8a8742b38e75547d98ce457b0b90af3ee7 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Mon, 25 Apr 2016 13:17:20 +0200 Subject: CppTools: Fix incompletely indexed project Use case to reproduce: 1. Open some bigger project, e.g. qtcreator.pro 2. As soon as "Parsing C/C++ files" is reported, add a character to qmake's additional arguments in project mode (indexing should not be finished at this point). 3. The indexing gets canceled. ==> ...but reindexing is not triggered. Fix by checking whether the future was canceled. Task-number: QTCREATORBUG-16134 Change-Id: I520c6a64a6adc1cb04cafb5e0aa56c8bf41d7b14 Reviewed-by: Christian Stenger --- src/plugins/cpptools/cppmodelmanager.cpp | 33 +++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'src/plugins/cpptools/cppmodelmanager.cpp') diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index 13b582cfed..2ffd37c14e 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -131,6 +132,7 @@ public: // Project integration mutable QMutex m_projectMutex; QMap m_projectToProjectsInfo; + QHash m_projectToIndexerCanceled; QMap > m_fileToProjectParts; QMap m_projectPartIdToProjectProjectPart; // The members below are cached/(re)calculated from the projects and/or their project parts @@ -759,6 +761,25 @@ void CppModelManager::recalculateProjectPartMappings() d->m_symbolFinder.clearCache(); } +void CppModelManager::watchForCanceledProjectIndexer(QFuture future, + ProjectExplorer::Project *project) +{ + d->m_projectToIndexerCanceled.insert(project, false); + + if (future.isCanceled() || future.isFinished()) + return; + + QFutureWatcher *watcher = new QFutureWatcher(); + connect(watcher, &QFutureWatcher::canceled, this, [this, project]() { + if (d->m_projectToIndexerCanceled.contains(project)) // Project not yet removed + d->m_projectToIndexerCanceled.insert(project, true); + }); + connect(watcher, &QFutureWatcher::finished, this, [watcher]() { + watcher->deleteLater(); + }); + watcher->setFuture(future); +} + void CppModelManager::updateCppEditorDocuments() const { // Refresh visible documents @@ -792,16 +813,17 @@ QFuture CppModelManager::updateProjectInfo(const ProjectInfo &newProjectIn QSet filesToReindex; QStringList removedProjectParts; bool filesRemoved = false; + ProjectExplorer::Project *project = newProjectInfo.project().data(); { // Only hold the mutex for a limited scope, so the dumping afterwards does not deadlock. QMutexLocker projectLocker(&d->m_projectMutex); - ProjectExplorer::Project *project = newProjectInfo.project().data(); const QSet newSourceFiles = newProjectInfo.sourceFiles(); // Check if we can avoid a full reindexing ProjectInfo oldProjectInfo = d->m_projectToProjectsInfo.value(project); - if (oldProjectInfo.isValid()) { + const bool previousIndexerCanceled = d->m_projectToIndexerCanceled.value(project, false); + if (!previousIndexerCanceled && oldProjectInfo.isValid()) { ProjectInfoComparer comparer(oldProjectInfo, newProjectInfo); if (comparer.configurationOrFilesChanged()) { @@ -872,7 +894,10 @@ QFuture CppModelManager::updateProjectInfo(const ProjectInfo &newProjectIn updateCppEditorDocuments(); // Trigger reindexing - return updateSourceFiles(filesToReindex, ForcedProgressNotification); + QFuture indexerFuture = updateSourceFiles(filesToReindex, ForcedProgressNotification); + watchForCanceledProjectIndexer(indexerFuture, project); + + return indexerFuture; } ProjectPart::Ptr CppModelManager::projectPartForId(const QString &projectPartId) const @@ -970,6 +995,8 @@ void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project) { QStringList projectPartIds; + d->m_projectToIndexerCanceled.remove(project); + { QMutexLocker locker(&d->m_projectMutex); d->m_dirty = true; -- cgit v1.2.1