forked from qt-creator/qt-creator
ClangCodeModel: Use QtConcurrent invocation for async run
Change-Id: Id404d3a7699f12cdbc1e51390b3e5218ab3459b6 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -34,9 +34,9 @@
|
||||
|
||||
#include <texteditor/textmark.h>
|
||||
|
||||
#include <utils/asynctask.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
|
||||
using namespace Core;
|
||||
@@ -61,7 +61,7 @@ void ClangCodeModelPlugin::generateCompilationDB()
|
||||
baseDir = TemporaryDirectory::masterDirectoryFilePath();
|
||||
|
||||
QFuture<GenerateCompilationDbResult> task
|
||||
= Utils::runAsync(&Internal::generateCompilationDB, ProjectInfoList{projectInfo},
|
||||
= Utils::asyncRun(&Internal::generateCompilationDB, ProjectInfoList{projectInfo},
|
||||
baseDir, CompilationDbPurpose::Project,
|
||||
warningsConfigForProject(target->project()),
|
||||
globalClangOptions(),
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "clangdquickfixes.h"
|
||||
#include "clangdsemantichighlighting.h"
|
||||
#include "clangdswitchdecldef.h"
|
||||
#include "clangmodelmanagersupport.h"
|
||||
#include "clangtextmark.h"
|
||||
#include "clangutils.h"
|
||||
#include "tasktimers.h"
|
||||
@@ -58,10 +57,10 @@
|
||||
#include <texteditor/codeassist/textdocumentmanipulatorinterface.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/asynctask.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/itemviews.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/theme/theme.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
@@ -1469,7 +1468,7 @@ void ClangdClient::Private::handleSemanticTokens(TextDocument *doc,
|
||||
clangdVersion = q->versionNumber(),
|
||||
this] {
|
||||
try {
|
||||
return Utils::runAsync(doSemanticHighlighting, filePath, tokens, text, ast, doc,
|
||||
return Utils::asyncRun(doSemanticHighlighting, filePath, tokens, text, ast, doc,
|
||||
rev, clangdVersion, highlightingTimer);
|
||||
} catch (const std::exception &e) {
|
||||
qWarning() << "caught" << e.what() << "in main highlighting thread";
|
||||
|
||||
@@ -112,7 +112,7 @@ static QList<BlockRange> cleanupDisabledCode(HighlightingResults &results, const
|
||||
class ExtraHighlightingResultsCollector
|
||||
{
|
||||
public:
|
||||
ExtraHighlightingResultsCollector(QFutureInterface<HighlightingResult> &future,
|
||||
ExtraHighlightingResultsCollector(QPromise<HighlightingResult> &promise,
|
||||
HighlightingResults &results,
|
||||
const Utils::FilePath &filePath, const ClangdAstNode &ast,
|
||||
const QTextDocument *doc, const QString &docContent,
|
||||
@@ -131,7 +131,7 @@ private:
|
||||
void collectFromNode(const ClangdAstNode &node);
|
||||
void visitNode(const ClangdAstNode&node);
|
||||
|
||||
QFutureInterface<HighlightingResult> &m_future;
|
||||
QPromise<HighlightingResult> &m_promise;
|
||||
HighlightingResults &m_results;
|
||||
const Utils::FilePath m_filePath;
|
||||
const ClangdAstNode &m_ast;
|
||||
@@ -142,7 +142,7 @@ private:
|
||||
};
|
||||
|
||||
void doSemanticHighlighting(
|
||||
QFutureInterface<HighlightingResult> &future,
|
||||
QPromise<HighlightingResult> &promise,
|
||||
const Utils::FilePath &filePath,
|
||||
const QList<ExpandedSemanticToken> &tokens,
|
||||
const QString &docContents,
|
||||
@@ -153,10 +153,8 @@ void doSemanticHighlighting(
|
||||
const TaskTimer &taskTimer)
|
||||
{
|
||||
ThreadedSubtaskTimer t("highlighting", taskTimer);
|
||||
if (future.isCanceled()) {
|
||||
future.reportFinished();
|
||||
if (promise.isCanceled())
|
||||
return;
|
||||
}
|
||||
|
||||
const QTextDocument doc(docContents);
|
||||
const auto tokenRange = [&doc](const ExpandedSemanticToken &token) {
|
||||
@@ -399,13 +397,13 @@ void doSemanticHighlighting(
|
||||
};
|
||||
auto results = QtConcurrent::blockingMapped<HighlightingResults>(tokens, safeToResult);
|
||||
const QList<BlockRange> ifdefedOutBlocks = cleanupDisabledCode(results, &doc, docContents);
|
||||
ExtraHighlightingResultsCollector(future, results, filePath, ast, &doc, docContents,
|
||||
ExtraHighlightingResultsCollector(promise, results, filePath, ast, &doc, docContents,
|
||||
clangdVersion).collect();
|
||||
Utils::erase(results, [](const HighlightingResult &res) {
|
||||
// QTCREATORBUG-28639
|
||||
return res.textStyles.mainStyle == C_TEXT && res.textStyles.mixinStyles.empty();
|
||||
});
|
||||
if (!future.isCanceled()) {
|
||||
if (!promise.isCanceled()) {
|
||||
qCInfo(clangdLogHighlight) << "reporting" << results.size() << "highlighting results";
|
||||
QMetaObject::invokeMethod(textDocument, [textDocument, ifdefedOutBlocks, docRevision] {
|
||||
if (textDocument && textDocument->document()->revision() == docRevision)
|
||||
@@ -423,16 +421,16 @@ void doSemanticHighlighting(
|
||||
if (ClangdClient * const client = ClangModelManagerSupport::clientForFile(filePath))
|
||||
client->setVirtualRanges(filePath, virtualRanges, docRevision);
|
||||
}, Qt::QueuedConnection);
|
||||
future.reportResults(QVector<HighlightingResult>(results.cbegin(), results.cend()));
|
||||
for (const HighlightingResult &r : results)
|
||||
promise.addResult(r);
|
||||
}
|
||||
future.reportFinished();
|
||||
}
|
||||
|
||||
ExtraHighlightingResultsCollector::ExtraHighlightingResultsCollector(
|
||||
QFutureInterface<HighlightingResult> &future, HighlightingResults &results,
|
||||
QPromise<HighlightingResult> &promise, HighlightingResults &results,
|
||||
const Utils::FilePath &filePath, const ClangdAstNode &ast, const QTextDocument *doc,
|
||||
const QString &docContent, const QVersionNumber &clangdVersion)
|
||||
: m_future(future), m_results(results), m_filePath(filePath), m_ast(ast), m_doc(doc),
|
||||
: m_promise(promise), m_results(results), m_filePath(filePath), m_ast(ast), m_doc(doc),
|
||||
m_docContent(docContent), m_clangdVersion(clangdVersion.majorVersion())
|
||||
{
|
||||
}
|
||||
@@ -916,7 +914,7 @@ void ExtraHighlightingResultsCollector::collectFromNode(const ClangdAstNode &nod
|
||||
|
||||
void ExtraHighlightingResultsCollector::visitNode(const ClangdAstNode &node)
|
||||
{
|
||||
if (m_future.isCanceled())
|
||||
if (m_promise.isCanceled())
|
||||
return;
|
||||
const ClangdAstNode::FileStatus prevFileStatus = m_currentFileStatus;
|
||||
m_currentFileStatus = node.fileStatus(m_filePath);
|
||||
|
||||
@@ -3,11 +3,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QFutureInterface>
|
||||
#include <QLoggingCategory>
|
||||
#include <QPointer>
|
||||
#include <QVersionNumber>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
template <typename T>
|
||||
class QPromise;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace LanguageClient { class ExpandedSemanticToken; }
|
||||
namespace TextEditor {
|
||||
class HighlightingResult;
|
||||
@@ -21,7 +25,7 @@ class TaskTimer;
|
||||
Q_DECLARE_LOGGING_CATEGORY(clangdLogHighlight);
|
||||
|
||||
void doSemanticHighlighting(
|
||||
QFutureInterface<TextEditor::HighlightingResult> &future,
|
||||
QPromise<TextEditor::HighlightingResult> &promise,
|
||||
const Utils::FilePath &filePath,
|
||||
const QList<LanguageClient::ExpandedSemanticToken> &tokens,
|
||||
const QString &docContents,
|
||||
|
||||
@@ -41,9 +41,9 @@
|
||||
#include <projectexplorer/taskhub.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/asynctask.h>
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
@@ -591,7 +591,7 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
|
||||
|
||||
});
|
||||
const FilePath includeDir = settings.clangdIncludePath();
|
||||
auto future = Utils::runAsync(&Internal::generateCompilationDB, projectInfo,
|
||||
auto future = Utils::asyncRun(&Internal::generateCompilationDB, projectInfo,
|
||||
jsonDbDir, CompilationDbPurpose::CodeModel,
|
||||
warningsConfigForProject(project),
|
||||
globalClangOptions(), includeDir);
|
||||
|
||||
Reference in New Issue
Block a user