aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2023-03-03 20:53:58 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2023-03-14 08:47:26 +0000
commit0bec769b69c660abec9ed0cc333522e4d4b0fc55 (patch)
treeb80383ee91a6f12a29274e1d5e701bb086736801 /src
parent9eb218aee74769d7f70dc08dc522daa4ea7dfc34 (diff)
QmlJS: Use QtConcurrent invocation for async run
Add ModelManagerInterface::importScan() overload to avoid instantiating dummy QPromise arg on caller side. Change-Id: Idf836d30b2167d8840cc4e7ac6f95377c9d5622a Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'src')
-rw-r--r--src/libs/qmljs/qmljsmodelmanagerinterface.cpp95
-rw-r--r--src/libs/qmljs/qmljsmodelmanagerinterface.h19
-rw-r--r--src/libs/qmljs/qmljsplugindumper.cpp22
-rw-r--r--src/plugins/autotest/quick/quicktestparser.cpp6
-rw-r--r--src/plugins/qmldesigner/components/itemlibrary/itemlibraryassetimporter.cpp4
-rw-r--r--src/plugins/qmlprofiler/tests/qmlprofilerdetailsrewriter_test.cpp3
6 files changed, 73 insertions, 76 deletions
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 <cplusplus/cppmodelmanagerbase.h>
#include <utils/algorithm.h>
+#include <utils/asynctask.h>
#include <utils/hostosinfo.h>
-#include <utils/runextensions.h>
#include <utils/stringutils.h>
#ifdef WITH_TESTS
@@ -337,11 +337,9 @@ QFuture<void> ModelManagerInterface::refreshSourceFiles(const QList<Utils::FileP
if (sourceFiles.isEmpty())
return QFuture<void>();
- QFuture<void> result = Utils::runAsync(&m_threadPool,
- &ModelManagerInterface::parse,
- workingCopyInternal(), sourceFiles,
- this, Dialect(Dialect::Qml),
- emitDocumentOnDiskChanged);
+ QFuture<void> 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<void> ModelManagerInterface::refreshSourceFiles(const QList<Utils::FileP
void ModelManagerInterface::fileChangedOnDisk(const Utils::FilePath &path)
{
- addFuture(Utils::runAsync(&m_threadPool,
- &ModelManagerInterface::parse,
- workingCopyInternal(),
- FilePaths({path}),
- this,
- Dialect(Dialect::AnyLanguage),
- true));
+ addFuture(Utils::asyncRun(&m_threadPool, &ModelManagerInterface::parse, workingCopyInternal(),
+ FilePaths({path}), this, Dialect(Dialect::AnyLanguage), true));
}
void ModelManagerInterface::removeFiles(const QList<Utils::FilePath> &files)
@@ -1044,24 +1037,24 @@ void ModelManagerInterface::parseLoop(QSet<Utils::FilePath> &scannedPaths,
class FutureReporter
{
public:
- FutureReporter(QFutureInterface<void> &future, int multiplier, int base)
- : future(future), multiplier(multiplier), base(base)
+ FutureReporter(QPromise<void> &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<void> &future;
- int multiplier;
- int base;
+ QPromise<void> &m_promise;
+ int m_multiplier;
+ int m_base;
};
-void ModelManagerInterface::parse(QFutureInterface<void> &future,
+void ModelManagerInterface::parse(QPromise<void> &promise,
const WorkingCopy &workingCopy,
QList<Utils::FilePath> files,
ModelManagerInterface *modelManager,
@@ -1069,8 +1062,8 @@ void ModelManagerInterface::parse(QFutureInterface<void> &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<Utils::FilePath> scannedPaths;
@@ -1078,7 +1071,7 @@ void ModelManagerInterface::parse(QFutureInterface<void> &future,
QSet<Utils::FilePath> 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<void> &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<void> promise;
+ promise.start();
+ importScanAsync(promise, workingCopy, paths, modelManager, emitDocChanged, libOnly, forceRescan);
+}
+
+void ModelManagerInterface::importScanAsync(QPromise<void> &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<Utils::FilePath> scannedPaths;
@@ -1118,9 +1120,9 @@ void ModelManagerInterface::importScan(QFutureInterface<void> &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<void> &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<void> &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<void> result = Utils::runAsync(&m_threadPool,
- &ModelManagerInterface::importScan,
+ QFuture<void> 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<void> &futureInterface, ModelManagerInterface *qmlModelManager,
- const CPlusPlus::Snapshot &snapshot,
+void ModelManagerInterface::updateCppQmlTypes(QPromise<void> &promise,
+ ModelManagerInterface *qmlModelManager, const CPlusPlus::Snapshot &snapshot,
const QHash<QString, QPair<CPlusPlus::Document::Ptr, bool>> &documents)
{
- futureInterface.setProgressRange(0, documents.size());
- futureInterface.setProgressValue(0);
+ promise.setProgressRange(0, documents.size());
+ promise.setProgressValue(0);
CppDataHash newData;
QHash<QString, QList<CPlusPlus::Document::Ptr>> newDeclarations;
@@ -1436,9 +1437,9 @@ void ModelManagerInterface::updateCppQmlTypes(
bool hasNewInfo = false;
using DocScanPair = QPair<CPlusPlus::Document::Ptr, bool>;
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<void> &future);
QmlJS::Document::Ptr ensuredGetDocumentForPath(const Utils::FilePath &filePath);
- static void importScan(QFutureInterface<void> &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<void> &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<bool(qreal)> &reportProgress);
- static void parse(QFutureInterface<void> &future,
+ static void parse(QPromise<void> &promise,
const WorkingCopy &workingCopyInternal,
QList<Utils::FilePath> files,
ModelManagerInterface *modelManager,
QmlJS::Dialect mainLanguage,
bool emitDocChangedOnDisk);
- static void updateCppQmlTypes(
- QFutureInterface<void> &futureInterface, ModelManagerInterface *qmlModelManager,
- const CPlusPlus::Snapshot &snapshot,
- const QHash<QString, QPair<CPlusPlus::Document::Ptr, bool>> &documents);
+ static void updateCppQmlTypes(QPromise<void> &promise, ModelManagerInterface *qmlModelManager,
+ const CPlusPlus::Snapshot &snapshot,
+ const QHash<QString, QPair<CPlusPlus::Document::Ptr, bool>> &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 <utils/algorithm.h>
+#include <utils/asynctask.h>
#include <utils/filesystemwatcher.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
@@ -273,14 +273,13 @@ void PluginDumper::qmlPluginTypeDumpDone(QtcProcess *process)
QStringList dependencies;
};
- auto future = Utils::runAsync(m_modelManager->threadPool(),
- [output, libraryPath](QFutureInterface<CppQmlTypesInfo>& future)
- {
+ auto future = Utils::asyncRun(m_modelManager->threadPool(),
+ [output, libraryPath](QPromise<CppQmlTypesInfo> &promise) {
CppQmlTypesInfo infos;
- CppQmlTypesLoader::parseQmlTypeDescriptions(output, &infos.objectsList, &infos.moduleApis, &infos.dependencies,
- &infos.error, &infos.warning,
- "<dump of " + libraryPath.toUserOutput() + '>');
- future.reportFinished(&infos);
+ CppQmlTypesLoader::parseQmlTypeDescriptions(output, &infos.objectsList,
+ &infos.moduleApis, &infos.dependencies, &infos.error, &infos.warning,
+ "<dump of " + libraryPath.toUserOutput() + '>');
+ promise.addResult(infos);
});
m_modelManager->addFuture(future);
@@ -327,8 +326,8 @@ void PluginDumper::pluginChanged(const QString &pluginLibrary)
QFuture<PluginDumper::QmlTypeDescription> PluginDumper::loadQmlTypeDescription(const FilePaths &paths) const
{
- auto future = Utils::runAsync(m_modelManager->threadPool(), [=](QFutureInterface<PluginDumper::QmlTypeDescription> &future)
- {
+ auto future = Utils::asyncRun(m_modelManager->threadPool(),
+ [=](QPromise<PluginDumper::QmlTypeDescription> &promise) {
PluginDumper::QmlTypeDescription result;
for (const FilePath &p: paths) {
@@ -355,8 +354,7 @@ QFuture<PluginDumper::QmlTypeDescription> 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<Document::Ptr> 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<void> 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<void> 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 <qmljs/qmljsmodelmanagerinterface.h>
#include <utils/algorithm.h>
-#include <utils/runextensions.h>
+#include <utils/asynctask.h>
#include <utils/qtcassert.h>
#include <QApplication>
@@ -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<void> 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);