Python: Avoid polluting global or virtual environments with pylsp

Install the language server into the Qt Creator resource directory
instead. Reuse the server for all interpreters with the same
version. This also reduces the amount of editor toolbars asking the user
to install a language server for a specific interpreter.

Change-Id: I48ef4ad30fe0097ee8d2b855b0f278e98be5ce57
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2023-11-27 14:15:29 +01:00
parent 1200419059
commit fbe054116a
6 changed files with 68 additions and 53 deletions

View File

@@ -21,6 +21,8 @@
#include <utils/mimeutils.h>
#include <utils/process.h>
#include <QReadLocker>
using namespace ProjectExplorer;
using namespace Utils;
@@ -208,4 +210,28 @@ bool pipIsUsable(const Utils::FilePath &python)
return process.result() == ProcessResult::FinishedWithSuccess;
}
QString pythonVersion(const FilePath &python)
{
static QReadWriteLock lock;
static QMap<FilePath, QString> versionCache;
{
QReadLocker locker(&lock);
auto it = versionCache.constFind(python);
if (it != versionCache.constEnd())
return *it;
}
Process p;
p.setCommand({python, {"--version"}});
p.runBlocking();
if (p.result() == Utils::ProcessResult::FinishedWithSuccess) {
const QString version = p.readAllStandardOutput().trimmed();
QWriteLocker locker(&lock);
versionCache.insert(python, version);
return version;
}
return QString();
}
} // Python::Internal