forked from qt-creator/qt-creator
AutoTest: Reduce re-parsings while editing single file
Change-Id: If3dbcb3026733873881921cb9208b7c9da33c8de Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -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,6 +106,7 @@ void TestCodeParser::setState(State state)
|
||||
} else if (m_partialUpdatePostponed) {
|
||||
m_partialUpdatePostponed = false;
|
||||
qCDebug(LOG) << "calling scanForTests with postponed files (setState)";
|
||||
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,6 +458,7 @@ void TestCodeParser::onPartialParsingFinished()
|
||||
} else if (m_partialUpdatePostponed) {
|
||||
m_partialUpdatePostponed = false;
|
||||
qCDebug(LOG) << "calling scanForTests with postponed files (onPartialParsingFinished)";
|
||||
if (!m_reparseTimer.isActive())
|
||||
scanForTests(m_postponedFiles.toList());
|
||||
} else {
|
||||
m_dirty |= m_codeModelParsing;
|
||||
@@ -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
|
||||
|
Reference in New Issue
Block a user