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 #include #include -#include -#include -#include #include -#include #include -#include -#include #include 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 document, + const Utils::FilePath &pylsPath); + void openDocument(const FilePath &python, TextEditor::TextDocument *document); + + QHash> m_infoBarEntries; + QHash>> + m_runningChecks; +}; void PyLSConfigureAssistant::installPythonLanguageServer(const FilePath &python, QPointer 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 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(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> 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 document, - const Utils::FilePath &pylsPath); - - QHash> m_infoBarEntries; - QHash>> - m_runningChecks; -}; +void openDocumentWithPython(const Utils::FilePath &python, TextEditor::TextDocument *document); } // Python::Internal