diff --git a/src/plugins/cpptools/builtinindexingsupport.cpp b/src/plugins/cpptools/builtinindexingsupport.cpp index b9cc315b165..fc06b95024b 100644 --- a/src/plugins/cpptools/builtinindexingsupport.cpp +++ b/src/plugins/cpptools/builtinindexingsupport.cpp @@ -61,9 +61,6 @@ namespace { class ParseParams { public: - ParseParams() : revision(0) {} - - int revision; ProjectPart::HeaderPaths headerPaths; WorkingCopy workingCopy; QSet sourceFiles; @@ -189,7 +186,6 @@ void indexFindErrors(QFutureInterface &future, const ParseParams params) void index(QFutureInterface &future, const ParseParams params) { QScopedPointer sourceProcessor(CppModelManager::createSourceProcessor()); - sourceProcessor->setRevision(params.revision); sourceProcessor->setHeaderPaths(params.headerPaths); sourceProcessor->setWorkingCopy(params.workingCopy); @@ -347,7 +343,6 @@ private: } // anonymous namespace BuiltinIndexingSupport::BuiltinIndexingSupport() - : m_revision(0) { m_synchronizer.setCancelOnWait(true); } @@ -361,7 +356,6 @@ QFuture BuiltinIndexingSupport::refreshSourceFiles(const QSet &so CppModelManager *mgr = CppModelManager::instance(); ParseParams params; - params.revision = ++m_revision; params.headerPaths = mgr->headerPaths(); params.workingCopy = mgr->workingCopy(); params.sourceFiles = sourceFiles; diff --git a/src/plugins/cpptools/builtinindexingsupport.h b/src/plugins/cpptools/builtinindexingsupport.h index d0584bdeff9..f49fabfb98c 100644 --- a/src/plugins/cpptools/builtinindexingsupport.h +++ b/src/plugins/cpptools/builtinindexingsupport.h @@ -54,7 +54,6 @@ public: private: QFutureSynchronizer m_synchronizer; - unsigned m_revision; }; } // namespace Internal diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index aad230149b7..9fd0a82909c 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -232,6 +232,11 @@ CppSourceProcessor *CppModelManager::createSourceProcessor() { CppModelManager *that = instance(); return new CppSourceProcessor(that->snapshot(), [that](const Document::Ptr &doc) { + const Document::Ptr previousDocument = that->document(doc->fileName()); + const unsigned newRevision = previousDocument.isNull() + ? 1U + : previousDocument->revision() + 1; + doc->setRevision(newRevision); that->emitDocumentUpdated(doc); doc->releaseSourceAndAST(); }); diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp index 16576454e1e..38f9c66105a 100644 --- a/src/plugins/cpptools/cppmodelmanager_test.cpp +++ b/src/plugins/cpptools/cppmodelmanager_test.cpp @@ -48,6 +48,10 @@ #include #include +#define VERIFY_DOCUMENT_REVISION(document, expectedRevision) \ + QVERIFY(document); \ + QCOMPARE(document->revision(), expectedRevision); + using namespace CppTools; using namespace CppTools::Internal; using namespace CppTools::Tests; @@ -172,6 +176,15 @@ static QSet updateProjectInfo(CppModelManager *modelManager, ModelManag return helper->waitForRefreshedSourceFiles(); } +void waitForProcessedEditorDocument(const QString &filePath) +{ + CppEditorDocumentHandle *editorDocument + = CppModelManager::instance()->cppEditorDocument(filePath); + QVERIFY(editorDocument); + while (editorDocument->processor()->isParserRunning()) + QCoreApplication::processEvents(); +} + } // anonymous namespace /// Check: The preprocessor cleans include and framework paths. @@ -1107,3 +1120,45 @@ void CppToolsPlugin::test_modelmanager_renameIncludes() foreach (const QString &sourceFile, sourceFiles) QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet() << newHeader); } + +void CppToolsPlugin::test_modelmanager_documentsAndRevisions() +{ + TestCase helper; + + // Index two files + const MyTestDataDir testDir(_("testdata_project1")); + const QString filePath1 = testDir.file(QLatin1String("foo.h")); + const QString filePath2 = testDir.file(QLatin1String("foo.cpp")); + const QSet filesToIndex = QSet() << filePath1 << filePath2; + QVERIFY(TestCase::parseFiles(filesToIndex)); + + CppModelManager *modelManager = CppModelManager::instance(); + VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 1U); + VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 1U); + + // Open editor for file 1 + TextEditor::BaseTextEditor *editor1; + QVERIFY(helper.openBaseTextEditor(filePath1, &editor1)); + helper.closeEditorAtEndOfTestCase(editor1); + waitForProcessedEditorDocument(filePath1); + VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 2U); + VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 1U); + + // Index again + QVERIFY(TestCase::parseFiles(filesToIndex)); + VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 3U); + VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 2U); + + // Open editor for file 2 + TextEditor::BaseTextEditor *editor2; + QVERIFY(helper.openBaseTextEditor(filePath2, &editor2)); + helper.closeEditorAtEndOfTestCase(editor2); + waitForProcessedEditorDocument(filePath2); + VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 3U); + VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 3U); + + // Index again + QVERIFY(TestCase::parseFiles(filesToIndex)); + VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 4U); + VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 4U); +} diff --git a/src/plugins/cpptools/cppsourceprocessor.cpp b/src/plugins/cpptools/cppsourceprocessor.cpp index 85332575649..4f292c0a346 100644 --- a/src/plugins/cpptools/cppsourceprocessor.cpp +++ b/src/plugins/cpptools/cppsourceprocessor.cpp @@ -117,7 +117,6 @@ CppSourceProcessor::CppSourceProcessor(const Snapshot &snapshot, DocumentCallbac m_documentFinished(documentFinished), m_preprocess(this, &m_env), m_languageFeatures(LanguageFeatures::defaultFeatures()), - m_revision(0), m_defaultCodec(Core::EditorManager::defaultTextCodec()) { m_preprocess.setKeepComments(true); @@ -126,9 +125,6 @@ CppSourceProcessor::CppSourceProcessor(const Snapshot &snapshot, DocumentCallbac CppSourceProcessor::~CppSourceProcessor() { } -void CppSourceProcessor::setRevision(unsigned revision) -{ m_revision = revision; } - void CppSourceProcessor::setWorkingCopy(const WorkingCopy &workingCopy) { m_workingCopy = workingCopy; } @@ -470,7 +466,6 @@ void CppSourceProcessor::sourceNeeded(unsigned line, const QString &fileName, In qCDebug(log) << "Parsing:" << absoluteFileName << "contents:" << contents.size() << "bytes"; Document::Ptr document = Document::create(absoluteFileName); - document->setRevision(m_revision); document->setEditorRevision(editorRevision); document->setLanguageFeatures(m_languageFeatures); foreach (const QString &include, initialIncludes) { diff --git a/src/plugins/cpptools/cppsourceprocessor.h b/src/plugins/cpptools/cppsourceprocessor.h index 3d8053bf26d..cd5f160897a 100644 --- a/src/plugins/cpptools/cppsourceprocessor.h +++ b/src/plugins/cpptools/cppsourceprocessor.h @@ -65,7 +65,6 @@ public: CppSourceProcessor(const CPlusPlus::Snapshot &snapshot, DocumentCallback documentFinished); ~CppSourceProcessor(); - void setRevision(unsigned revision); void setWorkingCopy(const CppTools::WorkingCopy &workingCopy); void setHeaderPaths(const ProjectPart::HeaderPaths &headerPaths); void setLanguageFeatures(CPlusPlus::LanguageFeatures languageFeatures); @@ -124,7 +123,6 @@ private: CPlusPlus::Document::Ptr m_currentDoc; QSet m_todo; QSet m_processed; - unsigned m_revision; QHash m_fileNameCache; QTextCodec *m_defaultCodec; }; diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h index ea9cc91ed74..59255029242 100644 --- a/src/plugins/cpptools/cpptoolsplugin.h +++ b/src/plugins/cpptools/cpptoolsplugin.h @@ -158,6 +158,7 @@ private slots: void test_modelmanager_updateEditorsAfterProjectUpdate(); void test_modelmanager_precompiled_headers(); void test_modelmanager_renameIncludes(); + void test_modelmanager_documentsAndRevisions(); void test_cpplocatorfilters_CppLocatorFilter(); void test_cpplocatorfilters_CppLocatorFilter_data();