forked from qt-creator/qt-creator
CppEditor: Use QtConcurrent invocation for async run
Change-Id: Ibbac7f7788fe966c0dd846d68b7d17c43acadb0e Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -59,15 +59,15 @@ void BaseEditorDocumentParser::setConfiguration(const Configuration &configurati
|
||||
|
||||
void BaseEditorDocumentParser::update(const UpdateParams &updateParams)
|
||||
{
|
||||
QFutureInterface<void> dummy;
|
||||
QPromise<void> dummy;
|
||||
update(dummy, updateParams);
|
||||
}
|
||||
|
||||
void BaseEditorDocumentParser::update(const QFutureInterface<void> &future,
|
||||
void BaseEditorDocumentParser::update(const QPromise<void> &promise,
|
||||
const UpdateParams &updateParams)
|
||||
{
|
||||
QMutexLocker locker(&m_updateIsRunning);
|
||||
updateImpl(future, updateParams);
|
||||
updateImpl(promise, updateParams);
|
||||
}
|
||||
|
||||
BaseEditorDocumentParser::State BaseEditorDocumentParser::state() const
|
||||
|
||||
@@ -6,14 +6,17 @@
|
||||
#include "cppeditor_global.h"
|
||||
#include "cpptoolsreuse.h"
|
||||
#include "cppworkingcopy.h"
|
||||
#include "projectpart.h"
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
|
||||
#include <QFutureInterface>
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
template <typename T>
|
||||
class QPromise;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace ProjectExplorer { class Project; }
|
||||
|
||||
namespace CppEditor {
|
||||
@@ -66,7 +69,7 @@ public:
|
||||
void setConfiguration(const Configuration &configuration);
|
||||
|
||||
void update(const UpdateParams &updateParams);
|
||||
void update(const QFutureInterface<void> &future, const UpdateParams &updateParams);
|
||||
void update(const QPromise<void> &promise, const UpdateParams &updateParams);
|
||||
|
||||
ProjectPartInfo projectPartInfo() const;
|
||||
|
||||
@@ -91,7 +94,7 @@ protected:
|
||||
mutable QMutex m_stateAndConfigurationMutex;
|
||||
|
||||
private:
|
||||
virtual void updateImpl(const QFutureInterface<void> &future,
|
||||
virtual void updateImpl(const QPromise<void> &promise,
|
||||
const UpdateParams &updateParams) = 0;
|
||||
|
||||
const Utils::FilePath m_filePath;
|
||||
|
||||
@@ -59,20 +59,20 @@ void BaseEditorDocumentProcessor::setParserConfig(
|
||||
parser()->setConfiguration(config);
|
||||
}
|
||||
|
||||
void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
|
||||
void BaseEditorDocumentProcessor::runParser(QPromise<void> &promise,
|
||||
BaseEditorDocumentParser::Ptr parser,
|
||||
BaseEditorDocumentParser::UpdateParams updateParams)
|
||||
{
|
||||
future.setProgressRange(0, 1);
|
||||
if (future.isCanceled()) {
|
||||
future.setProgressValue(1);
|
||||
promise.setProgressRange(0, 1);
|
||||
if (promise.isCanceled()) {
|
||||
promise.setProgressValue(1);
|
||||
return;
|
||||
}
|
||||
|
||||
parser->update(future, updateParams);
|
||||
parser->update(promise, updateParams);
|
||||
CppModelManager::instance()->finishedRefreshingSourceFiles({parser->filePath().toString()});
|
||||
|
||||
future.setProgressValue(1);
|
||||
promise.setProgressValue(1);
|
||||
}
|
||||
|
||||
} // namespace CppEditor
|
||||
|
||||
@@ -83,7 +83,7 @@ signals:
|
||||
void semanticInfoUpdated(const SemanticInfo semanticInfo); // TODO: Remove me
|
||||
|
||||
protected:
|
||||
static void runParser(QFutureInterface<void> &future,
|
||||
static void runParser(QPromise<void> &promise,
|
||||
BaseEditorDocumentParser::Ptr parser,
|
||||
BaseEditorDocumentParser::UpdateParams updateParams);
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
#include <cplusplus/Macro.h>
|
||||
#include <cplusplus/TranslationUnit.h>
|
||||
|
||||
#include <utils/textutils.h>
|
||||
#include <utils/asynctask.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/textutils.h>
|
||||
|
||||
#include <QTextBlock>
|
||||
|
||||
@@ -322,7 +322,7 @@ QFuture<CursorInfo> BuiltinCursorInfo::run(const CursorInfoParams &cursorInfoPar
|
||||
QString expression;
|
||||
Scope *scope = canonicalSymbol.getScopeAndExpression(textCursor, &expression);
|
||||
|
||||
return Utils::runAsync(&FindUses::find, document, snapshot, line, column, scope, expression);
|
||||
return Utils::asyncRun(&FindUses::find, document, snapshot, line, column, scope, expression);
|
||||
}
|
||||
|
||||
SemanticInfo::LocalUseMap
|
||||
|
||||
@@ -42,7 +42,7 @@ BuiltinEditorDocumentParser::BuiltinEditorDocumentParser(const FilePath &filePat
|
||||
qRegisterMetaType<CPlusPlus::Snapshot>("CPlusPlus::Snapshot");
|
||||
}
|
||||
|
||||
void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &future,
|
||||
void BuiltinEditorDocumentParser::updateImpl(const QPromise<void> &promise,
|
||||
const UpdateParams &updateParams)
|
||||
{
|
||||
if (filePath().isEmpty())
|
||||
@@ -180,7 +180,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
|
||||
doc->releaseSourceAndAST();
|
||||
});
|
||||
sourceProcessor.setFileSizeLimitInMb(m_fileSizeLimitInMb);
|
||||
sourceProcessor.setCancelChecker([future]() { return future.isCanceled(); });
|
||||
sourceProcessor.setCancelChecker([&promise] { return promise.isCanceled(); });
|
||||
|
||||
Snapshot globalSnapshot = modelManager->snapshot();
|
||||
globalSnapshot.remove(filePath());
|
||||
|
||||
@@ -34,8 +34,7 @@ public:
|
||||
static Ptr get(const Utils::FilePath &filePath);
|
||||
|
||||
private:
|
||||
void updateImpl(const QFutureInterface<void> &future,
|
||||
const UpdateParams &updateParams) override;
|
||||
void updateImpl(const QPromise<void> &promise, const UpdateParams &updateParams) override;
|
||||
void addFileAndDependencies(CPlusPlus::Snapshot *snapshot,
|
||||
QSet<Utils::FilePath> *toRemove,
|
||||
const Utils::FilePath &fileName) const;
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <cplusplus/SimpleLexer.h>
|
||||
|
||||
#include <utils/textutils.h>
|
||||
#include <utils/asynctask.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/textutils.h>
|
||||
|
||||
#include <QLoggingCategory>
|
||||
#include <QTextBlock>
|
||||
@@ -180,10 +180,8 @@ BuiltinEditorDocumentProcessor::~BuiltinEditorDocumentProcessor()
|
||||
void BuiltinEditorDocumentProcessor::runImpl(
|
||||
const BaseEditorDocumentParser::UpdateParams &updateParams)
|
||||
{
|
||||
m_parserFuture = Utils::runAsync(CppModelManager::instance()->sharedThreadPool(),
|
||||
runParser,
|
||||
parser(),
|
||||
updateParams);
|
||||
m_parserFuture = Utils::asyncRun(CppModelManager::instance()->sharedThreadPool(),
|
||||
runParser, parser(), updateParams);
|
||||
}
|
||||
|
||||
BaseEditorDocumentParser::Ptr BuiltinEditorDocumentProcessor::parser()
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
#include <texteditor/basefilefind.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/asynctask.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/textfileformat.h>
|
||||
|
||||
#include <QtConcurrentMap>
|
||||
@@ -220,7 +220,7 @@ class ProcessFile
|
||||
const CPlusPlus::Snapshot snapshot;
|
||||
CPlusPlus::Document::Ptr symbolDocument;
|
||||
CPlusPlus::Symbol *symbol;
|
||||
QFutureInterface<CPlusPlus::Usage> *future;
|
||||
QPromise<CPlusPlus::Usage> *m_promise;
|
||||
const bool categorize;
|
||||
|
||||
public:
|
||||
@@ -232,22 +232,21 @@ public:
|
||||
const CPlusPlus::Snapshot snapshot,
|
||||
CPlusPlus::Document::Ptr symbolDocument,
|
||||
CPlusPlus::Symbol *symbol,
|
||||
QFutureInterface<CPlusPlus::Usage> *future,
|
||||
QPromise<CPlusPlus::Usage> *promise,
|
||||
bool categorize)
|
||||
: workingCopy(workingCopy),
|
||||
snapshot(snapshot),
|
||||
symbolDocument(symbolDocument),
|
||||
symbol(symbol),
|
||||
future(future),
|
||||
m_promise(promise),
|
||||
categorize(categorize)
|
||||
{ }
|
||||
|
||||
QList<CPlusPlus::Usage> operator()(const Utils::FilePath &filePath)
|
||||
{
|
||||
QList<CPlusPlus::Usage> usages;
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
if (future->isCanceled())
|
||||
m_promise->suspendIfRequested();
|
||||
if (m_promise->isCanceled())
|
||||
return usages;
|
||||
const CPlusPlus::Identifier *symbolId = symbol->identifier();
|
||||
|
||||
@@ -277,25 +276,24 @@ public:
|
||||
usages = process.usages();
|
||||
}
|
||||
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
m_promise->suspendIfRequested();
|
||||
return usages;
|
||||
}
|
||||
};
|
||||
|
||||
class UpdateUI
|
||||
{
|
||||
QFutureInterface<CPlusPlus::Usage> *future;
|
||||
QPromise<CPlusPlus::Usage> *m_promise;
|
||||
|
||||
public:
|
||||
explicit UpdateUI(QFutureInterface<CPlusPlus::Usage> *future): future(future) {}
|
||||
explicit UpdateUI(QPromise<CPlusPlus::Usage> *promise): m_promise(promise) {}
|
||||
|
||||
void operator()(QList<CPlusPlus::Usage> &, const QList<CPlusPlus::Usage> &usages)
|
||||
{
|
||||
for (const CPlusPlus::Usage &u : usages)
|
||||
future->reportResult(u);
|
||||
m_promise->addResult(u);
|
||||
|
||||
future->setProgressValue(future->progressValue() + 1);
|
||||
m_promise->setProgressValue(m_promise->future().progressValue() + 1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -321,7 +319,7 @@ QList<int> CppFindReferences::references(CPlusPlus::Symbol *symbol,
|
||||
return references;
|
||||
}
|
||||
|
||||
static void find_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
||||
static void find_helper(QPromise<CPlusPlus::Usage> &promise,
|
||||
const WorkingCopy workingCopy,
|
||||
const CPlusPlus::LookupContext &context,
|
||||
CPlusPlus::Symbol *symbol,
|
||||
@@ -355,16 +353,16 @@ static void find_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
||||
}
|
||||
files = Utils::filteredUnique(files);
|
||||
|
||||
future.setProgressRange(0, files.size());
|
||||
promise.setProgressRange(0, files.size());
|
||||
|
||||
ProcessFile process(workingCopy, snapshot, context.thisDocument(), symbol, &future, categorize);
|
||||
UpdateUI reduce(&future);
|
||||
ProcessFile process(workingCopy, snapshot, context.thisDocument(), symbol, &promise, categorize);
|
||||
UpdateUI reduce(&promise);
|
||||
// This thread waits for blockingMappedReduced to finish, so reduce the pool's used thread count
|
||||
// so the blockingMappedReduced can use one more thread, and increase it again afterwards.
|
||||
QThreadPool::globalInstance()->releaseThread();
|
||||
QtConcurrent::blockingMappedReduced<QList<CPlusPlus::Usage> > (files, process, reduce);
|
||||
QThreadPool::globalInstance()->reserveThread();
|
||||
future.setProgressValue(files.size());
|
||||
promise.setProgressValue(files.size());
|
||||
}
|
||||
|
||||
void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
|
||||
@@ -439,7 +437,7 @@ void CppFindReferences::findAll_helper(SearchResult *search, CPlusPlus::Symbol *
|
||||
SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
|
||||
const WorkingCopy workingCopy = m_modelManager->workingCopy();
|
||||
QFuture<CPlusPlus::Usage> result;
|
||||
result = Utils::runAsync(m_modelManager->sharedThreadPool(), find_helper,
|
||||
result = Utils::asyncRun(m_modelManager->sharedThreadPool(), find_helper,
|
||||
workingCopy, context, symbol, categorize);
|
||||
createWatcher(result, search);
|
||||
|
||||
@@ -625,7 +623,7 @@ class FindMacroUsesInFile
|
||||
const WorkingCopy workingCopy;
|
||||
const CPlusPlus::Snapshot snapshot;
|
||||
const CPlusPlus::Macro ¯o;
|
||||
QFutureInterface<CPlusPlus::Usage> *future;
|
||||
QPromise<CPlusPlus::Usage> *m_promise;
|
||||
|
||||
public:
|
||||
// needed by QtConcurrent
|
||||
@@ -635,8 +633,8 @@ public:
|
||||
FindMacroUsesInFile(const WorkingCopy &workingCopy,
|
||||
const CPlusPlus::Snapshot snapshot,
|
||||
const CPlusPlus::Macro ¯o,
|
||||
QFutureInterface<CPlusPlus::Usage> *future)
|
||||
: workingCopy(workingCopy), snapshot(snapshot), macro(macro), future(future)
|
||||
QPromise<CPlusPlus::Usage> *promise)
|
||||
: workingCopy(workingCopy), snapshot(snapshot), macro(macro), m_promise(promise)
|
||||
{ }
|
||||
|
||||
QList<CPlusPlus::Usage> operator()(const Utils::FilePath &fileName)
|
||||
@@ -646,9 +644,8 @@ public:
|
||||
QByteArray source;
|
||||
|
||||
restart_search:
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
if (future->isCanceled())
|
||||
m_promise->suspendIfRequested();
|
||||
if (m_promise->isCanceled())
|
||||
return usages;
|
||||
|
||||
usages.clear();
|
||||
@@ -676,8 +673,7 @@ restart_search:
|
||||
}
|
||||
}
|
||||
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
m_promise->suspendIfRequested();
|
||||
return usages;
|
||||
}
|
||||
|
||||
@@ -706,7 +702,7 @@ restart_search:
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
||||
static void findMacroUses_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
||||
static void findMacroUses_helper(QPromise<CPlusPlus::Usage> &promise,
|
||||
const WorkingCopy workingCopy,
|
||||
const CPlusPlus::Snapshot snapshot,
|
||||
const CPlusPlus::Macro macro)
|
||||
@@ -715,15 +711,15 @@ static void findMacroUses_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
||||
FilePaths files{sourceFile};
|
||||
files = Utils::filteredUnique(files + snapshot.filesDependingOn(sourceFile));
|
||||
|
||||
future.setProgressRange(0, files.size());
|
||||
FindMacroUsesInFile process(workingCopy, snapshot, macro, &future);
|
||||
UpdateUI reduce(&future);
|
||||
promise.setProgressRange(0, files.size());
|
||||
FindMacroUsesInFile process(workingCopy, snapshot, macro, &promise);
|
||||
UpdateUI reduce(&promise);
|
||||
// This thread waits for blockingMappedReduced to finish, so reduce the pool's used thread count
|
||||
// so the blockingMappedReduced can use one more thread, and increase it again afterwards.
|
||||
QThreadPool::globalInstance()->releaseThread();
|
||||
QtConcurrent::blockingMappedReduced<QList<CPlusPlus::Usage> > (files, process, reduce);
|
||||
QThreadPool::globalInstance()->reserveThread();
|
||||
future.setProgressValue(files.size());
|
||||
promise.setProgressValue(files.size());
|
||||
}
|
||||
|
||||
void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o)
|
||||
@@ -773,7 +769,7 @@ void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o, const QStri
|
||||
}
|
||||
|
||||
QFuture<CPlusPlus::Usage> result;
|
||||
result = Utils::runAsync(m_modelManager->sharedThreadPool(), findMacroUses_helper,
|
||||
result = Utils::asyncRun(m_modelManager->sharedThreadPool(), findMacroUses_helper,
|
||||
workingCopy, snapshot, macro);
|
||||
createWatcher(result, search);
|
||||
|
||||
@@ -834,7 +830,7 @@ void CppFindReferences::checkUnused(Core::SearchResult *search, const Link &link
|
||||
});
|
||||
connect(search, &SearchResult::canceled, watcher, [watcher] { watcher->cancel(); });
|
||||
connect(search, &SearchResult::destroyed, watcher, [watcher] { watcher->cancel(); });
|
||||
watcher->setFuture(Utils::runAsync(m_modelManager->sharedThreadPool(), find_helper,
|
||||
watcher->setFuture(Utils::asyncRun(m_modelManager->sharedThreadPool(), find_helper,
|
||||
m_modelManager->workingCopy(), context, symbol, true));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
#include <cplusplus/Overview.h>
|
||||
#include <cplusplus/TypeOfExpression.h>
|
||||
|
||||
#include <utils/asynctask.h>
|
||||
#include <utils/proxyaction.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/tooltip/tooltip.h>
|
||||
|
||||
#include <QRegularExpression>
|
||||
@@ -232,7 +232,7 @@ void FunctionDeclDefLinkFinder::startFindLinkAt(
|
||||
// handle the rest in a thread
|
||||
m_watcher.reset(new QFutureWatcher<QSharedPointer<FunctionDeclDefLink> >());
|
||||
connect(m_watcher.data(), &QFutureWatcherBase::finished, this, &FunctionDeclDefLinkFinder::onFutureDone);
|
||||
m_watcher->setFuture(Utils::runAsync(findLinkHelper, result, refactoringChanges));
|
||||
m_watcher->setFuture(Utils::asyncRun(findLinkHelper, result, refactoringChanges));
|
||||
}
|
||||
|
||||
bool FunctionDeclDefLink::isValid() const
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
#include <cplusplus/LookupContext.h>
|
||||
|
||||
#include <utils/asynctask.h>
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/stringutils.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
|
||||
@@ -116,8 +116,7 @@ void classifyFiles(const QSet<QString> &files, QStringList *headers, QStringList
|
||||
}
|
||||
}
|
||||
|
||||
void indexFindErrors(QFutureInterface<void> &indexingFuture,
|
||||
const ParseParams params)
|
||||
void indexFindErrors(QPromise<void> &promise, const ParseParams params)
|
||||
{
|
||||
QStringList sources, headers;
|
||||
classifyFiles(params.sourceFiles, &headers, &sources);
|
||||
@@ -130,7 +129,7 @@ void indexFindErrors(QFutureInterface<void> &indexingFuture,
|
||||
timer.start();
|
||||
|
||||
for (int i = 0, end = files.size(); i < end ; ++i) {
|
||||
if (indexingFuture.isCanceled())
|
||||
if (promise.isCanceled())
|
||||
break;
|
||||
|
||||
const QString file = files.at(i);
|
||||
@@ -153,15 +152,14 @@ void indexFindErrors(QFutureInterface<void> &indexingFuture,
|
||||
|
||||
document->releaseSourceAndAST();
|
||||
|
||||
indexingFuture.setProgressValue(i + 1);
|
||||
promise.setProgressValue(i + 1);
|
||||
}
|
||||
|
||||
const QString elapsedTime = Utils::formatElapsedTime(timer.elapsed());
|
||||
qDebug("FindErrorsIndexing: %s", qPrintable(elapsedTime));
|
||||
}
|
||||
|
||||
void index(QFutureInterface<void> &indexingFuture,
|
||||
const ParseParams params)
|
||||
void index(QPromise<void> &promise, const ParseParams params)
|
||||
{
|
||||
QScopedPointer<Internal::CppSourceProcessor> sourceProcessor(CppModelManager::createSourceProcessor());
|
||||
sourceProcessor->setFileSizeLimitInMb(params.indexerFileSizeLimitInMb);
|
||||
@@ -190,7 +188,7 @@ void index(QFutureInterface<void> &indexingFuture,
|
||||
|
||||
qCDebug(indexerLog) << "About to index" << files.size() << "files.";
|
||||
for (int i = 0; i < files.size(); ++i) {
|
||||
if (indexingFuture.isCanceled())
|
||||
if (promise.isCanceled())
|
||||
break;
|
||||
|
||||
const QString fileName = files.at(i);
|
||||
@@ -216,7 +214,7 @@ void index(QFutureInterface<void> &indexingFuture,
|
||||
sourceProcessor->setHeaderPaths(headerPaths);
|
||||
sourceProcessor->run(FilePath::fromString(fileName));
|
||||
|
||||
indexingFuture.setProgressValue(files.size() - sourceProcessor->todo().size());
|
||||
promise.setProgressValue(files.size() - sourceProcessor->todo().size());
|
||||
|
||||
if (isSourceFile)
|
||||
sourceProcessor->resetEnvironment();
|
||||
@@ -224,29 +222,29 @@ void index(QFutureInterface<void> &indexingFuture,
|
||||
qCDebug(indexerLog) << "Indexing finished.";
|
||||
}
|
||||
|
||||
void parse(QFutureInterface<void> &indexingFuture, const ParseParams params)
|
||||
void parse(QPromise<void> &promise, const ParseParams params)
|
||||
{
|
||||
const QSet<QString> &files = params.sourceFiles;
|
||||
if (files.isEmpty())
|
||||
return;
|
||||
|
||||
indexingFuture.setProgressRange(0, files.size());
|
||||
promise.setProgressRange(0, files.size());
|
||||
|
||||
if (CppIndexingSupport::isFindErrorsIndexingActive())
|
||||
indexFindErrors(indexingFuture, params);
|
||||
indexFindErrors(promise, params);
|
||||
else
|
||||
index(indexingFuture, params);
|
||||
index(promise, params);
|
||||
|
||||
indexingFuture.setProgressValue(files.size());
|
||||
promise.setProgressValue(files.size());
|
||||
CppModelManager::instance()->finishedRefreshingSourceFiles(files);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
void SymbolSearcher::runSearch(QFutureInterface<Core::SearchResultItem> &future)
|
||||
void SymbolSearcher::runSearch(QPromise<Core::SearchResultItem> &promise)
|
||||
{
|
||||
future.setProgressRange(0, m_snapshot.size());
|
||||
future.setProgressValue(0);
|
||||
promise.setProgressRange(0, m_snapshot.size());
|
||||
promise.setProgressValue(0);
|
||||
int progress = 0;
|
||||
|
||||
SearchSymbols search;
|
||||
@@ -262,9 +260,8 @@ void SymbolSearcher::runSearch(QFutureInterface<Core::SearchResultItem> &future)
|
||||
: QRegularExpression::CaseInsensitiveOption));
|
||||
matcher.optimize();
|
||||
while (it != m_snapshot.end()) {
|
||||
if (future.isPaused())
|
||||
future.waitForResume();
|
||||
if (future.isCanceled())
|
||||
promise.suspendIfRequested();
|
||||
if (promise.isCanceled())
|
||||
break;
|
||||
if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->filePath().path())) {
|
||||
QVector<Core::SearchResultItem> resultItems;
|
||||
@@ -291,15 +288,14 @@ void SymbolSearcher::runSearch(QFutureInterface<Core::SearchResultItem> &future)
|
||||
return IndexItem::Recurse;
|
||||
};
|
||||
search(it.value())->visitAllChildren(filter);
|
||||
if (!resultItems.isEmpty())
|
||||
future.reportResults(resultItems);
|
||||
for (const Core::SearchResultItem &item : std::as_const(resultItems))
|
||||
promise.addResult(item);
|
||||
}
|
||||
++it;
|
||||
++progress;
|
||||
future.setProgressValue(progress);
|
||||
promise.setProgressValue(progress);
|
||||
}
|
||||
if (future.isPaused())
|
||||
future.waitForResume();
|
||||
promise.suspendIfRequested();
|
||||
}
|
||||
|
||||
CppIndexingSupport::CppIndexingSupport()
|
||||
@@ -325,7 +321,7 @@ QFuture<void> CppIndexingSupport::refreshSourceFiles(const QSet<QString> &source
|
||||
params.workingCopy = mgr->workingCopy();
|
||||
params.sourceFiles = sourceFiles;
|
||||
|
||||
QFuture<void> result = Utils::runAsync(mgr->sharedThreadPool(), parse, params);
|
||||
QFuture<void> result = Utils::asyncRun(mgr->sharedThreadPool(), parse, params);
|
||||
m_synchronizer.addFuture(result);
|
||||
|
||||
if (mode == CppModelManager::ForcedProgressNotification || sourceFiles.count() > 1) {
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
};
|
||||
|
||||
SymbolSearcher(const SymbolSearcher::Parameters ¶meters, const QSet<QString> &fileNames);
|
||||
void runSearch(QFutureInterface<Core::SearchResultItem> &future);
|
||||
void runSearch(QPromise<Core::SearchResultItem> &promise);
|
||||
|
||||
private:
|
||||
const CPlusPlus::Snapshot m_snapshot;
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
|
||||
#include "cppsemanticinfoupdater.h"
|
||||
|
||||
#include "cpplocalsymbols.h"
|
||||
#include "cppmodelmanager.h"
|
||||
|
||||
#include <utils/asynctask.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
#include <cplusplus/Control.h>
|
||||
#include <cplusplus/CppDocument.h>
|
||||
@@ -29,11 +28,11 @@ public:
|
||||
class FuturizedTopLevelDeclarationProcessor: public TopLevelDeclarationProcessor
|
||||
{
|
||||
public:
|
||||
explicit FuturizedTopLevelDeclarationProcessor(QFutureInterface<void> &future): m_future(future) {}
|
||||
explicit FuturizedTopLevelDeclarationProcessor(QPromise<void> &promise): m_promise(promise) {}
|
||||
bool processDeclaration(DeclarationAST *) override { return !isCanceled(); }
|
||||
bool isCanceled() { return m_future.isCanceled(); }
|
||||
bool isCanceled() { return m_promise.isCanceled(); }
|
||||
private:
|
||||
QFutureInterface<void> m_future;
|
||||
QPromise<void> &m_promise;
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -49,7 +48,7 @@ public:
|
||||
|
||||
bool reuseCurrentSemanticInfo(const SemanticInfo::Source &source, bool emitSignalWhenFinished);
|
||||
|
||||
void update_helper(QFutureInterface<void> &future, const SemanticInfo::Source &source);
|
||||
void update_helper(QPromise<void> &promise, const SemanticInfo::Source &source);
|
||||
|
||||
public:
|
||||
SemanticInfoUpdater *q;
|
||||
@@ -136,10 +135,10 @@ bool SemanticInfoUpdaterPrivate::reuseCurrentSemanticInfo(const SemanticInfo::So
|
||||
return false;
|
||||
}
|
||||
|
||||
void SemanticInfoUpdaterPrivate::update_helper(QFutureInterface<void> &future,
|
||||
void SemanticInfoUpdaterPrivate::update_helper(QPromise<void> &promise,
|
||||
const SemanticInfo::Source &source)
|
||||
{
|
||||
FuturizedTopLevelDeclarationProcessor processor(future);
|
||||
FuturizedTopLevelDeclarationProcessor processor(promise);
|
||||
update(source, true, &processor);
|
||||
}
|
||||
|
||||
@@ -179,7 +178,7 @@ void SemanticInfoUpdater::updateDetached(const SemanticInfo::Source &source)
|
||||
return;
|
||||
}
|
||||
|
||||
d->m_future = Utils::runAsync(CppModelManager::instance()->sharedThreadPool(),
|
||||
d->m_future = Utils::asyncRun(CppModelManager::instance()->sharedThreadPool(),
|
||||
&SemanticInfoUpdaterPrivate::update_helper, d.data(), source);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
#include "symbolsearcher_test.h"
|
||||
|
||||
#include "cppindexingsupport.h"
|
||||
#include "cppmodelmanager.h"
|
||||
#include "cpptoolstestcase.h"
|
||||
#include "searchsymbols.h"
|
||||
|
||||
#include <coreplugin/testdatadir.h>
|
||||
#include <coreplugin/find/searchresultwindow.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
#include <utils/asynctask.h>
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
const QScopedPointer<SymbolSearcher> symbolSearcher(
|
||||
new SymbolSearcher(searchParameters, QSet<QString>{testFile}));
|
||||
QFuture<Core::SearchResultItem> search
|
||||
= Utils::runAsync(&SymbolSearcher::runSearch, symbolSearcher.data());
|
||||
= Utils::asyncRun(&SymbolSearcher::runSearch, symbolSearcher.data());
|
||||
search.waitForFinished();
|
||||
ResultDataList results = ResultData::fromSearchResultList(search.results());
|
||||
QCOMPARE(results, expectedResults);
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/asynctask.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QSet>
|
||||
#include <QButtonGroup>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QButtonGroup>
|
||||
#include <QSet>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Utils;
|
||||
@@ -121,7 +121,7 @@ void SymbolsFindFilter::startSearch(SearchResult *search)
|
||||
SymbolSearcher *symbolSearcher = new SymbolSearcher(parameters, projectFileNames);
|
||||
connect(watcher, &QFutureWatcherBase::finished,
|
||||
symbolSearcher, &QObject::deleteLater);
|
||||
watcher->setFuture(Utils::runAsync(m_manager->sharedThreadPool(),
|
||||
watcher->setFuture(Utils::asyncRun(m_manager->sharedThreadPool(),
|
||||
&SymbolSearcher::runSearch, symbolSearcher));
|
||||
FutureProgress *progress = ProgressManager::addTask(watcher->future(), Tr::tr("Searching for Symbol"),
|
||||
Core::Constants::TASK_SEARCH);
|
||||
|
||||
Reference in New Issue
Block a user