Commit 20f05072 authored by Christian Stenger's avatar Christian Stenger
Browse files

Add logging capability to code parser



Helps to get more information when something goes wrong.
Can be enabled by setting QT_LOGGING_RULES to
qtc.autotest.testcodeparser.debug=true

Change-Id: Ic168029912f8af509d6a822440658225c7f04eab
Reviewed-by: default avatarNiels Weber <niels.weber@theqtcompany.com>
parent d87b4668
...@@ -47,8 +47,11 @@ ...@@ -47,8 +47,11 @@
#include <QDirIterator> #include <QDirIterator>
#include <QFuture> #include <QFuture>
#include <QFutureInterface> #include <QFutureInterface>
#include <QLoggingCategory>
#include <QTimer> #include <QTimer>
static Q_LOGGING_CATEGORY(LOG, "qtc.autotest.testcodeparser")
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
...@@ -79,15 +82,19 @@ TestCodeParser::~TestCodeParser() ...@@ -79,15 +82,19 @@ TestCodeParser::~TestCodeParser()
void TestCodeParser::setState(State state) void TestCodeParser::setState(State state)
{ {
qCDebug(LOG) << "setState(" << state << "), currentState:" << m_parserState;
// avoid triggering parse before code model parsing has finished, but mark as dirty // avoid triggering parse before code model parsing has finished, but mark as dirty
if (m_codeModelParsing) { if (m_codeModelParsing) {
m_dirty = true; m_dirty = true;
qCDebug(LOG) << "Not setting new state - code model parsing is running, just marking dirty";
return; return;
} }
if ((state == Disabled || state == Idle) if ((state == Disabled || state == Idle)
&& (m_parserState == PartialParse || m_parserState == FullParse)) && (m_parserState == PartialParse || m_parserState == FullParse)) {
qCDebug(LOG) << "Not setting state, parse is running";
return; return;
}
m_parserState = state; m_parserState = state;
if (m_parserState == Disabled) { if (m_parserState == Disabled) {
...@@ -98,6 +105,7 @@ void TestCodeParser::setState(State state) ...@@ -98,6 +105,7 @@ void TestCodeParser::setState(State state)
emitUpdateTestTree(); emitUpdateTestTree();
} else if (m_partialUpdatePostponed) { } else if (m_partialUpdatePostponed) {
m_partialUpdatePostponed = false; m_partialUpdatePostponed = false;
qCDebug(LOG) << "calling scanForTests with postponed files (setState)";
scanForTests(m_postponedFiles.toList()); scanForTests(m_postponedFiles.toList());
} }
} }
...@@ -105,9 +113,12 @@ void TestCodeParser::setState(State state) ...@@ -105,9 +113,12 @@ void TestCodeParser::setState(State state)
void TestCodeParser::emitUpdateTestTree() void TestCodeParser::emitUpdateTestTree()
{ {
if (m_singleShotScheduled) if (m_singleShotScheduled) {
qCDebug(LOG) << "not scheduling another updateTestTree";
return; return;
}
qCDebug(LOG) << "adding singleShot";
m_singleShotScheduled = true; m_singleShotScheduled = true;
QTimer::singleShot(1000, this, SLOT(updateTestTree())); QTimer::singleShot(1000, this, SLOT(updateTestTree()));
} }
...@@ -128,6 +139,7 @@ void TestCodeParser::updateTestTree() ...@@ -128,6 +139,7 @@ void TestCodeParser::updateTestTree()
m_fullUpdatePostponed = false; m_fullUpdatePostponed = false;
clearCache(); clearCache();
qCDebug(LOG) << "calling scanForTests (updateTestTree)";
scanForTests(); scanForTests();
} }
...@@ -506,6 +518,7 @@ void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &docume ...@@ -506,6 +518,7 @@ void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &docume
} else if (!project->files(ProjectExplorer::Project::AllFiles).contains(fileName)) { } else if (!project->files(ProjectExplorer::Project::AllFiles).contains(fileName)) {
return; return;
} }
qCDebug(LOG) << "calling scanForTests (onCppDocumentUpdated)";
scanForTests(QStringList(fileName)); scanForTests(QStringList(fileName));
} }
...@@ -534,8 +547,11 @@ void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document) ...@@ -534,8 +547,11 @@ void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document)
const CPlusPlus::Snapshot snapshot = CppTools::CppModelManager::instance()->snapshot(); const CPlusPlus::Snapshot snapshot = CppTools::CppModelManager::instance()->snapshot();
if (m_quickDocMap.contains(fileName) if (m_quickDocMap.contains(fileName)
&& snapshot.contains(m_quickDocMap[fileName].referencingFile())) { && snapshot.contains(m_quickDocMap[fileName].referencingFile())) {
if (!m_quickDocMap[fileName].referencingFile().isEmpty()) if (!m_quickDocMap[fileName].referencingFile().isEmpty()) {
qCDebug(LOG) << "calling scanForTests with cached referencing files"
<< "(onQmlDocumentUpdated)";
scanForTests(QStringList(m_quickDocMap[fileName].referencingFile())); scanForTests(QStringList(m_quickDocMap[fileName].referencingFile()));
}
} }
if (m_unnamedQuickDocList.size() == 0) if (m_unnamedQuickDocList.size() == 0)
return; return;
...@@ -543,6 +559,7 @@ void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document) ...@@ -543,6 +559,7 @@ void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document)
// special case of having unnamed TestCases // special case of having unnamed TestCases
const QString &mainFile = m_model->getMainFileForUnnamedQuickTest(fileName); const QString &mainFile = m_model->getMainFileForUnnamedQuickTest(fileName);
if (!mainFile.isEmpty() && snapshot.contains(mainFile)) { if (!mainFile.isEmpty() && snapshot.contains(mainFile)) {
qCDebug(LOG) << "calling scanForTests with mainfile (onQmlDocumentUpdated)";
scanForTests(QStringList(mainFile)); scanForTests(QStringList(mainFile));
} }
} }
...@@ -630,9 +647,11 @@ void TestCodeParser::scanForTests(const QStringList &fileList) ...@@ -630,9 +647,11 @@ void TestCodeParser::scanForTests(const QStringList &fileList)
list = ProjectExplorer::SessionManager::startupProject()->files(ProjectExplorer::Project::AllFiles); list = ProjectExplorer::SessionManager::startupProject()->files(ProjectExplorer::Project::AllFiles);
if (list.isEmpty()) if (list.isEmpty())
return; return;
qCDebug(LOG) << "setting state to FullParse (scanForTests)";
m_parserState = FullParse; m_parserState = FullParse;
} else { } else {
list << fileList; list << fileList;
qCDebug(LOG) << "setting state to PartialParse (scanForTests)";
m_parserState = PartialParse; m_parserState = PartialParse;
} }
...@@ -729,19 +748,25 @@ void TestCodeParser::onFinished() ...@@ -729,19 +748,25 @@ void TestCodeParser::onFinished()
{ {
switch (m_parserState) { switch (m_parserState) {
case PartialParse: case PartialParse:
qCDebug(LOG) << "setting state to Idle (onFinished, PartialParse)";
m_parserState = Idle; m_parserState = Idle;
emit partialParsingFinished(); emit partialParsingFinished();
break; break;
case FullParse: case FullParse:
qCDebug(LOG) << "setting state to Idle (onFinished, FullParse)";
m_parserState = Idle; m_parserState = Idle;
m_dirty = parsingHasFailed; m_dirty = parsingHasFailed;
if (m_partialUpdatePostponed || m_fullUpdatePostponed || parsingHasFailed) if (m_partialUpdatePostponed || m_fullUpdatePostponed || parsingHasFailed) {
emit partialParsingFinished(); emit partialParsingFinished();
else } else {
qCDebug(LOG) << "emitting parsingFinished"
<< "(onFinished, FullParse, nothing postponed, parsing succeeded)";
emit parsingFinished(); emit parsingFinished();
}
m_dirty = false; m_dirty = false;
break; break;
case Disabled: // can happen if all Test related widgets become hidden while parsing case Disabled: // can happen if all Test related widgets become hidden while parsing
qCDebug(LOG) << "emitting parsingFinished (onFinished, Disabled)";
emit parsingFinished(); emit parsingFinished();
break; break;
default: default:
...@@ -757,16 +782,24 @@ void TestCodeParser::onPartialParsingFinished() ...@@ -757,16 +782,24 @@ void TestCodeParser::onPartialParsingFinished()
m_partialUpdatePostponed = false;m_postponedFiles.clear();); m_partialUpdatePostponed = false;m_postponedFiles.clear(););
if (m_fullUpdatePostponed) { if (m_fullUpdatePostponed) {
m_fullUpdatePostponed = false; m_fullUpdatePostponed = false;
qCDebug(LOG) << "calling updateTestTree (onPartialParsingFinished)";
updateTestTree(); updateTestTree();
} else if (m_partialUpdatePostponed) { } else if (m_partialUpdatePostponed) {
m_partialUpdatePostponed = false; m_partialUpdatePostponed = false;
qCDebug(LOG) << "calling scanForTests with postponed files (onPartialParsingFinished)";
scanForTests(m_postponedFiles.toList()); scanForTests(m_postponedFiles.toList());
} else { } else {
m_dirty |= m_codeModelParsing; m_dirty |= m_codeModelParsing;
if (m_dirty) if (m_dirty) {
emit parsingFailed(); emit parsingFailed();
else if (!m_singleShotScheduled) } else if (!m_singleShotScheduled) {
qCDebug(LOG) << "emitting parsingFinished"
<< "(onPartialParsingFinished, nothing postponed, not dirty)";
emit parsingFinished(); emit parsingFinished();
} else {
qCDebug(LOG) << "not emitting parsingFinished"
<< "(on PartialParsingFinished, singleshot scheduled)";
}
} }
} }
......
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