Commit 9eb61671 authored by Christian Stenger's avatar Christian Stenger
Browse files

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: default avatarOliver Wolff <oliver.wolff@theqtcompany.com>
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent 01eb2ad2
......@@ -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,12 +77,22 @@ TestCodeParser::~TestCodeParser()
clearCache();
}
ProjectExplorer::Project *currentProject()
{
const ProjectExplorer::SessionManager *session = ProjectExplorer::SessionManager::instance();
if (!session || !session->hasProjects())
return 0;
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());
}
}
......@@ -90,14 +101,6 @@ void TestCodeParser::emitUpdateTestTree()
QTimer::singleShot(1000, this, SLOT(updateTestTree()));
}
ProjectExplorer::Project *currentProject()
{
const ProjectExplorer::SessionManager *session = ProjectExplorer::SessionManager::instance();
if (!session || !session->hasProjects())
return 0;
return session->startupProject();
}
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();
}
}
......
......@@ -113,6 +113,7 @@ private:
bool m_pendingUpdate;
bool m_fullUpdatePostPoned;
bool m_partialUpdatePostPoned;
bool m_dirty;
QSet<QString> m_postPonedFiles;
State m_parserState;
};
......
......@@ -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
......
......@@ -113,8 +113,6 @@ private:
TestTreeItem *m_quickTestRootItem;
TestCodeParser *m_parser;
bool m_connectionsInitialized;
int m_initializationCounter;
};
class TestTreeSortFilterModel : public QSortFilterProxyModel
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment