forked from qt-creator/qt-creator
QmlJSSemanticHighlighter: Use QPromise for async calls
Change-Id: Ic5d70d766cc25214a3c4a54251d514b678aa9aff Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -20,9 +20,9 @@
|
|||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <texteditor/fontsettings.h>
|
#include <texteditor/fontsettings.h>
|
||||||
|
#include <utils/asynctask.h>
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/runextensions.h>
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
@@ -156,11 +156,11 @@ public:
|
|||||||
AddMessagesHighlights,
|
AddMessagesHighlights,
|
||||||
SkipMessagesHighlights,
|
SkipMessagesHighlights,
|
||||||
};
|
};
|
||||||
CollectionTask(QFutureInterface<SemanticHighlighter::Use> &futureInterface,
|
CollectionTask(QPromise<SemanticHighlighter::Use> &promise,
|
||||||
const QmlJSTools::SemanticInfo &semanticInfo,
|
const QmlJSTools::SemanticInfo &semanticInfo,
|
||||||
const TextEditor::FontSettings &fontSettings,
|
const TextEditor::FontSettings &fontSettings,
|
||||||
Flags flags)
|
Flags flags)
|
||||||
: m_futureInterface(futureInterface)
|
: m_promise(promise)
|
||||||
, m_semanticInfo(semanticInfo)
|
, m_semanticInfo(semanticInfo)
|
||||||
, m_fontSettings(fontSettings)
|
, m_fontSettings(fontSettings)
|
||||||
, m_scopeChain(semanticInfo.scopeChain())
|
, m_scopeChain(semanticInfo.scopeChain())
|
||||||
@@ -211,7 +211,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void accept(Node *ast)
|
void accept(Node *ast)
|
||||||
{
|
{
|
||||||
if (m_futureInterface.isCanceled())
|
if (m_promise.isCanceled())
|
||||||
return;
|
return;
|
||||||
if (ast)
|
if (ast)
|
||||||
ast->accept(this);
|
ast->accept(this);
|
||||||
@@ -219,7 +219,7 @@ protected:
|
|||||||
|
|
||||||
void scopedAccept(Node *ast, Node *child)
|
void scopedAccept(Node *ast, Node *child)
|
||||||
{
|
{
|
||||||
if (m_futureInterface.isCanceled())
|
if (m_promise.isCanceled())
|
||||||
return;
|
return;
|
||||||
m_scopeBuilder.push(ast);
|
m_scopeBuilder.push(ast);
|
||||||
accept(child);
|
accept(child);
|
||||||
@@ -510,12 +510,13 @@ private:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Utils::sort(m_uses, sortByLinePredicate);
|
Utils::sort(m_uses, sortByLinePredicate);
|
||||||
m_futureInterface.reportResults(m_uses);
|
for (const SemanticHighlighter::Use &use : std::as_const(m_uses))
|
||||||
|
m_promise.addResult(use);
|
||||||
m_uses.clear();
|
m_uses.clear();
|
||||||
m_uses.reserve(chunkSize);
|
m_uses.reserve(chunkSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFutureInterface<SemanticHighlighter::Use> &m_futureInterface;
|
QPromise<SemanticHighlighter::Use> &m_promise;
|
||||||
const QmlJSTools::SemanticInfo &m_semanticInfo;
|
const QmlJSTools::SemanticInfo &m_semanticInfo;
|
||||||
const TextEditor::FontSettings &m_fontSettings;
|
const TextEditor::FontSettings &m_fontSettings;
|
||||||
ScopeChain m_scopeChain;
|
ScopeChain m_scopeChain;
|
||||||
@@ -549,11 +550,8 @@ void SemanticHighlighter::rerun(const QmlJSTools::SemanticInfo &semanticInfo)
|
|||||||
m_watcher.cancel();
|
m_watcher.cancel();
|
||||||
|
|
||||||
m_startRevision = m_document->document()->revision();
|
m_startRevision = m_document->document()->revision();
|
||||||
auto future = Utils::runAsync(QThread::LowestPriority,
|
auto future = Utils::asyncRun(QThread::LowestPriority, &SemanticHighlighter::run, this,
|
||||||
&SemanticHighlighter::run,
|
semanticInfo, TextEditor::TextEditorSettings::fontSettings());
|
||||||
this,
|
|
||||||
semanticInfo,
|
|
||||||
TextEditor::TextEditorSettings::fontSettings());
|
|
||||||
m_watcher.setFuture(future);
|
m_watcher.setFuture(future);
|
||||||
m_futureSynchronizer.addFuture(future);
|
m_futureSynchronizer.addFuture(future);
|
||||||
}
|
}
|
||||||
@@ -590,11 +588,11 @@ void SemanticHighlighter::finished()
|
|||||||
m_document->syntaxHighlighter(), m_watcher.future());
|
m_document->syntaxHighlighter(), m_watcher.future());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SemanticHighlighter::run(QFutureInterface<SemanticHighlighter::Use> &futureInterface,
|
void SemanticHighlighter::run(QPromise<Use> &promise,
|
||||||
const QmlJSTools::SemanticInfo &semanticInfo,
|
const QmlJSTools::SemanticInfo &semanticInfo,
|
||||||
const TextEditor::FontSettings &fontSettings)
|
const TextEditor::FontSettings &fontSettings)
|
||||||
{
|
{
|
||||||
CollectionTask task(futureInterface,
|
CollectionTask task(promise,
|
||||||
semanticInfo,
|
semanticInfo,
|
||||||
fontSettings,
|
fontSettings,
|
||||||
(m_enableWarnings ? CollectionTask::AddMessagesHighlights
|
(m_enableWarnings ? CollectionTask::AddMessagesHighlights
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void applyResults(int from, int to);
|
void applyResults(int from, int to);
|
||||||
void finished();
|
void finished();
|
||||||
void run(QFutureInterface<Use> &futureInterface,
|
void run(QPromise<Use> &promise,
|
||||||
const QmlJSTools::SemanticInfo &semanticInfo,
|
const QmlJSTools::SemanticInfo &semanticInfo,
|
||||||
const TextEditor::FontSettings &fontSettings);
|
const TextEditor::FontSettings &fontSettings);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user