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;
|
return;
|
||||||
const FilePath &python = detectPython(filePath());
|
const FilePath &python = detectPython(filePath());
|
||||||
if (python.exists())
|
if (python.exists())
|
||||||
PyLSConfigureAssistant::openDocumentWithPython(python, this);
|
openDocumentWithPython(python, this);
|
||||||
});
|
});
|
||||||
connect(this,
|
connect(this,
|
||||||
&PythonDocument::openFinishedSuccessfully,
|
&PythonDocument::openFinishedSuccessfully,
|
||||||
@@ -304,7 +304,7 @@ void PythonDocument::updateCurrentPython()
|
|||||||
|
|
||||||
void PythonDocument::updatePython(const FilePath &python)
|
void PythonDocument::updatePython(const FilePath &python)
|
||||||
{
|
{
|
||||||
PyLSConfigureAssistant::openDocumentWithPython(python, this);
|
openDocumentWithPython(python, this);
|
||||||
PySideInstaller::checkPySideInstallation(python, this);
|
PySideInstaller::checkPySideInstallation(python, this);
|
||||||
emit pythonUpdated(python);
|
emit pythonUpdated(python);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,7 @@
|
|||||||
#include "pythonbuildconfiguration.h"
|
#include "pythonbuildconfiguration.h"
|
||||||
#include "pysideuicextracompiler.h"
|
#include "pysideuicextracompiler.h"
|
||||||
#include "pythonconstants.h"
|
#include "pythonconstants.h"
|
||||||
#include "pythonplugin.h"
|
|
||||||
#include "pythonproject.h"
|
#include "pythonproject.h"
|
||||||
#include "pythonrunconfiguration.h"
|
|
||||||
#include "pythonsettings.h"
|
#include "pythonsettings.h"
|
||||||
#include "pythontr.h"
|
#include "pythontr.h"
|
||||||
#include "pythonutils.h"
|
#include "pythonutils.h"
|
||||||
@@ -35,15 +33,9 @@
|
|||||||
#include <utils/async.h>
|
#include <utils/async.h>
|
||||||
#include <utils/infobar.h>
|
#include <utils/infobar.h>
|
||||||
#include <utils/process.h>
|
#include <utils/process.h>
|
||||||
#include <utils/variablechooser.h>
|
|
||||||
|
|
||||||
#include <QCheckBox>
|
|
||||||
#include <QComboBox>
|
|
||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
#include <QGroupBox>
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QPushButton>
|
|
||||||
#include <QRegularExpression>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
using namespace LanguageClient;
|
using namespace LanguageClient;
|
||||||
@@ -263,11 +255,24 @@ PyLSClient *PyLSClient::clientForPython(const FilePath &python)
|
|||||||
return pythonClients()[python];
|
return pythonClients()[python];
|
||||||
}
|
}
|
||||||
|
|
||||||
PyLSConfigureAssistant *PyLSConfigureAssistant::instance()
|
class PyLSConfigureAssistant : public QObject
|
||||||
{
|
{
|
||||||
static auto *instance = new PyLSConfigureAssistant(pluginInstance());
|
public:
|
||||||
return instance;
|
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,
|
void PyLSConfigureAssistant::installPythonLanguageServer(const FilePath &python,
|
||||||
QPointer<TextEditor::TextDocument> document,
|
QPointer<TextEditor::TextDocument> document,
|
||||||
@@ -300,10 +305,9 @@ void PyLSConfigureAssistant::installPythonLanguageServer(const FilePath &python,
|
|||||||
install->run();
|
install->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python,
|
void PyLSConfigureAssistant::openDocument(const FilePath &python, TextEditor::TextDocument *document)
|
||||||
TextEditor::TextDocument *document)
|
|
||||||
{
|
{
|
||||||
instance()->resetEditorInfoBar(document);
|
resetEditorInfoBar(document);
|
||||||
if (!PythonSettings::pylsEnabled() || !python.exists())
|
if (!PythonSettings::pylsEnabled() || !python.exists())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -316,7 +320,7 @@ void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python,
|
|||||||
QPointer<CheckPylsWatcher> watcher = new CheckPylsWatcher();
|
QPointer<CheckPylsWatcher> watcher = new CheckPylsWatcher();
|
||||||
|
|
||||||
// cancel and delete watcher after a 10 second timeout
|
// cancel and delete watcher after a 10 second timeout
|
||||||
QTimer::singleShot(10000, instance(), [watcher]() {
|
QTimer::singleShot(10000, this, [watcher]() {
|
||||||
if (watcher) {
|
if (watcher) {
|
||||||
watcher->cancel();
|
watcher->cancel();
|
||||||
watcher->deleteLater();
|
watcher->deleteLater();
|
||||||
@@ -325,18 +329,18 @@ void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python,
|
|||||||
|
|
||||||
connect(watcher,
|
connect(watcher,
|
||||||
&CheckPylsWatcher::resultReadyAt,
|
&CheckPylsWatcher::resultReadyAt,
|
||||||
instance(),
|
this,
|
||||||
[=, document = QPointer<TextEditor::TextDocument>(document)]() {
|
[=, document = QPointer<TextEditor::TextDocument>(document)]() {
|
||||||
if (!document || !watcher)
|
if (!document || !watcher)
|
||||||
return;
|
return;
|
||||||
instance()->handlePyLSState(python, watcher->result(), document);
|
handlePyLSState(python, watcher->result(), document);
|
||||||
});
|
});
|
||||||
connect(watcher, &CheckPylsWatcher::finished, watcher, &CheckPylsWatcher::deleteLater);
|
connect(watcher, &CheckPylsWatcher::finished, watcher, &CheckPylsWatcher::deleteLater);
|
||||||
connect(watcher, &CheckPylsWatcher::finished, instance(), [document](){
|
connect(watcher, &CheckPylsWatcher::finished, this, [this, document] {
|
||||||
instance()->m_runningChecks.remove(document);
|
m_runningChecks.remove(document);
|
||||||
});
|
});
|
||||||
watcher->setFuture(Utils::asyncRun(&checkPythonLanguageServer, python));
|
watcher->setFuture(Utils::asyncRun(&checkPythonLanguageServer, python));
|
||||||
instance()->m_runningChecks[document] = watcher;
|
m_runningChecks[document] = watcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PyLSConfigureAssistant::handlePyLSState(const FilePath &python,
|
void PyLSConfigureAssistant::handlePyLSState(const FilePath &python,
|
||||||
@@ -375,8 +379,7 @@ void PyLSConfigureAssistant::resetEditorInfoBar(TextEditor::TextDocument *docume
|
|||||||
watcher->cancel();
|
watcher->cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
PyLSConfigureAssistant::PyLSConfigureAssistant(QObject *parent)
|
PyLSConfigureAssistant::PyLSConfigureAssistant()
|
||||||
: QObject(parent)
|
|
||||||
{
|
{
|
||||||
Core::EditorManager::instance();
|
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
|
} // Python::Internal
|
||||||
|
|||||||
@@ -47,29 +47,6 @@ private:
|
|||||||
QHash<ProjectExplorer::Project *, QList<ProjectExplorer::ExtraCompiler *>> m_extraCompilers;
|
QHash<ProjectExplorer::Project *, QList<ProjectExplorer::ExtraCompiler *>> m_extraCompilers;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PyLSConfigureAssistant : public QObject
|
void openDocumentWithPython(const Utils::FilePath &python, TextEditor::TextDocument *document);
|
||||||
{
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // Python::Internal
|
} // Python::Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user