Commit 2b27f305 authored by Christian Stenger's avatar Christian Stenger
Browse files

AutoTest: Reduce re-parsings while editing single file



Change-Id: If3dbcb3026733873881921cb9208b7c9da33c8de
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent 99a82f70
......@@ -45,7 +45,6 @@
#include <QFuture>
#include <QFutureInterface>
#include <QLoggingCategory>
#include <QTimer>
static Q_LOGGING_CATEGORY(LOG, "qtc.autotest.testcodeparser")
......@@ -54,13 +53,7 @@ namespace Internal {
TestCodeParser::TestCodeParser(TestTreeModel *parent)
: QObject(parent),
m_model(parent),
m_codeModelParsing(false),
m_fullUpdatePostponed(false),
m_partialUpdatePostponed(false),
m_dirty(false),
m_singleShotScheduled(false),
m_parserState(Disabled)
m_model(parent)
{
// connect to ProgressManager to postpone test parsing when CppModelManager is parsing
auto progressManager = qobject_cast<Core::ProgressManager *>(Core::ProgressManager::instance());
......@@ -77,6 +70,8 @@ TestCodeParser::TestCodeParser(TestTreeModel *parent)
emit testParseResultReady(m_futureWatcher.resultAt(index));
});
connect(this, &TestCodeParser::parsingFinished, this, &TestCodeParser::releaseParserInternals);
m_reparseTimer.setSingleShot(true);
connect(&m_reparseTimer, &QTimer::timeout, this, &TestCodeParser::parsePostponedFiles);
}
TestCodeParser::~TestCodeParser()
......@@ -111,7 +106,8 @@ void TestCodeParser::setState(State state)
} else if (m_partialUpdatePostponed) {
m_partialUpdatePostponed = false;
qCDebug(LOG) << "calling scanForTests with postponed files (setState)";
scanForTests(m_postponedFiles.toList());
if (!m_reparseTimer.isActive())
scanForTests(m_postponedFiles.toList());
}
}
}
......@@ -267,6 +263,30 @@ bool TestCodeParser::postponed(const QStringList &fileList)
{
switch (m_parserState) {
case Idle:
if (fileList.size() == 1) {
if (m_reparseTimerTimedOut)
return false;
switch (m_postponedFiles.size()) {
case 0:
m_postponedFiles.insert(fileList.first());
m_reparseTimer.setInterval(1000);
m_reparseTimer.start();
return true;
case 1:
if (m_postponedFiles.contains(fileList.first())) {
m_reparseTimer.start();
return true;
}
// intentional fall-through
default:
m_postponedFiles.insert(fileList.first());
m_reparseTimer.stop();
m_reparseTimer.setInterval(0);
m_reparseTimerTimedOut = false;
m_reparseTimer.start();
return true;
}
}
return false;
case PartialParse:
case FullParse:
......@@ -313,6 +333,8 @@ void TestCodeParser::scanForTests(const QStringList &fileList)
if (postponed(fileList))
return;
m_reparseTimer.stop();
m_reparseTimerTimedOut = false;
m_postponedFiles.clear();
bool isFullParse = fileList.isEmpty();
QStringList list;
......@@ -436,7 +458,8 @@ void TestCodeParser::onPartialParsingFinished()
} else if (m_partialUpdatePostponed) {
m_partialUpdatePostponed = false;
qCDebug(LOG) << "calling scanForTests with postponed files (onPartialParsingFinished)";
scanForTests(m_postponedFiles.toList());
if (!m_reparseTimer.isActive())
scanForTests(m_postponedFiles.toList());
} else {
m_dirty |= m_codeModelParsing;
if (m_dirty) {
......@@ -454,6 +477,12 @@ void TestCodeParser::onPartialParsingFinished()
}
}
void TestCodeParser::parsePostponedFiles()
{
m_reparseTimerTimedOut = true;
scanForTests(m_postponedFiles.toList());
}
void TestCodeParser::releaseParserInternals()
{
for (ITestParser *parser : m_testCodeParsers)
......
......@@ -32,6 +32,7 @@
#include <QObject>
#include <QMap>
#include <QFutureWatcher>
#include <QTimer>
namespace Core {
class Id;
......@@ -89,19 +90,22 @@ private:
void onAllTasksFinished(Core::Id type);
void onFinished();
void onPartialParsingFinished();
void parsePostponedFiles();
void releaseParserInternals();
TestTreeModel *m_model;
bool m_codeModelParsing;
bool m_fullUpdatePostponed;
bool m_partialUpdatePostponed;
bool m_dirty;
bool m_singleShotScheduled;
bool m_codeModelParsing = false;
bool m_fullUpdatePostponed = false;
bool m_partialUpdatePostponed = false;
bool m_dirty = false;
bool m_singleShotScheduled = false;
bool m_reparseTimerTimedOut = false;
QSet<QString> m_postponedFiles;
State m_parserState;
State m_parserState = Disabled;
QFutureWatcher<TestParseResultPtr> m_futureWatcher;
QVector<ITestParser *> m_testCodeParsers; // ptrs are still owned by TestFrameworkManager
QTimer m_reparseTimer;
};
} // namespace Internal
......
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