fix: bspConfig sbt.script - use `Path` env variable as a fallback for Windows

Originally reported in https://github.com/scalameta/metals/issues/4702#issuecomment-1339137772
This commit is contained in:
Vadim Chelyshov 2022-12-06 15:59:27 +03:00
parent 09e06c45f0
commit a2de0643a6
2 changed files with 5 additions and 2 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ npm-debug.log
.bsp/
metals.sbt
launcher-package/citest/freshly-baked
.vscode

View File

@ -63,8 +63,10 @@ object BuildServerConnection {
// For those who use an old sbt script, the -Dsbt.script is not set
// As a fallback we try to find the sbt script in $PATH
val fileName = if (Properties.isWin) "sbt.bat" else "sbt"
val envPath = sys.env.getOrElse("PATH", "")
val allPaths = envPath.split(File.pathSeparator).map(Paths.get(_))
val envPath = sys.env.collectFirst {
case (k, v) if k.toUpperCase() == "PATH" => v
}
val allPaths = envPath.map(_.split(File.pathSeparator).map(Paths.get(_))).getOrElse(Array.empty)
allPaths
.map(_.resolve(fileName))
.find(file => Files.exists(file) && Files.isExecutable(file))