diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp index 3d2fc32120b..f6c84fb88f4 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp @@ -15,8 +15,8 @@ #include #include +#include #include -#include #include #ifdef WITH_TESTS @@ -337,11 +337,9 @@ QFuture ModelManagerInterface::refreshSourceFiles(const QList(); - QFuture result = Utils::runAsync(&m_threadPool, - &ModelManagerInterface::parse, - workingCopyInternal(), sourceFiles, - this, Dialect(Dialect::Qml), - emitDocumentOnDiskChanged); + QFuture result = Utils::asyncRun(&m_threadPool, &ModelManagerInterface::parse, + workingCopyInternal(), sourceFiles, this, + Dialect(Dialect::Qml), emitDocumentOnDiskChanged); addFuture(result); if (sourceFiles.count() > 1) @@ -365,13 +363,8 @@ QFuture ModelManagerInterface::refreshSourceFiles(const QList &files) @@ -1044,24 +1037,24 @@ void ModelManagerInterface::parseLoop(QSet &scannedPaths, class FutureReporter { public: - FutureReporter(QFutureInterface &future, int multiplier, int base) - : future(future), multiplier(multiplier), base(base) + FutureReporter(QPromise &promise, int multiplier, int base) + : m_promise(promise), m_multiplier(multiplier), m_base(base) {} bool operator()(qreal val) { - if (future.isCanceled()) + if (m_promise.isCanceled()) return false; - future.setProgressValue(int(base + multiplier * val)); + m_promise.setProgressValue(int(m_base + m_multiplier * val)); return true; } private: - QFutureInterface &future; - int multiplier; - int base; + QPromise &m_promise; + int m_multiplier; + int m_base; }; -void ModelManagerInterface::parse(QFutureInterface &future, +void ModelManagerInterface::parse(QPromise &promise, const WorkingCopy &workingCopy, QList files, ModelManagerInterface *modelManager, @@ -1069,8 +1062,8 @@ void ModelManagerInterface::parse(QFutureInterface &future, bool emitDocChangedOnDisk) { const int progressMax = 100; - FutureReporter reporter(future, progressMax, 0); - future.setProgressRange(0, progressMax); + FutureReporter reporter(promise, progressMax, 0); + promise.setProgressRange(0, progressMax); // paths we have scanned for files and added to the files list QSet scannedPaths; @@ -1078,7 +1071,7 @@ void ModelManagerInterface::parse(QFutureInterface &future, QSet newLibraries; parseLoop(scannedPaths, newLibraries, workingCopy, std::move(files), modelManager, mainLanguage, emitDocChangedOnDisk, reporter); - future.setProgressValue(progressMax); + promise.setProgressValue(progressMax); } struct ScanItem { @@ -1087,11 +1080,20 @@ struct ScanItem { Dialect language = Dialect::AnyLanguage; }; -void ModelManagerInterface::importScan(QFutureInterface &future, - const ModelManagerInterface::WorkingCopy &workingCopy, +void ModelManagerInterface::importScan(const WorkingCopy &workingCopy, const PathsAndLanguages &paths, ModelManagerInterface *modelManager, - bool emitDocChangedOnDisk, bool libOnly, bool forceRescan) + bool emitDocChanged, bool libOnly, bool forceRescan) +{ + QPromise promise; + promise.start(); + importScanAsync(promise, workingCopy, paths, modelManager, emitDocChanged, libOnly, forceRescan); +} + +void ModelManagerInterface::importScanAsync(QPromise &promise, const WorkingCopy &workingCopy, + const PathsAndLanguages &paths, + ModelManagerInterface *modelManager, + bool emitDocChanged, bool libOnly, bool forceRescan) { // paths we have scanned for files and added to the files list QSet scannedPaths; @@ -1118,9 +1120,9 @@ void ModelManagerInterface::importScan(QFutureInterface &future, int progressRange = pathsToScan.size() * (1 << (2 + maxScanDepth)); int totalWork = progressRange; int workDone = 0; - future.setProgressRange(0, progressRange); // update max length while iterating? + promise.setProgressRange(0, progressRange); // update max length while iterating? const Snapshot snapshot = modelManager->snapshot(); - bool isCanceled = future.isCanceled(); + bool isCanceled = promise.isCanceled(); while (!pathsToScan.isEmpty() && !isCanceled) { ScanItem toScan = pathsToScan.last(); pathsToScan.pop_back(); @@ -1135,16 +1137,16 @@ void ModelManagerInterface::importScan(QFutureInterface &future, toScan.language.companionLanguages()); } workDone += 1; - future.setProgressValue(progressRange * workDone / totalWork); + promise.setProgressValue(progressRange * workDone / totalWork); if (!importedFiles.isEmpty()) { - FutureReporter reporter(future, progressRange * pathBudget / (4 * totalWork), + FutureReporter reporter(promise, progressRange * pathBudget / (4 * totalWork), progressRange * workDone / totalWork); parseLoop(scannedPaths, newLibraries, workingCopy, importedFiles, modelManager, - toScan.language, emitDocChangedOnDisk, reporter); // run in parallel?? + toScan.language, emitDocChanged, reporter); // run in parallel?? importedFiles.clear(); } workDone += pathBudget / 4 - 1; - future.setProgressValue(progressRange * workDone / totalWork); + promise.setProgressValue(progressRange * workDone / totalWork); } else { workDone += pathBudget / 4; } @@ -1159,10 +1161,10 @@ void ModelManagerInterface::importScan(QFutureInterface &future, } else { workDone += pathBudget * 3 / 4; } - future.setProgressValue(progressRange * workDone / totalWork); - isCanceled = future.isCanceled(); + promise.setProgressValue(progressRange * workDone / totalWork); + isCanceled = promise.isCanceled(); } - future.setProgressValue(progressRange); + promise.setProgressValue(progressRange); if (isCanceled) { // assume no work has been done QMutexLocker l(&modelManager->m_mutex); @@ -1206,8 +1208,8 @@ void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths) } if (pathToScan.length() >= 1) { - QFuture result = Utils::runAsync(&m_threadPool, - &ModelManagerInterface::importScan, + QFuture result = Utils::asyncRun(&m_threadPool, + &ModelManagerInterface::importScanAsync, workingCopyInternal(), pathToScan, this, true, true, false); addFuture(result); @@ -1373,8 +1375,8 @@ void ModelManagerInterface::startCppQmlTypeUpdate() if (!cppModelManager) return; - m_cppQmlTypesUpdater = Utils::runAsync(&ModelManagerInterface::updateCppQmlTypes, - this, cppModelManager->snapshot(), m_queuedCppDocuments); + m_cppQmlTypesUpdater = Utils::asyncRun(&ModelManagerInterface::updateCppQmlTypes, this, + cppModelManager->snapshot(), m_queuedCppDocuments); m_queuedCppDocuments.clear(); } @@ -1415,13 +1417,12 @@ bool rescanExports(const QString &fileName, FindExportedCppTypes &finder, return hasNewInfo; } -void ModelManagerInterface::updateCppQmlTypes( - QFutureInterface &futureInterface, ModelManagerInterface *qmlModelManager, - const CPlusPlus::Snapshot &snapshot, +void ModelManagerInterface::updateCppQmlTypes(QPromise &promise, + ModelManagerInterface *qmlModelManager, const CPlusPlus::Snapshot &snapshot, const QHash> &documents) { - futureInterface.setProgressRange(0, documents.size()); - futureInterface.setProgressValue(0); + promise.setProgressRange(0, documents.size()); + promise.setProgressValue(0); CppDataHash newData; QHash> newDeclarations; @@ -1436,9 +1437,9 @@ void ModelManagerInterface::updateCppQmlTypes( bool hasNewInfo = false; using DocScanPair = QPair; for (const DocScanPair &pair : documents) { - if (futureInterface.isCanceled()) + if (promise.isCanceled()) return; - futureInterface.setProgressValue(futureInterface.progressValue() + 1); + promise.setProgressValue(promise.future().progressValue() + 1); CPlusPlus::Document::Ptr doc = pair.first; const bool scan = pair.second; diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.h b/src/libs/qmljs/qmljsmodelmanagerinterface.h index b7b88c24ff5..e702b91afbb 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.h +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.h @@ -179,10 +179,12 @@ public: void addFuture(const QFuture &future); QmlJS::Document::Ptr ensuredGetDocumentForPath(const Utils::FilePath &filePath); - static void importScan(QFutureInterface &future, const WorkingCopy& workingCopyInternal, - const PathsAndLanguages& paths, ModelManagerInterface *modelManager, - bool emitDocChangedOnDisk, bool libOnly = true, - bool forceRescan = false); + static void importScan(const WorkingCopy &workingCopy, const PathsAndLanguages &paths, + ModelManagerInterface *modelManager, bool emitDocChanged, + bool libOnly = true, bool forceRescan = false); + static void importScanAsync(QPromise &promise, const WorkingCopy& workingCopyInternal, + const PathsAndLanguages& paths, ModelManagerInterface *modelManager, + bool emitDocChanged, bool libOnly = true, bool forceRescan = false); virtual void resetCodeModel(); void removeProjectInfo(ProjectExplorer::Project *project); @@ -218,16 +220,15 @@ protected: QmlJS::Dialect mainLanguage, bool emitDocChangedOnDisk, const std::function &reportProgress); - static void parse(QFutureInterface &future, + static void parse(QPromise &promise, const WorkingCopy &workingCopyInternal, QList files, ModelManagerInterface *modelManager, QmlJS::Dialect mainLanguage, bool emitDocChangedOnDisk); - static void updateCppQmlTypes( - QFutureInterface &futureInterface, ModelManagerInterface *qmlModelManager, - const CPlusPlus::Snapshot &snapshot, - const QHash> &documents); + static void updateCppQmlTypes(QPromise &promise, ModelManagerInterface *qmlModelManager, + const CPlusPlus::Snapshot &snapshot, + const QHash> &documents); void maybeScan(const PathsAndLanguages &importPaths); void updateImportPaths(); diff --git a/src/libs/qmljs/qmljsplugindumper.cpp b/src/libs/qmljs/qmljsplugindumper.cpp index a7bafdde948..20736803d27 100644 --- a/src/libs/qmljs/qmljsplugindumper.cpp +++ b/src/libs/qmljs/qmljsplugindumper.cpp @@ -7,9 +7,9 @@ #include "qmljsmodelmanagerinterface.h" #include "qmljstr.h" #include "qmljsutils.h" -#include "qmljsviewercontext.h" #include +#include #include #include #include @@ -273,14 +273,13 @@ void PluginDumper::qmlPluginTypeDumpDone(QtcProcess *process) QStringList dependencies; }; - auto future = Utils::runAsync(m_modelManager->threadPool(), - [output, libraryPath](QFutureInterface& future) - { + auto future = Utils::asyncRun(m_modelManager->threadPool(), + [output, libraryPath](QPromise &promise) { CppQmlTypesInfo infos; - CppQmlTypesLoader::parseQmlTypeDescriptions(output, &infos.objectsList, &infos.moduleApis, &infos.dependencies, - &infos.error, &infos.warning, - "'); - future.reportFinished(&infos); + CppQmlTypesLoader::parseQmlTypeDescriptions(output, &infos.objectsList, + &infos.moduleApis, &infos.dependencies, &infos.error, &infos.warning, + "'); + promise.addResult(infos); }); m_modelManager->addFuture(future); @@ -327,8 +326,8 @@ void PluginDumper::pluginChanged(const QString &pluginLibrary) QFuture PluginDumper::loadQmlTypeDescription(const FilePaths &paths) const { - auto future = Utils::runAsync(m_modelManager->threadPool(), [=](QFutureInterface &future) - { + auto future = Utils::asyncRun(m_modelManager->threadPool(), + [=](QPromise &promise) { PluginDumper::QmlTypeDescription result; for (const FilePath &p: paths) { @@ -355,8 +354,7 @@ QFuture PluginDumper::loadQmlTypeDescription(c if (!warning.isEmpty()) result.warnings += warning; } - - future.reportFinished(&result); + promise.addResult(result); }); m_modelManager->addFuture(future); diff --git a/src/plugins/autotest/quick/quicktestparser.cpp b/src/plugins/autotest/quick/quicktestparser.cpp index 09965a099a4..de0003b2ffc 100644 --- a/src/plugins/autotest/quick/quicktestparser.cpp +++ b/src/plugins/autotest/quick/quicktestparser.cpp @@ -160,10 +160,9 @@ QList QuickTestParser::scanDirectoryForQuickTestQmlFiles(const Fi QStringList dirsStr({srcDir.toString()}); ModelManagerInterface *qmlJsMM = QmlJSTools::Internal::ModelManager::instance(); // make sure even files not listed in pro file are available inside the snapshot - QFutureInterface future; PathsAndLanguages paths; paths.maybeInsert(srcDir, Dialect::Qml); - ModelManagerInterface::importScan(future, ModelManagerInterface::workingCopy(), paths, qmlJsMM, + ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), paths, qmlJsMM, false /*emitDocumentChanges*/, false /*onlyTheLib*/, true /*forceRescan*/ ); const Snapshot snapshot = QmlJSTools::Internal::ModelManager::instance()->snapshot(); @@ -307,9 +306,8 @@ void QuickTestParser::handleDirectoryChanged(const QString &directory) m_watchedFiles[directory] = filesAndDates; PathsAndLanguages paths; paths.maybeInsert(FilePath::fromString(directory), Dialect::Qml); - QFutureInterface future; ModelManagerInterface *qmlJsMM = ModelManagerInterface::instance(); - ModelManagerInterface::importScan(future, ModelManagerInterface::workingCopy(), paths, + ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), paths, qmlJsMM, true /*emitDocumentChanges*/, false /*onlyTheLib*/, diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryassetimporter.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryassetimporter.cpp index d9b82419433..cca5ed47b31 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibraryassetimporter.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibraryassetimporter.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include @@ -684,7 +684,7 @@ void ItemLibraryAssetImporter::finalizeQuick3DImport() if (modelManager) { QmlJS::PathsAndLanguages pathToScan; pathToScan.maybeInsert(Utils::FilePath::fromString(m_importPath)); - result = Utils::runAsync(&QmlJS::ModelManagerInterface::importScan, + result = Utils::asyncRun(&QmlJS::ModelManagerInterface::importScan, modelManager->workingCopy(), pathToScan, modelManager, true, true, true); } diff --git a/src/plugins/qmlprofiler/tests/qmlprofilerdetailsrewriter_test.cpp b/src/plugins/qmlprofiler/tests/qmlprofilerdetailsrewriter_test.cpp index ad787e05a5e..d71836319cc 100644 --- a/src/plugins/qmlprofiler/tests/qmlprofilerdetailsrewriter_test.cpp +++ b/src/plugins/qmlprofiler/tests/qmlprofilerdetailsrewriter_test.cpp @@ -175,12 +175,11 @@ void QmlProfilerDetailsRewriterTest::seedRewriter() m_modelManager = new QmlJS::ModelManagerInterface(this); QString filename = ":/qmlprofiler/tests/Test.qml"; - QFutureInterface result; QmlJS::PathsAndLanguages lPaths; lPaths.maybeInsert( Utils::FilePath::fromString(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath)), QmlJS::Dialect::Qml); - QmlJS::ModelManagerInterface::importScan(result, QmlJS::ModelManagerInterface::workingCopy(), + QmlJS::ModelManagerInterface::importScan(QmlJS::ModelManagerInterface::workingCopy(), lPaths, m_modelManager, false); QFile file(filename); diff --git a/tests/auto/qml/codemodel/check/tst_check.cpp b/tests/auto/qml/codemodel/check/tst_check.cpp index 46542b8bf8f..56ccdfd2a37 100644 --- a/tests/auto/qml/codemodel/check/tst_check.cpp +++ b/tests/auto/qml/codemodel/check/tst_check.cpp @@ -72,12 +72,11 @@ void tst_Check::initTestCase() new ExtensionSystem::PluginManager; ModelManagerInterface *modelManager = ModelManagerInterface::instance(); - QFutureInterface result; PathsAndLanguages lPaths; QStringList paths(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath)); for (auto p: paths) lPaths.maybeInsert(Utils::FilePath::fromString(p), Dialect::Qml); - ModelManagerInterface::importScan(result, ModelManagerInterface::workingCopy(), lPaths, + ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), lPaths, modelManager, false); modelManager->test_joinAllThreads(); } diff --git a/tests/auto/qml/codemodel/dependencies/tst_dependencies.cpp b/tests/auto/qml/codemodel/dependencies/tst_dependencies.cpp index 1a09449c114..48f8d7ce6cf 100644 --- a/tests/auto/qml/codemodel/dependencies/tst_dependencies.cpp +++ b/tests/auto/qml/codemodel/dependencies/tst_dependencies.cpp @@ -122,13 +122,12 @@ void tst_Dependencies::test() ModelManagerInterface *modelManager = ModelManagerInterface::instance(); - QFutureInterface result; PathsAndLanguages lPaths; QStringList paths(m_basePaths); paths << m_path; for (auto p: paths) lPaths.maybeInsert(Utils::FilePath::fromString(p), Dialect::Qml); - ModelManagerInterface::importScan(result, ModelManagerInterface::workingCopy(), lPaths, + ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), lPaths, ModelManagerInterface::instance(), false); ModelManagerInterface::instance()->test_joinAllThreads(); TestData data = testData(filename); diff --git a/tests/auto/qml/codemodel/ecmascript7/tst_ecmascript7.cpp b/tests/auto/qml/codemodel/ecmascript7/tst_ecmascript7.cpp index 9ca768cbeee..4f86e3ba988 100644 --- a/tests/auto/qml/codemodel/ecmascript7/tst_ecmascript7.cpp +++ b/tests/auto/qml/codemodel/ecmascript7/tst_ecmascript7.cpp @@ -149,12 +149,11 @@ void tst_Ecmascript::test() ModelManagerInterface *modelManager = ModelManagerInterface::instance(); - QFutureInterface result; PathsAndLanguages lPaths; QStringList paths(m_basePaths); for (auto p: paths) lPaths.maybeInsert(Utils::FilePath::fromString(p), Dialect::Qml); - ModelManagerInterface::importScan(result, ModelManagerInterface::workingCopy(), lPaths, + ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), lPaths, ModelManagerInterface::instance(), false); TestData data = testData(filename); diff --git a/tests/auto/qml/codemodel/importscheck/tst_importscheck.cpp b/tests/auto/qml/codemodel/importscheck/tst_importscheck.cpp index 5cad7930e8f..e47c77db482 100644 --- a/tests/auto/qml/codemodel/importscheck/tst_importscheck.cpp +++ b/tests/auto/qml/codemodel/importscheck/tst_importscheck.cpp @@ -51,10 +51,9 @@ private: void scanDirectory(const QString &dir) { auto dirPath = Utils::FilePath::fromString(dir); - QFutureInterface result; PathsAndLanguages paths; paths.maybeInsert(dirPath, Dialect::Qml); - ModelManagerInterface::importScan(result, ModelManagerInterface::workingCopy(), paths, + ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), paths, ModelManagerInterface::instance(), false); ModelManagerInterface::instance()->test_joinAllThreads(); ViewerContext vCtx; @@ -170,11 +169,10 @@ void tst_ImportCheck::test() const auto pathPaths = Utils::transform(paths, [](const QString &s) { return Utils::FilePath::fromString(s); }); - QFutureInterface result; PathsAndLanguages lPaths; for (const Utils::FilePath &path : pathPaths) lPaths.maybeInsert(path, Dialect::Qml); - ModelManagerInterface::importScan(result, ModelManagerInterface::workingCopy(), lPaths, + ModelManagerInterface::importScan(ModelManagerInterface::workingCopy(), lPaths, ModelManagerInterface::instance(), false); ModelManagerInterface::instance()->test_joinAllThreads(); ViewerContext vCtx; diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp index d6e62263807..f483e1d09dc 100644 --- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp @@ -233,12 +233,10 @@ void tst_TestCore::initTestCase() QStringList basePaths; basePaths.append(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath)); - - QFutureInterface result; QmlJS::PathsAndLanguages lPaths; lPaths.maybeInsert(Utils::FilePath::fromString(basePaths.first()), QmlJS::Dialect::Qml); - QmlJS::ModelManagerInterface::importScan(result, QmlJS::ModelManagerInterface::workingCopy(), + QmlJS::ModelManagerInterface::importScan(QmlJS::ModelManagerInterface::workingCopy(), lPaths, QmlJS::ModelManagerInterface::instance(), false); // Load plugins