forked from qt-creator/qt-creator
LanguageClient: Fix npm installs for newer npm versions
We used the bin command line parameter for npm to get the path to the runnable cmd inside the install location, but it seems this command is missing for newer npm versions. Just check the default install location and fall back to parse the npm list output in order to find the language server path. Change-Id: Ie144b061552c4a26fa6d54b232cef308669f7dbd Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -551,22 +551,38 @@ void autoSetupLanguageServer(TextDocument *document)
|
|||||||
LanguageClientManager::instance());
|
LanguageClientManager::instance());
|
||||||
|
|
||||||
auto handleInstall = [=](const bool success) {
|
auto handleInstall = [=](const bool success) {
|
||||||
if (success) {
|
|
||||||
Process process;
|
|
||||||
process.setCommand(CommandLine(npm, {"bin"}));
|
|
||||||
process.setWorkingDirectory(lsPath);
|
|
||||||
process.start();
|
|
||||||
process.waitForFinished();
|
|
||||||
const FilePath lspath = FilePath::fromUserInput(
|
|
||||||
process.stdOutLines().value(0));
|
|
||||||
FilePath lsExecutable = lspath.pathAppended(languageServer);
|
|
||||||
if (HostOsInfo::isWindowsHost())
|
|
||||||
lsExecutable = lsExecutable.stringAppended(".cmd");
|
|
||||||
|
|
||||||
if (lsExecutable.isExecutableFile())
|
|
||||||
setupStdIOSettings(lsExecutable);
|
|
||||||
}
|
|
||||||
install->deleteLater();
|
install->deleteLater();
|
||||||
|
if (!success)
|
||||||
|
return;
|
||||||
|
FilePath relativePath = FilePath::fromPathPart(
|
||||||
|
QString("node_modules/.bin/" + languageServer));
|
||||||
|
if (HostOsInfo::isWindowsHost())
|
||||||
|
relativePath = relativePath.withSuffix(".cmd");
|
||||||
|
FilePath lsExecutable = lsPath.resolvePath(relativePath);
|
||||||
|
if (lsExecutable.isExecutableFile()) {
|
||||||
|
setupStdIOSettings(lsExecutable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Process process;
|
||||||
|
process.setCommand(CommandLine(npm, {"list", languageServer}));
|
||||||
|
process.setWorkingDirectory(lsPath);
|
||||||
|
process.start();
|
||||||
|
process.waitForFinished();
|
||||||
|
const QStringList output = process.stdOutLines();
|
||||||
|
// we are expecting output in the form of:
|
||||||
|
// tst@ C:\tmp\tst
|
||||||
|
// `-- vscode-json-languageserver@1.3.4
|
||||||
|
for (const QString &line : output) {
|
||||||
|
const qsizetype splitIndex = line.indexOf('@');
|
||||||
|
if (splitIndex == -1)
|
||||||
|
continue;
|
||||||
|
lsExecutable = FilePath::fromUserInput(line.mid(splitIndex + 1).trimmed())
|
||||||
|
.resolvePath(relativePath);
|
||||||
|
if (lsExecutable.isExecutableFile()) {
|
||||||
|
setupStdIOSettings(lsExecutable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QObject::connect(install,
|
QObject::connect(install,
|
||||||
|
Reference in New Issue
Block a user