summaryrefslogtreecommitdiff
path: root/src/plugins/python
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2019-10-17 10:03:57 +0200
committerDavid Schulz <david.schulz@qt.io>2019-10-18 05:23:29 +0000
commit28c3f0c31ece00d29e59d854bae61f80e29e9c2a (patch)
treeb3fb8c864842bcfe818b93206116271567fb15f3 /src/plugins/python
parentc8ccfea225d506513e5575dd100bf6175720e29a (diff)
downloadqt-creator-28c3f0c31ece00d29e59d854bae61f80e29e9c2a.tar.gz
Python: Add info bar entry to enable pyls
Show an editor info bar entry displaying that the language server for the current python is disabled and a button to quickly enable the pyls. Change-Id: I3adb2e7cbfb1a32e35413b0b06dfbe66a0b214af Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/python')
-rw-r--r--src/plugins/python/pythonutils.cpp46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp
index 29fc14953b..acb78ef4c3 100644
--- a/src/plugins/python/pythonutils.cpp
+++ b/src/plugins/python/pythonutils.cpp
@@ -41,6 +41,7 @@
#include <texteditor/textdocument.h>
+#include <utils/qtcassert.h>
#include <utils/synchronousprocess.h>
#include <QDir>
@@ -55,12 +56,19 @@ namespace Internal {
static constexpr char startPylsInfoBarId[] = "Python::StartPyls";
static constexpr char installPylsInfoBarId[] = "Python::InstallPyls";
+static constexpr char enablePylsInfoBarId[] = "Python::EnablePyls";
static constexpr char installPylsTaskId[] = "Python::InstallPylsTask";
static constexpr char pythonUtilsTrContext[] = "Python::Utils";
struct PythonLanguageServerState
{
- enum { CanNotBeInstalled, CanBeInstalled, AlreadyInstalled, AlreadyConfigured } state;
+ enum {
+ CanNotBeInstalled,
+ CanBeInstalled,
+ AlreadyInstalled,
+ AlreadyConfigured,
+ ConfiguredButDisabled
+ } state;
FilePath pylsModulePath;
};
@@ -130,8 +138,11 @@ static PythonLanguageServerState checkPythonLanguageServer(const FilePath &pytho
if (response.allOutput().contains("Python Language Server")) {
const FilePath &modulePath = getPylsModulePath(pythonLShelpCommand);
for (const StdIOSettings *serverSetting : configuredPythonLanguageServer()) {
- if (modulePath == getPylsModulePath(serverSetting->command()))
- return {PythonLanguageServerState::AlreadyConfigured, FilePath()};
+ if (modulePath == getPylsModulePath(serverSetting->command())) {
+ return {serverSetting->m_enabled ? PythonLanguageServerState::AlreadyConfigured
+ : PythonLanguageServerState::ConfiguredButDisabled,
+ FilePath()};
+ }
}
return {PythonLanguageServerState::AlreadyInstalled, getPylsModulePath(pythonLShelpCommand)};
@@ -299,6 +310,20 @@ static void setupPythonLanguageServer(const FilePath &python,
LanguageClient::LanguageClientManager::reOpenDocumentWithClient(document, client);
}
+static void enablePythonLanguageServer(const FilePath &python,
+ QPointer<TextEditor::TextDocument> document)
+{
+ using namespace LanguageClient;
+ document->infoBar()->removeInfo(enablePylsInfoBarId);
+ if (const StdIOSettings *setting = languageServerForPython(python)) {
+ LanguageClientManager::enableClientSettings(setting->m_id);
+ if (const StdIOSettings *setting = languageServerForPython(python)) {
+ if (Client *client = LanguageClientManager::clientForSetting(setting).value(0))
+ LanguageClientManager::reOpenDocumentWithClient(document, client);
+ }
+ }
+}
+
void updateEditorInfoBar(const FilePath &python, TextEditor::TextDocument *document)
{
const PythonLanguageServerState &lsState = checkPythonLanguageServer(python);
@@ -308,9 +333,8 @@ void updateEditorInfoBar(const FilePath &python, TextEditor::TextDocument *docum
return;
}
+ resetEditorInfoBar(document);
Core::InfoBar *infoBar = document->infoBar();
- infoBar->removeInfo(installPylsInfoBarId);
- infoBar->removeInfo(startPylsInfoBarId);
if (lsState.state == PythonLanguageServerState::CanBeInstalled
&& infoBar->canInfoBeAdded(installPylsInfoBarId)) {
auto message
@@ -336,6 +360,17 @@ void updateEditorInfoBar(const FilePath &python, TextEditor::TextDocument *docum
info.setCustomButtonInfo(QCoreApplication::translate(pythonUtilsTrContext, "Setup"),
[=]() { setupPythonLanguageServer(python, document); });
infoBar->addInfo(info);
+ } else if (lsState.state == PythonLanguageServerState::ConfiguredButDisabled
+ && infoBar->canInfoBeAdded(enablePylsInfoBarId)) {
+ auto message = QCoreApplication::translate(pythonUtilsTrContext,
+ "Enable Python language server for %1 (%2)?")
+ .arg(pythonName(python), python.toUserOutput());
+ Core::InfoBarEntry info(enablePylsInfoBarId,
+ message,
+ Core::InfoBarEntry::GlobalSuppression::Enabled);
+ info.setCustomButtonInfo(QCoreApplication::translate(pythonUtilsTrContext, "Enable"),
+ [=]() { enablePythonLanguageServer(python, document); });
+ infoBar->addInfo(info);
}
}
@@ -344,6 +379,7 @@ void resetEditorInfoBar(TextEditor::TextDocument *document)
Core::InfoBar *infoBar = document->infoBar();
infoBar->removeInfo(installPylsInfoBarId);
infoBar->removeInfo(startPylsInfoBarId);
+ infoBar->removeInfo(enablePylsInfoBarId);
}
} // namespace Internal