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