forked from qt-creator/qt-creator
Python: Apply 'static' pattern for singleton members
Plus some cosmetics. Change-Id: Ia2c8f425f0491fbe6a0bbf2e508857a5550e4d38 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -60,16 +60,16 @@ PySideInstaller *PySideInstaller::instance()
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PySideInstaller::checkPySideInstallation(const Utils::FilePath &python,
|
void PySideInstaller::checkPySideInstallation(const FilePath &python,
|
||||||
TextEditor::TextDocument *document)
|
TextEditor::TextDocument *document)
|
||||||
{
|
{
|
||||||
document->infoBar()->removeInfo(installPySideInfoBarId);
|
document->infoBar()->removeInfo(installPySideInfoBarId);
|
||||||
const QString pySide = importedPySide(document->plainText());
|
const QString pySide = importedPySide(document->plainText());
|
||||||
if (pySide == "PySide2" || pySide == "PySide6")
|
if (pySide == "PySide2" || pySide == "PySide6")
|
||||||
runPySideChecker(python, pySide, document);
|
instance()->runPySideChecker(python, pySide, document);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PySideInstaller::missingPySideInstallation(const Utils::FilePath &pythonPath,
|
bool PySideInstaller::missingPySideInstallation(const FilePath &pythonPath,
|
||||||
const QString &pySide)
|
const QString &pySide)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!pySide.isEmpty(), return false);
|
QTC_ASSERT(!pySide.isEmpty(), return false);
|
||||||
@@ -78,8 +78,7 @@ bool PySideInstaller::missingPySideInstallation(const Utils::FilePath &pythonPat
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
QtcProcess pythonProcess;
|
QtcProcess pythonProcess;
|
||||||
const CommandLine importPySideCheck(pythonPath, {"-c", "import " + pySide});
|
pythonProcess.setCommand({pythonPath, {"-c", "import " + pySide}});
|
||||||
pythonProcess.setCommand(importPySideCheck);
|
|
||||||
pythonProcess.runBlocking();
|
pythonProcess.runBlocking();
|
||||||
const bool missing = pythonProcess.result() != ProcessResult::FinishedWithSuccess;
|
const bool missing = pythonProcess.result() != ProcessResult::FinishedWithSuccess;
|
||||||
if (!missing)
|
if (!missing)
|
||||||
|
@@ -40,9 +40,11 @@ namespace Internal {
|
|||||||
class PySideInstaller : public QObject
|
class PySideInstaller : public QObject
|
||||||
{
|
{
|
||||||
Q_DECLARE_TR_FUNCTIONS(Python::Internal::PySideInstaller)
|
Q_DECLARE_TR_FUNCTIONS(Python::Internal::PySideInstaller)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static PySideInstaller *instance();
|
static PySideInstaller *instance();
|
||||||
void checkPySideInstallation(const Utils::FilePath &python, TextEditor::TextDocument *document);
|
static void checkPySideInstallation(const Utils::FilePath &python,
|
||||||
|
TextEditor::TextDocument *document);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PySideInstaller();
|
PySideInstaller();
|
||||||
|
@@ -118,8 +118,8 @@ public:
|
|||||||
if (!python.exists())
|
if (!python.exists())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PyLSConfigureAssistant::instance()->openDocumentWithPython(python, this);
|
PyLSConfigureAssistant::openDocumentWithPython(python, this);
|
||||||
PySideInstaller::instance()->checkPySideInstallation(python, this);
|
PySideInstaller::checkPySideInstallation(python, this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -614,7 +614,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, this, [watcher]() {
|
QTimer::singleShot(10000, instance(), [watcher]() {
|
||||||
if (watcher) {
|
if (watcher) {
|
||||||
watcher->cancel();
|
watcher->cancel();
|
||||||
watcher->deleteLater();
|
watcher->deleteLater();
|
||||||
@@ -623,11 +623,11 @@ void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python,
|
|||||||
|
|
||||||
connect(watcher,
|
connect(watcher,
|
||||||
&CheckPylsWatcher::resultReadyAt,
|
&CheckPylsWatcher::resultReadyAt,
|
||||||
this,
|
instance(),
|
||||||
[=, document = QPointer<TextEditor::TextDocument>(document)]() {
|
[=, document = QPointer<TextEditor::TextDocument>(document)]() {
|
||||||
if (!document || !watcher)
|
if (!document || !watcher)
|
||||||
return;
|
return;
|
||||||
handlePyLSState(python, watcher->result(), document);
|
instance()->handlePyLSState(python, watcher->result(), document);
|
||||||
watcher->deleteLater();
|
watcher->deleteLater();
|
||||||
});
|
});
|
||||||
watcher->setFuture(Utils::runAsync(&checkPythonLanguageServer, python));
|
watcher->setFuture(Utils::runAsync(&checkPythonLanguageServer, python));
|
||||||
|
@@ -71,9 +71,11 @@ public:
|
|||||||
|
|
||||||
static const LanguageClient::StdIOSettings *languageServerForPython(
|
static const LanguageClient::StdIOSettings *languageServerForPython(
|
||||||
const Utils::FilePath &python);
|
const Utils::FilePath &python);
|
||||||
static void updateEditorInfoBars(const Utils::FilePath &python, LanguageClient::Client *client);
|
|
||||||
|
|
||||||
void openDocumentWithPython(const Utils::FilePath &python, TextEditor::TextDocument *document);
|
static void updateEditorInfoBars(const Utils::FilePath &python,
|
||||||
|
LanguageClient::Client *client);
|
||||||
|
static void openDocumentWithPython(const Utils::FilePath &python,
|
||||||
|
TextEditor::TextDocument *document);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit PyLSConfigureAssistant(QObject *parent);
|
explicit PyLSConfigureAssistant(QObject *parent);
|
||||||
|
@@ -152,8 +152,8 @@ public:
|
|||||||
for (FilePath &file : project()->files(Project::AllFiles)) {
|
for (FilePath &file : project()->files(Project::AllFiles)) {
|
||||||
if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) {
|
if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) {
|
||||||
if (document->mimeType() == Constants::C_PY_MIMETYPE) {
|
if (document->mimeType() == Constants::C_PY_MIMETYPE) {
|
||||||
PyLSConfigureAssistant::instance()->openDocumentWithPython(python, document);
|
PyLSConfigureAssistant::openDocumentWithPython(python, document);
|
||||||
PySideInstaller::instance()->checkPySideInstallation(python, document);
|
PySideInstaller::checkPySideInstallation(python, document);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user