forked from qt-creator/qt-creator
Python: Simplify PyLSConfigureAssistant setup
Change-Id: Icdd8d0017a8fe71f579af6f19fa2b870f0677efc Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user