summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor/codeassist/asyncprocessor.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2022-11-09 15:38:22 +0100
committerDavid Schulz <david.schulz@qt.io>2022-11-14 13:02:51 +0000
commit09ee528c40de17401487974dae5ce708079ac8ad (patch)
tree6dae9a77cb60b6c3e16a1f0fbd99ad465b40b73b /src/plugins/texteditor/codeassist/asyncprocessor.cpp
parent33a33612c8ff92bb541d76cb338675f16beb4281 (diff)
downloadqt-creator-09ee528c40de17401487974dae5ce708079ac8ad.tar.gz
Editor: unify assist processor handling
Define the run type of the processor by its implementation instead of a enum value of the provider. The execution of a processor inside the assist now follows a unified procedure. Change-Id: Ibe9fab324c6072e77702c2663946d7a9f562a085 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/texteditor/codeassist/asyncprocessor.cpp')
-rw-r--r--src/plugins/texteditor/codeassist/asyncprocessor.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/plugins/texteditor/codeassist/asyncprocessor.cpp b/src/plugins/texteditor/codeassist/asyncprocessor.cpp
new file mode 100644
index 0000000000..2ee5ada35f
--- /dev/null
+++ b/src/plugins/texteditor/codeassist/asyncprocessor.cpp
@@ -0,0 +1,58 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
+
+#include "asyncprocessor.h"
+
+#include "assistinterface.h"
+#include "iassistproposal.h"
+
+#include <utils/runextensions.h>
+
+namespace TextEditor {
+
+AsyncProcessor::AsyncProcessor()
+{
+ QObject::connect(&m_watcher, &QFutureWatcher<IAssistProposal *>::finished, [this]() {
+ setAsyncProposalAvailable(m_watcher.result());
+ });
+}
+
+IAssistProposal *AsyncProcessor::perform(AssistInterface *interface)
+{
+ IAssistProposal *result = immediateProposal(interface);
+ m_interface = interface;
+ m_interface->prepareForAsyncUse();
+ m_watcher.setFuture(Utils::runAsync([this]() {
+ m_interface->recreateTextDocument();
+ return performAsync(m_interface);
+ }));
+ return result;
+}
+
+bool AsyncProcessor::running()
+{
+ return m_watcher.isRunning();
+}
+
+void AsyncProcessor::cancel()
+{
+ setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal){
+ delete proposal;
+ QMetaObject::invokeMethod(QCoreApplication::instance(), [this] {
+ delete this;
+ }, Qt::QueuedConnection);
+ });
+}
+
+IAssistProposal *AsyncProcessor::immediateProposal(AssistInterface *interface)
+{
+ Q_UNUSED(interface)
+ return nullptr;
+}
+
+bool AsyncProcessor::isCanceled() const
+{
+ return m_watcher.isCanceled();
+}
+
+} // namespace TextEditor