aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/python
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2024-01-15 17:26:18 +0100
committerhjk <hjk@qt.io>2024-01-16 10:43:28 +0000
commit9c8e5d4cdb81e53655c94932036f6ee2a16e5774 (patch)
tree936024d85b09c7d9d8db87255fc6c3f7d89f433b /src/plugins/python
parent5de41fb40df2bc229fb32b1d7d3836daea5e0474 (diff)
Python: Simplify PyLSConfigureAssistant setup
Change-Id: Icdd8d0017a8fe71f579af6f19fa2b870f0677efc Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/python')
-rw-r--r--src/plugins/python/pythoneditor.cpp4
-rw-r--r--src/plugins/python/pythonlanguageclient.cpp60
-rw-r--r--src/plugins/python/pythonlanguageclient.h25
3 files changed, 40 insertions, 49 deletions
diff --git a/src/plugins/python/pythoneditor.cpp b/src/plugins/python/pythoneditor.cpp
index a4efb19e63d..f8d6a83a4ad 100644
--- a/src/plugins/python/pythoneditor.cpp
+++ b/src/plugins/python/pythoneditor.cpp
@@ -289,7 +289,7 @@ PythonDocument::PythonDocument()
return;
const FilePath &python = detectPython(filePath());
if (python.exists())
- PyLSConfigureAssistant::openDocumentWithPython(python, this);
+ openDocumentWithPython(python, this);
});
connect(this,
&PythonDocument::openFinishedSuccessfully,
@@ -304,7 +304,7 @@ void PythonDocument::updateCurrentPython()
void PythonDocument::updatePython(const FilePath &python)
{
- PyLSConfigureAssistant::openDocumentWithPython(python, this);
+ openDocumentWithPython(python, this);
PySideInstaller::checkPySideInstallation(python, this);
emit pythonUpdated(python);
}
diff --git a/src/plugins/python/pythonlanguageclient.cpp b/src/plugins/python/pythonlanguageclient.cpp
index aaf1e7c8a3d..8f2c799d81b 100644
--- a/src/plugins/python/pythonlanguageclient.cpp
+++ b/src/plugins/python/pythonlanguageclient.cpp
@@ -7,9 +7,7 @@
#include "pythonbuildconfiguration.h"
#include "pysideuicextracompiler.h"
#include "pythonconstants.h"
-#include "pythonplugin.h"
#include "pythonproject.h"
-#include "pythonrunconfiguration.h"
#include "pythonsettings.h"
#include "pythontr.h"
#include "pythonutils.h"
@@ -35,15 +33,9 @@
#include <utils/async.h>
#include <utils/infobar.h>
#include <utils/process.h>
-#include <utils/variablechooser.h>
-#include <QCheckBox>
-#include <QComboBox>
#include <QFutureWatcher>
-#include <QGroupBox>
#include <QJsonDocument>
-#include <QPushButton>
-#include <QRegularExpression>
#include <QTimer>
using namespace LanguageClient;
@@ -263,11 +255,24 @@ PyLSClient *PyLSClient::clientForPython(const FilePath &python)
return pythonClients()[python];
}
-PyLSConfigureAssistant *PyLSConfigureAssistant::instance()
+class PyLSConfigureAssistant : public QObject
{
- static auto *instance = new PyLSConfigureAssistant(pluginInstance());
- return instance;
-}
+public:
+ PyLSConfigureAssistant();
+
+ void handlePyLSState(const Utils::FilePath &python,
+ const PythonLanguageServerState &state,
+ TextEditor::TextDocument *document);
+ void resetEditorInfoBar(TextEditor::TextDocument *document);
+ void installPythonLanguageServer(const Utils::FilePath &python,
+ QPointer<TextEditor::TextDocument> document,
+ const Utils::FilePath &pylsPath);
+ void openDocument(const FilePath &python, TextEditor::TextDocument *document);
+
+ QHash<Utils::FilePath, QList<TextEditor::TextDocument *>> m_infoBarEntries;
+ QHash<TextEditor::TextDocument *, QPointer<QFutureWatcher<PythonLanguageServerState>>>
+ m_runningChecks;
+};
void PyLSConfigureAssistant::installPythonLanguageServer(const FilePath &python,
QPointer<TextEditor::TextDocument> document,
@@ -300,10 +305,9 @@ void PyLSConfigureAssistant::installPythonLanguageServer(const FilePath &python,
install->run();
}
-void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python,
- TextEditor::TextDocument *document)
+void PyLSConfigureAssistant::openDocument(const FilePath &python, TextEditor::TextDocument *document)
{
- instance()->resetEditorInfoBar(document);
+ resetEditorInfoBar(document);
if (!PythonSettings::pylsEnabled() || !python.exists())
return;
@@ -316,7 +320,7 @@ void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python,
QPointer<CheckPylsWatcher> watcher = new CheckPylsWatcher();
// cancel and delete watcher after a 10 second timeout
- QTimer::singleShot(10000, instance(), [watcher]() {
+ QTimer::singleShot(10000, this, [watcher]() {
if (watcher) {
watcher->cancel();
watcher->deleteLater();
@@ -325,18 +329,18 @@ void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python,
connect(watcher,
&CheckPylsWatcher::resultReadyAt,
- instance(),
+ this,
[=, document = QPointer<TextEditor::TextDocument>(document)]() {
if (!document || !watcher)
return;
- instance()->handlePyLSState(python, watcher->result(), document);
+ handlePyLSState(python, watcher->result(), document);
});
connect(watcher, &CheckPylsWatcher::finished, watcher, &CheckPylsWatcher::deleteLater);
- connect(watcher, &CheckPylsWatcher::finished, instance(), [document](){
- instance()->m_runningChecks.remove(document);
+ connect(watcher, &CheckPylsWatcher::finished, this, [this, document] {
+ m_runningChecks.remove(document);
});
watcher->setFuture(Utils::asyncRun(&checkPythonLanguageServer, python));
- instance()->m_runningChecks[document] = watcher;
+ m_runningChecks[document] = watcher;
}
void PyLSConfigureAssistant::handlePyLSState(const FilePath &python,
@@ -375,8 +379,7 @@ void PyLSConfigureAssistant::resetEditorInfoBar(TextEditor::TextDocument *docume
watcher->cancel();
}
-PyLSConfigureAssistant::PyLSConfigureAssistant(QObject *parent)
- : QObject(parent)
+PyLSConfigureAssistant::PyLSConfigureAssistant()
{
Core::EditorManager::instance();
@@ -389,4 +392,15 @@ PyLSConfigureAssistant::PyLSConfigureAssistant(QObject *parent)
});
}
+static PyLSConfigureAssistant &pyLSConfigureAssistant()
+{
+ static PyLSConfigureAssistant thePyLSConfigureAssistant;
+ return thePyLSConfigureAssistant;
+}
+
+void openDocumentWithPython(const FilePath &python, TextEditor::TextDocument *document)
+{
+ pyLSConfigureAssistant().openDocument(python, document);
+}
+
} // Python::Internal
diff --git a/src/plugins/python/pythonlanguageclient.h b/src/plugins/python/pythonlanguageclient.h
index fa0fb493e78..12fb9c140d0 100644
--- a/src/plugins/python/pythonlanguageclient.h
+++ b/src/plugins/python/pythonlanguageclient.h
@@ -47,29 +47,6 @@ private:
QHash<ProjectExplorer::Project *, QList<ProjectExplorer::ExtraCompiler *>> m_extraCompilers;
};
-class PyLSConfigureAssistant : public QObject
-{
- Q_OBJECT
-public:
- static PyLSConfigureAssistant *instance();
-
- static void openDocumentWithPython(const Utils::FilePath &python,
- TextEditor::TextDocument *document);
-
-private:
- explicit PyLSConfigureAssistant(QObject *parent);
-
- void handlePyLSState(const Utils::FilePath &python,
- const PythonLanguageServerState &state,
- TextEditor::TextDocument *document);
- void resetEditorInfoBar(TextEditor::TextDocument *document);
- void installPythonLanguageServer(const Utils::FilePath &python,
- QPointer<TextEditor::TextDocument> document,
- const Utils::FilePath &pylsPath);
-
- QHash<Utils::FilePath, QList<TextEditor::TextDocument *>> m_infoBarEntries;
- QHash<TextEditor::TextDocument *, QPointer<QFutureWatcher<PythonLanguageServerState>>>
- m_runningChecks;
-};
+void openDocumentWithPython(const Utils::FilePath &python, TextEditor::TextDocument *document);
} // Python::Internal