Improve handling of disabled parser and re-enabling parser

Instead of always parsing again when re-enabling parser do it only
if there are changes of the current project.
If the current project has not changed since last parsing just rely
on the cached information.

Change-Id: I7681318132f37172730648604ddbecf1cd37d177
Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
Christian Stenger
2015-02-19 11:19:59 +01:00
parent 01eb2ad24f
commit 9eb6167189
4 changed files with 42 additions and 49 deletions

View File

@@ -59,7 +59,8 @@ TestCodeParser::TestCodeParser(TestTreeModel *parent)
m_pendingUpdate(false),
m_fullUpdatePostPoned(false),
m_partialUpdatePostPoned(false),
m_parserState(Idle)
m_dirty(true),
m_parserState(Disabled)
{
// connect to ProgressManager to post-pone test parsing when CppModelManager is parsing
auto progressManager = qobject_cast<Core::ProgressManager *>(Core::ProgressManager::instance());
@@ -76,20 +77,6 @@ TestCodeParser::~TestCodeParser()
clearCache();
}
void TestCodeParser::setState(State state)
{
m_parserState = state;
if (m_parserState == Disabled) {
m_pendingUpdate = m_fullUpdatePostPoned = m_partialUpdatePostPoned = false;
m_postPonedFiles.clear();
}
}
void TestCodeParser::emitUpdateTestTree()
{
QTimer::singleShot(1000, this, SLOT(updateTestTree()));
}
ProjectExplorer::Project *currentProject()
{
const ProjectExplorer::SessionManager *session = ProjectExplorer::SessionManager::instance();
@@ -98,6 +85,22 @@ ProjectExplorer::Project *currentProject()
return session->startupProject();
}
void TestCodeParser::setState(State state)
{
m_parserState = state;
if (m_parserState == Disabled) {
m_pendingUpdate = m_fullUpdatePostPoned = m_partialUpdatePostPoned = false;
m_postPonedFiles.clear();
} else if (m_parserState == Idle && m_dirty && currentProject()) {
scanForTests(m_postPonedFiles.toList());
}
}
void TestCodeParser::emitUpdateTestTree()
{
QTimer::singleShot(1000, this, SLOT(updateTestTree()));
}
void TestCodeParser::updateTestTree()
{
if (!m_parserEnabled) {
@@ -578,14 +581,29 @@ bool TestCodeParser::postponed(const QStringList &fileList)
}
return true;
case Disabled:
qWarning("Checking for postponing but being disabled...");
return false;
break;
}
QTC_ASSERT(false, return false); // should not happen at all
}
void TestCodeParser::scanForTests(const QStringList &fileList)
{
if (m_parserState == Disabled) {
m_dirty = true;
if (fileList.isEmpty()) {
m_fullUpdatePostPoned = true;
m_partialUpdatePostPoned = false;
m_postPonedFiles.clear();
} else {
if (!m_fullUpdatePostPoned) {
m_partialUpdatePostPoned = true;
foreach (const QString &file, fileList)
m_postPonedFiles.insert(file);
}
}
return;
}
if (postponed(fileList))
return;
@@ -730,6 +748,7 @@ void TestCodeParser::onFinished()
case FullParse:
m_parserState = Idle;
emit parsingFinished();
m_dirty = false;
break;
default:
qWarning("I should not be here...");
@@ -752,6 +771,9 @@ void TestCodeParser::onPartialParsingFinished()
tmp << file;
m_postPonedFiles.clear();
scanForTests(tmp);
} else {
m_dirty = false;
emit parsingFinished();
}
}

View File

@@ -113,6 +113,7 @@ private:
bool m_pendingUpdate;
bool m_fullUpdatePostPoned;
bool m_partialUpdatePostPoned;
bool m_dirty;
QSet<QString> m_postPonedFiles;
State m_parserState;
};

View File

@@ -51,8 +51,7 @@ TestTreeModel::TestTreeModel(QObject *parent) :
m_autoTestRootItem(new TestTreeItem(tr("Auto Tests"), QString(), TestTreeItem::ROOT, m_rootItem)),
m_quickTestRootItem(new TestTreeItem(tr("Qt Quick Tests"), QString(), TestTreeItem::ROOT, m_rootItem)),
m_parser(new TestCodeParser(this)),
m_connectionsInitialized(false),
m_initializationCounter(0)
m_connectionsInitialized(false)
{
m_rootItem->appendChild(m_autoTestRootItem);
m_rootItem->appendChild(m_quickTestRootItem);
@@ -103,13 +102,10 @@ TestTreeModel::~TestTreeModel()
void TestTreeModel::enableParsing()
{
++m_initializationCounter;
m_parser->setState(TestCodeParser::Idle);
if (m_connectionsInitialized)
return;
m_parser->setState(TestCodeParser::Idle);
ProjectExplorer::SessionManager *sm = ProjectExplorer::SessionManager::instance();
connect(sm, &ProjectExplorer::SessionManager::startupProjectChanged,
m_parser, &TestCodeParser::emitUpdateTestTree);
@@ -126,35 +122,11 @@ void TestTreeModel::enableParsing()
connect(qmlJsMM, &QmlJS::ModelManagerInterface::aboutToRemoveFiles,
m_parser, &TestCodeParser::removeFiles, Qt::QueuedConnection);
m_connectionsInitialized = true;
m_parser->updateTestTree();
}
void TestTreeModel::disableParsing()
{
if (!m_connectionsInitialized)
return;
if (--m_initializationCounter != 0)
return;
ProjectExplorer::SessionManager *sm = ProjectExplorer::SessionManager::instance();
disconnect(sm, &ProjectExplorer::SessionManager::startupProjectChanged,
m_parser, &TestCodeParser::emitUpdateTestTree);
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
disconnect(cppMM, &CppTools::CppModelManager::documentUpdated,
m_parser, &TestCodeParser::onCppDocumentUpdated);
disconnect(cppMM, &CppTools::CppModelManager::aboutToRemoveFiles,
m_parser, &TestCodeParser::removeFiles);
QmlJS::ModelManagerInterface *qmlJsMM = QmlJS::ModelManagerInterface::instance();
disconnect(qmlJsMM, &QmlJS::ModelManagerInterface::documentUpdated,
m_parser, &TestCodeParser::onQmlDocumentUpdated);
disconnect(qmlJsMM, &QmlJS::ModelManagerInterface::aboutToRemoveFiles,
m_parser, &TestCodeParser::removeFiles);
m_parser->setState(TestCodeParser::Disabled);
m_connectionsInitialized = false;
}
QModelIndex TestTreeModel::index(int row, int column, const QModelIndex &parent) const

View File

@@ -113,8 +113,6 @@ private:
TestTreeItem *m_quickTestRootItem;
TestCodeParser *m_parser;
bool m_connectionsInitialized;
int m_initializationCounter;
};
class TestTreeSortFilterModel : public QSortFilterProxyModel