From a2de0643a60284dd8274228abdc17f814939fe6b Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Tue, 6 Dec 2022 15:59:27 +0300 Subject: [PATCH] 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 --- .gitignore | 1 + .../main/scala/sbt/internal/bsp/BuildServerConnection.scala | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 322179c4a..b36926580 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ npm-debug.log .bsp/ metals.sbt launcher-package/citest/freshly-baked +.vscode diff --git a/protocol/src/main/scala/sbt/internal/bsp/BuildServerConnection.scala b/protocol/src/main/scala/sbt/internal/bsp/BuildServerConnection.scala index bdc850cd2..4317f893d 100644 --- a/protocol/src/main/scala/sbt/internal/bsp/BuildServerConnection.scala +++ b/protocol/src/main/scala/sbt/internal/bsp/BuildServerConnection.scala @@ -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))