summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2019-10-30 14:33:04 +0100
committerDavid Schulz <david.schulz@qt.io>2019-11-04 05:47:38 +0000
commit54f2ebf91d76d05d0202de5263939fc4ba227fed (patch)
tree4acb1745eeba0bdf36d796b41334d89302e730b4
parent37d378f479d36e9b388af0fddd72490bf2b67f41 (diff)
downloadqt-creator-54f2ebf91d76d05d0202de5263939fc4ba227fed.tar.gz
Python: cache the module path for executable
This reduces ui freezes when switching the interpreter for a python project. Change-Id: Iaa8ce8ed8d51666f8696eb96f504aaf8c4a11822 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r--src/plugins/python/pythonutils.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp
index aa7051b396..dced51518b 100644
--- a/src/plugins/python/pythonutils.cpp
+++ b/src/plugins/python/pythonutils.cpp
@@ -94,6 +94,11 @@ static QString pythonName(const FilePath &pythonPath)
FilePath getPylsModulePath(CommandLine pylsCommand)
{
+ static QMap<FilePath, FilePath> cache;
+ const FilePath &modulePath = cache.value(pylsCommand.executable());
+ if (!modulePath.isEmpty())
+ return modulePath;
+
pylsCommand.addArg("-h");
SynchronousProcess pythonProcess;
pythonProcess.setEnvironment(pythonProcess.environment() + QStringList("PYTHONVERBOSE=x"));
@@ -111,8 +116,11 @@ FilePath getPylsModulePath(CommandLine pylsCommand)
const QString &output = response.allOutput();
for (auto regex : {regexCached, regexNotCached}) {
QRegularExpressionMatch result = regex.match(output);
- if (result.hasMatch())
- return FilePath::fromUserInput(result.captured(1));
+ if (result.hasMatch()) {
+ const FilePath &modulePath = FilePath::fromUserInput(result.captured(1));
+ cache[pylsCommand.executable()] = modulePath;
+ return modulePath;
+ }
}
return {};
}
@@ -146,7 +154,7 @@ static PythonLanguageServerState checkPythonLanguageServer(const FilePath &pytho
}
}
- return {PythonLanguageServerState::AlreadyInstalled, getPylsModulePath(pythonLShelpCommand)};
+ return {PythonLanguageServerState::AlreadyInstalled, modulePath};
}
const CommandLine pythonPipVersionCommand(python, {"-m", "pip", "-V"});