aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/python/pythonlanguageclient.cpp
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2025-08-28 11:04:35 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2025-09-09 09:17:40 +0000
commitf1441ac13083ae97d9de04e24c103a081b9c89a9 (patch)
tree38f4373e53eb302f8070b4a624b66a9b278e9794 /src/plugins/python/pythonlanguageclient.cpp
parent1a40aabd7907fce1fba248f78a0c472a6a0b6a74 (diff)
Python: Use mapped task tree runner in openDocument()
Change-Id: I886b90ac7c01ca0160bed2e15b612b4060e149bc Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/python/pythonlanguageclient.cpp')
-rw-r--r--src/plugins/python/pythonlanguageclient.cpp41
1 files changed, 14 insertions, 27 deletions
diff --git a/src/plugins/python/pythonlanguageclient.cpp b/src/plugins/python/pythonlanguageclient.cpp
index 2a953a8f95c..13381454988 100644
--- a/src/plugins/python/pythonlanguageclient.cpp
+++ b/src/plugins/python/pythonlanguageclient.cpp
@@ -36,9 +36,7 @@
#include <utils/infobar.h>
#include <utils/qtcprocess.h>
-#include <QFutureWatcher>
#include <QJsonDocument>
-#include <QTimer>
using namespace LanguageClient;
using namespace LanguageServerProtocol;
@@ -314,7 +312,7 @@ public:
void openDocument(const FilePath &python, TextDocument *document);
QHash<FilePath, QList<TextDocument *>> m_infoBarEntries;
- QHash<TextDocument *, QPointer<QFutureWatcher<PythonLanguageServerState>>> m_runningChecks;
+ MappedTaskTreeRunner<TextDocument *> m_documentRunner;
SingleTaskTreeRunner m_pipInstallerRunner;
};
@@ -364,29 +362,19 @@ void PyLSConfigureAssistant::openDocument(const FilePath &python, TextDocument *
return;
}
- using CheckPylsWatcher = QFutureWatcher<PythonLanguageServerState>;
- QPointer<CheckPylsWatcher> watcher = new CheckPylsWatcher();
-
- // cancel and delete watcher after a 10 second timeout
- QTimer::singleShot(10000, this, [watcher]() {
- if (watcher) {
- watcher->cancel();
- watcher->deleteLater();
- }
- });
+ const auto onSetup = [python](Async<PythonLanguageServerState> &task) {
+ task.setConcurrentCallData(&checkPythonLanguageServer, python);
+ };
+ const auto onDone = [this, python, document = QPointer<TextDocument>(document)](
+ const Async<PythonLanguageServerState> &task) {
+ if (!document || !task.isResultAvailable())
+ return;
+ handlePyLSState(python, task.result(), document);
+ };
- connect(watcher, &CheckPylsWatcher::resultReadyAt, this,
- [this, watcher, python, document = QPointer<TextDocument>(document)] {
- if (!document || !watcher)
- return;
- handlePyLSState(python, watcher->result(), document);
- });
- connect(watcher, &CheckPylsWatcher::finished, watcher, &CheckPylsWatcher::deleteLater);
- connect(watcher, &CheckPylsWatcher::finished, this, [this, document] {
- m_runningChecks.remove(document);
- });
- watcher->setFuture(Utils::asyncRun(&checkPythonLanguageServer, python));
- m_runningChecks[document] = watcher;
+ using namespace std::literals::chrono_literals;
+ const Group recipe { AsyncTask<PythonLanguageServerState>(onSetup, onDone).withTimeout(10s) };
+ m_documentRunner.start(document, recipe);
}
void PyLSConfigureAssistant::handlePyLSState(const FilePath &python,
@@ -459,8 +447,7 @@ void PyLSConfigureAssistant::resetEditorInfoBar(TextDocument *document)
for (QList<TextDocument *> &documents : m_infoBarEntries)
documents.removeAll(document);
document->infoBar()->removeInfo(installPylsInfoBarId);
- if (auto watcher = m_runningChecks.value(document))
- watcher->cancel();
+ m_documentRunner.resetKey(document);
}
PyLSConfigureAssistant::PyLSConfigureAssistant()