forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -94,6 +94,11 @@ static QString pythonName(const FilePath &pythonPath)
|
|||||||
|
|
||||||
FilePath getPylsModulePath(CommandLine pylsCommand)
|
FilePath getPylsModulePath(CommandLine pylsCommand)
|
||||||
{
|
{
|
||||||
|
static QMap<FilePath, FilePath> cache;
|
||||||
|
const FilePath &modulePath = cache.value(pylsCommand.executable());
|
||||||
|
if (!modulePath.isEmpty())
|
||||||
|
return modulePath;
|
||||||
|
|
||||||
pylsCommand.addArg("-h");
|
pylsCommand.addArg("-h");
|
||||||
SynchronousProcess pythonProcess;
|
SynchronousProcess pythonProcess;
|
||||||
pythonProcess.setEnvironment(pythonProcess.environment() + QStringList("PYTHONVERBOSE=x"));
|
pythonProcess.setEnvironment(pythonProcess.environment() + QStringList("PYTHONVERBOSE=x"));
|
||||||
@@ -111,8 +116,11 @@ FilePath getPylsModulePath(CommandLine pylsCommand)
|
|||||||
const QString &output = response.allOutput();
|
const QString &output = response.allOutput();
|
||||||
for (auto regex : {regexCached, regexNotCached}) {
|
for (auto regex : {regexCached, regexNotCached}) {
|
||||||
QRegularExpressionMatch result = regex.match(output);
|
QRegularExpressionMatch result = regex.match(output);
|
||||||
if (result.hasMatch())
|
if (result.hasMatch()) {
|
||||||
return FilePath::fromUserInput(result.captured(1));
|
const FilePath &modulePath = FilePath::fromUserInput(result.captured(1));
|
||||||
|
cache[pylsCommand.executable()] = modulePath;
|
||||||
|
return modulePath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {};
|
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"});
|
const CommandLine pythonPipVersionCommand(python, {"-m", "pip", "-V"});
|
||||||
|
Reference in New Issue
Block a user