diff --git a/src/plugins/autotest/autotestplugin.cpp b/src/plugins/autotest/autotestplugin.cpp index 226f0f26c62..571af4ba08d 100644 --- a/src/plugins/autotest/autotestplugin.cpp +++ b/src/plugins/autotest/autotestplugin.cpp @@ -114,8 +114,9 @@ void AutotestPlugin::initializeMenuEntries() action = new QAction(tr("Re&scan Tests"), this); command = ActionManager::registerAction(action, Constants::ACTION_SCAN_ID); command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+S"))); - connect(action, &QAction::triggered, - TestTreeModel::instance()->parser(), &TestCodeParser::updateTestTree); + connect(action, &QAction::triggered, [this] () { + TestTreeModel::instance()->parser()->updateTestTree(); + }); menu->addAction(command); ActionContainer *toolsMenu = ActionManager::actionContainer(Core::Constants::M_TOOLS); diff --git a/src/plugins/autotest/quick/quicktestparser.cpp b/src/plugins/autotest/quick/quicktestparser.cpp index e79af5dea47..c7d375b1f2d 100644 --- a/src/plugins/autotest/quick/quicktestparser.cpp +++ b/src/plugins/autotest/quick/quicktestparser.cpp @@ -28,16 +28,22 @@ #include "quicktestvisitors.h" #include "quicktest_utils.h" #include "../autotest_utils.h" +#include "../testcodeparser.h" +#include #include #include #include #include #include +#include + namespace Autotest { namespace Internal { +static QFileSystemWatcher s_directoryWatcher; + TestTreeItem *QuickTestParseResult::createTestTreeItem() const { if (itemType == TestTreeItem::Root || itemType == TestTreeItem::TestDataTag) @@ -140,6 +146,8 @@ static QList scanDirectoryForQuickTestQmlFiles(const QStri QFileInfo fi(it.fileInfo().canonicalFilePath()); dirs << fi.filePath(); } + s_directoryWatcher.addPaths(dirs); + QList foundDocs; for (const QString &path : dirs) { @@ -227,6 +235,27 @@ static bool handleQtQuickTest(QFutureInterface futureInterfa return result; } +QuickTestParser::QuickTestParser() + : CppParser() +{ + QObject::connect(ProjectExplorer::SessionManager::instance(), + &ProjectExplorer::SessionManager::startupProjectChanged, [] { + const QStringList &dirs = s_directoryWatcher.directories(); + if (!dirs.isEmpty()) + s_directoryWatcher.removePaths(dirs); + }); + QObject::connect(&s_directoryWatcher, &QFileSystemWatcher::directoryChanged, + [this] { TestTreeModel::instance()->parser()->emitUpdateTestTree(this); }); +} + +QuickTestParser::~QuickTestParser() +{ + QObject::disconnect(&s_directoryWatcher, 0, 0, 0); + const QStringList &dirs = s_directoryWatcher.directories(); + if (!dirs.isEmpty()) + s_directoryWatcher.removePaths(dirs); +} + void QuickTestParser::init(const QStringList &filesToParse) { m_qmlSnapshot = QmlJSTools::Internal::ModelManager::instance()->snapshot(); diff --git a/src/plugins/autotest/quick/quicktestparser.h b/src/plugins/autotest/quick/quicktestparser.h index 2d2e1c866be..9258599e717 100644 --- a/src/plugins/autotest/quick/quicktestparser.h +++ b/src/plugins/autotest/quick/quicktestparser.h @@ -42,6 +42,8 @@ public: class QuickTestParser : public CppParser { public: + QuickTestParser(); + virtual ~QuickTestParser(); void init(const QStringList &filesToParse) override; void release() override; bool processDocument(QFutureInterface futureInterface, diff --git a/src/plugins/autotest/testcodeparser.cpp b/src/plugins/autotest/testcodeparser.cpp index 5ac939bdfa1..8707da8a1c4 100644 --- a/src/plugins/autotest/testcodeparser.cpp +++ b/src/plugins/autotest/testcodeparser.cpp @@ -131,7 +131,7 @@ void TestCodeParser::syncTestFrameworks(const QVector &frameworkIds) updateTestTree(); } -void TestCodeParser::emitUpdateTestTree() +void TestCodeParser::emitUpdateTestTree(ITestParser *parser) { if (m_testCodeParsers.isEmpty()) return; @@ -142,10 +142,10 @@ void TestCodeParser::emitUpdateTestTree() qCDebug(LOG) << "adding singleShot"; m_singleShotScheduled = true; - QTimer::singleShot(1000, this, &TestCodeParser::updateTestTree); + QTimer::singleShot(1000, this, [this, parser](){ updateTestTree(parser); }); } -void TestCodeParser::updateTestTree() +void TestCodeParser::updateTestTree(ITestParser *parser) { m_singleShotScheduled = false; if (m_codeModelParsing) { @@ -160,7 +160,7 @@ void TestCodeParser::updateTestTree() m_fullUpdatePostponed = false; qCDebug(LOG) << "calling scanForTests (updateTestTree)"; - scanForTests(); + scanForTests(QStringList(), parser); } static QStringList filterFiles(const QString &projectDir, const QStringList &files) @@ -315,7 +315,7 @@ static void parseFileForTests(const QVector &parsers, } } -void TestCodeParser::scanForTests(const QStringList &fileList) +void TestCodeParser::scanForTests(const QStringList &fileList, ITestParser *parser) { if (m_parserState == Shutdown || m_testCodeParsers.isEmpty()) return; @@ -355,7 +355,14 @@ void TestCodeParser::scanForTests(const QStringList &fileList) list = Utils::filtered(list, [] (const QString &fn) { return !fn.endsWith(".qml"); }); - m_model->markAllForRemoval(); + if (parser) + TestFrameworkManager::instance()->rootNodeForTestFramework(parser->id())->markForRemovalRecursively(true); + else + m_model->markAllForRemoval(); + } else if (parser) { + TestTreeItem *root = TestFrameworkManager::instance()->rootNodeForTestFramework(parser->id()); + for (const QString &filePath : list) + root->markForRemovalRecursively(filePath); } else { for (const QString &filePath : list) m_model->markForRemoval(filePath); @@ -372,13 +379,20 @@ void TestCodeParser::scanForTests(const QStringList &fileList) onFinished(); return; } + + // use only a single parser or all current active? + QVector codeParsers; + if (parser) + codeParsers.append(parser); + else + codeParsers.append(m_testCodeParsers); qCDebug(LOG) << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "StartParsing"; - for (ITestParser *parser : m_testCodeParsers) + for (ITestParser *parser : codeParsers) parser->init(list); QFuture future = Utils::map(list, - [this](QFutureInterface &fi, const QString &file) { - parseFileForTests(m_testCodeParsers, fi, file); + [this, codeParsers](QFutureInterface &fi, const QString &file) { + parseFileForTests(codeParsers, fi, file); }, Utils::MapReduceOption::Unordered, QThread::LowestPriority); diff --git a/src/plugins/autotest/testcodeparser.h b/src/plugins/autotest/testcodeparser.h index 8f9cc0a4fd4..55a381139b9 100644 --- a/src/plugins/autotest/testcodeparser.h +++ b/src/plugins/autotest/testcodeparser.h @@ -72,8 +72,8 @@ signals: void parsingFailed(); public: - void emitUpdateTestTree(); - void updateTestTree(); + void emitUpdateTestTree(ITestParser *parser = nullptr); + void updateTestTree(ITestParser *parser = nullptr); void onCppDocumentUpdated(const CPlusPlus::Document::Ptr &document); void onQmlDocumentUpdated(const QmlJS::Document::Ptr &document); void onStartupProjectChanged(ProjectExplorer::Project *project); @@ -82,7 +82,7 @@ public: private: bool postponed(const QStringList &fileList); - void scanForTests(const QStringList &fileList = QStringList()); + void scanForTests(const QStringList &fileList = QStringList(), ITestParser *parser = nullptr); void onDocumentUpdated(const QString &fileName); void onTaskStarted(Core::Id type);