From b570ee1b801da0906fdba9e0218e681b003a9857 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 27 Jun 2016 15:47:30 +0200 Subject: [PATCH] AutoTest: Fix initial parse when loading session Avoid displaying tests from other projects of the same session which have been indexed but do not belong to the current startup project. Change-Id: I6e0fb62cc97898ef3853ec61580dd2deb5ac64e5 Reviewed-by: David Schulz --- src/plugins/autotest/testcodeparser.cpp | 54 ++++++++++++------------- src/plugins/autotest/testcodeparser.h | 1 + 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/plugins/autotest/testcodeparser.cpp b/src/plugins/autotest/testcodeparser.cpp index 7e6e0b3c3c4..2a81e580e48 100644 --- a/src/plugins/autotest/testcodeparser.cpp +++ b/src/plugins/autotest/testcodeparser.cpp @@ -202,30 +202,14 @@ static void performParse(QFutureInterface &futureInterface, /****** threaded parsing stuff *******/ -void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &document) +void TestCodeParser::onDocumentUpdated(const QString &fileName) { - if (m_codeModelParsing) { - if (!m_fullUpdatePostponed) { - m_partialUpdatePostponed = true; - m_postponedFiles.insert(document->fileName()); - } - return; - } - ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); if (!project) return; - const QString fileName = document->fileName(); - if (!project->files(ProjectExplorer::Project::AllFiles).contains(fileName)) + if (!project->files(ProjectExplorer::Project::SourceFiles).contains(fileName)) return; - qCDebug(LOG) << "calling scanForTests (onCppDocumentUpdated)"; - scanForTests(QStringList(fileName)); -} - -void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document) -{ - const QString &fileName = document->fileName(); if (m_codeModelParsing) { if (!m_fullUpdatePostponed) { m_partialUpdatePostponed = true; @@ -234,22 +218,26 @@ void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document) return; } - ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); - if (!project) - return; - if (!project->files(ProjectExplorer::Project::AllFiles).contains(fileName)) { - // what if the file is not listed inside the pro file, but will be used anyway? - return; - } - scanForTests(QStringList(fileName)); } +void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &document) +{ + onDocumentUpdated(document->fileName()); +} + +void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document) +{ + onDocumentUpdated(document->fileName()); +} + void TestCodeParser::onStartupProjectChanged(ProjectExplorer::Project *project) { - if (m_parserState == FullParse || m_parserState == PartialParse) + if (m_parserState == FullParse || m_parserState == PartialParse) { + qCDebug(LOG) << "Canceling scanForTest (startup project changed)"; Core::ProgressManager::instance()->cancelTasks(Constants::TASK_PARSE); - else if (project) + } + if (project) emitUpdateTestTree(); } @@ -275,6 +263,7 @@ bool TestCodeParser::postponed(const QStringList &fileList) m_partialUpdatePostponed = false; m_postponedFiles.clear(); m_fullUpdatePostponed = true; + qCDebug(LOG) << "Canceling scanForTest (full parse triggered while running a scan)"; Core::ProgressManager::instance()->cancelTasks(Constants::TASK_PARSE); } else { // partial parse triggered, but full parse is postponed already, ignoring this @@ -352,8 +341,15 @@ void TestCodeParser::scanForTests(const QStringList &fileList) void TestCodeParser::onTaskStarted(Core::Id type) { - if (type == CppTools::Constants::TASK_INDEX) + if (type == CppTools::Constants::TASK_INDEX) { m_codeModelParsing = true; + if (m_parserState == FullParse || m_parserState == PartialParse) { + m_fullUpdatePostponed = m_parserState == FullParse; + m_partialUpdatePostponed = !m_fullUpdatePostponed; + qCDebug(LOG) << "Canceling scan for test (CppModelParsing started)"; + Core::ProgressManager::instance()->cancelTasks(Constants::TASK_PARSE); + } + } } void TestCodeParser::onAllTasksFinished(Core::Id type) diff --git a/src/plugins/autotest/testcodeparser.h b/src/plugins/autotest/testcodeparser.h index 19b58dfa468..d9779525f8a 100644 --- a/src/plugins/autotest/testcodeparser.h +++ b/src/plugins/autotest/testcodeparser.h @@ -82,6 +82,7 @@ private: bool postponed(const QStringList &fileList); void scanForTests(const QStringList &fileList = QStringList()); + void onDocumentUpdated(const QString &fileName); void onTaskStarted(Core::Id type); void onAllTasksFinished(Core::Id type); void onFinished();