Post-pone parsing for test if CppModelManager is parsing

Change-Id: I7af93eb587e55f7d6e4ee14ed9808ceeb41ed8a3
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Christian Stenger
2014-12-10 09:41:23 +01:00
parent 19f36ebf78
commit d778fc5477
3 changed files with 53 additions and 2 deletions

View File

@@ -23,15 +23,20 @@
#include "testtreemodel.h" #include "testtreemodel.h"
#include "testvisitor.h" #include "testvisitor.h"
#include <coreplugin/progressmanager/progressmanager.h>
#include <cplusplus/LookupContext.h> #include <cplusplus/LookupContext.h>
#include <cplusplus/TypeOfExpression.h> #include <cplusplus/TypeOfExpression.h>
#include <cpptools/cpptoolsconstants.h>
#include <cpptools/cppmodelmanager.h> #include <cpptools/cppmodelmanager.h>
#include <cpptools/cppworkingcopy.h> #include <cpptools/cppworkingcopy.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <qmakeprojectmanager/qmakeproject.h> #include <qmakeprojectmanager/qmakeproject.h>
#include <qmakeprojectmanager/qmakeprojectmanagerconstants.h>
#include <qmljs/parser/qmljsast_p.h> #include <qmljs/parser/qmljsast_p.h>
#include <qmljs/qmljsdialect.h> #include <qmljs/qmljsdialect.h>
#include <qmljstools/qmljsmodelmanager.h> #include <qmljstools/qmljsmodelmanager.h>
@@ -44,8 +49,15 @@ namespace Internal {
TestCodeParser::TestCodeParser(TestTreeModel *parent) TestCodeParser::TestCodeParser(TestTreeModel *parent)
: QObject(parent), : QObject(parent),
m_model(parent), m_model(parent),
m_currentProject(0) m_currentProject(0),
m_parserEnabled(true),
m_pendingUpdate(false)
{ {
// connect to ProgressManager to post-pone test parsing when CppModelManager is parsing
Core::ProgressManager *pm = qobject_cast<Core::ProgressManager *>(
Core::ProgressManager::instance());
connect(pm, &Core::ProgressManager::taskStarted, this, &TestCodeParser::onTaskStarted);
connect(pm, &Core::ProgressManager::allTasksFinished, this, &TestCodeParser::onAllTasksFinished);
} }
TestCodeParser::~TestCodeParser() TestCodeParser::~TestCodeParser()
@@ -53,8 +65,19 @@ TestCodeParser::~TestCodeParser()
clearMaps(); clearMaps();
} }
void TestCodeParser::emitUpdateTestTree()
{
QTimer::singleShot(1000, this, SLOT(updateTestTree()));
}
void TestCodeParser::updateTestTree() void TestCodeParser::updateTestTree()
{ {
if (!m_parserEnabled) {
m_pendingUpdate = true;
qDebug() << "Skipped update due to running parser or pro file evaluate";
return;
}
qDebug("updating TestTreeModel"); qDebug("updating TestTreeModel");
clearMaps(); clearMaps();
@@ -84,6 +107,7 @@ void TestCodeParser::updateTestTree()
} }
} }
scanForTests(); scanForTests();
m_pendingUpdate = false;
} }
/****** scan for QTest related stuff helpers ******/ /****** scan for QTest related stuff helpers ******/
@@ -721,6 +745,24 @@ void TestCodeParser::removeTestsIfNecessaryByProFile(const QString &proFile)
m_quickDocMap.insert(tr(Constants::UNNAMED_QUICKTESTS), unnamedInfo); m_quickDocMap.insert(tr(Constants::UNNAMED_QUICKTESTS), unnamedInfo);
} }
void TestCodeParser::onTaskStarted(Core::Id type)
{
if (type != CppTools::Constants::TASK_INDEX
&& type != QmakeProjectManager::Constants::PROFILE_EVALUATE)
return;
m_parserEnabled = false;
}
void TestCodeParser::onAllTasksFinished(Core::Id type)
{
if (type != CppTools::Constants::TASK_INDEX
&& type != QmakeProjectManager::Constants::PROFILE_EVALUATE)
return;
m_parserEnabled = true;
if (m_pendingUpdate)
updateTestTree();
}
void TestCodeParser::onProFileEvaluated() void TestCodeParser::onProFileEvaluated()
{ {
if (!m_currentProject) if (!m_currentProject)

View File

@@ -30,6 +30,10 @@ namespace ProjectExplorer {
class Project; class Project;
} }
namespace Core {
class Id;
}
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
@@ -46,6 +50,7 @@ public:
signals: signals:
public slots: public slots:
void emitUpdateTestTree();
void updateTestTree(); void updateTestTree();
void checkDocumentForTestCode(CPlusPlus::Document::Ptr doc); void checkDocumentForTestCode(CPlusPlus::Document::Ptr doc);
void handleQtQuickTest(CPlusPlus::Document::Ptr doc); void handleQtQuickTest(CPlusPlus::Document::Ptr doc);
@@ -60,11 +65,15 @@ private:
void clearMaps(); void clearMaps();
void removeTestsIfNecessary(const QString &fileName); void removeTestsIfNecessary(const QString &fileName);
void removeTestsIfNecessaryByProFile(const QString &proFile); void removeTestsIfNecessaryByProFile(const QString &proFile);
void onTaskStarted(Core::Id type);
void onAllTasksFinished(Core::Id type);
TestTreeModel *m_model; TestTreeModel *m_model;
QMap<QString, TestInfo> m_cppDocMap; QMap<QString, TestInfo> m_cppDocMap;
QMap<QString, TestInfo> m_quickDocMap; QMap<QString, TestInfo> m_quickDocMap;
ProjectExplorer::Project *m_currentProject; ProjectExplorer::Project *m_currentProject;
bool m_parserEnabled;
bool m_pendingUpdate;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -65,7 +65,7 @@ TestTreeViewWidget::TestTreeViewWidget(QWidget *parent) :
TestCodeParser *parser = m_model->parser(); TestCodeParser *parser = m_model->parser();
ProjectExplorer::SessionManager *sm = ProjectExplorer::SessionManager::instance(); ProjectExplorer::SessionManager *sm = ProjectExplorer::SessionManager::instance();
connect(sm, &ProjectExplorer::SessionManager::startupProjectChanged, connect(sm, &ProjectExplorer::SessionManager::startupProjectChanged,
parser, &TestCodeParser::updateTestTree); parser, &TestCodeParser::emitUpdateTestTree);
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance(); CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
connect(cppMM, &CppTools::CppModelManager::documentUpdated, connect(cppMM, &CppTools::CppModelManager::documentUpdated,