From 13e8ed12cbc99994f522f081bfea0ee818fe153e Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Tue, 24 Oct 2023 18:05:59 +0200 Subject: [PATCH] bugfix: Take into account JVM_OPTS and SBT_OPTS env variables Previously, they seemed to be ignored. Now, we fallback if the file doesn't exist. --- .../main/scala/scala/meta/internal/builds/SbtBuildTool.scala | 4 ++-- .../src/main/scala/scala/meta/internal/metals/JvmOpts.scala | 4 ++-- .../src/main/scala/scala/meta/internal/metals/SbtOpts.scala | 4 ++-- tests/unit/src/test/scala/tests/SbtOptsSuite.scala | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/builds/SbtBuildTool.scala b/metals/src/main/scala/scala/meta/internal/builds/SbtBuildTool.scala index e9fea8c2163..14690d8a747 100644 --- a/metals/src/main/scala/scala/meta/internal/builds/SbtBuildTool.scala +++ b/metals/src/main/scala/scala/meta/internal/builds/SbtBuildTool.scala @@ -109,8 +109,8 @@ case class SbtBuildTool( List( javaArgs, sbtVersion, - SbtOpts.fromWorkspace(workspace), - JvmOpts.fromWorkspace(workspace), + SbtOpts.fromWorkspaceOrEnv(workspace), + JvmOpts.fromWorkspaceOrEnv(workspace), jarArgs, sbtArgs, ).flatten diff --git a/metals/src/main/scala/scala/meta/internal/metals/JvmOpts.scala b/metals/src/main/scala/scala/meta/internal/metals/JvmOpts.scala index 76f5394d1d4..5580a16dfb5 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/JvmOpts.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/JvmOpts.scala @@ -14,13 +14,13 @@ import scala.meta.io.AbsolutePath */ object JvmOpts { - def fromWorkspace(workspace: AbsolutePath): List[String] = { + def fromWorkspaceOrEnv(workspace: AbsolutePath): List[String] = { val jvmOpts = workspace.resolve(".jvmopts") if (jvmOpts.isFile && Files.isReadable(jvmOpts.toNIO)) { val text = FileIO.slurp(jvmOpts, StandardCharsets.UTF_8) text.linesIterator.map(_.trim).filter(_.startsWith("-")).toList } else { - Nil + fromEnvironment } } diff --git a/metals/src/main/scala/scala/meta/internal/metals/SbtOpts.scala b/metals/src/main/scala/scala/meta/internal/metals/SbtOpts.scala index f825f98e2db..2bb3268e232 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/SbtOpts.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/SbtOpts.scala @@ -14,13 +14,13 @@ import scala.meta.io.AbsolutePath */ object SbtOpts { - def fromWorkspace(workspace: AbsolutePath): List[String] = { + def fromWorkspaceOrEnv(workspace: AbsolutePath): List[String] = { val sbtOpts = workspace.resolve(".sbtopts") if (sbtOpts.isFile && Files.isReadable(sbtOpts.toNIO)) { val text = FileIO.slurp(sbtOpts, StandardCharsets.UTF_8) process(text.linesIterator.map(_.trim).toList) } else { - Nil + fromEnvironment } } diff --git a/tests/unit/src/test/scala/tests/SbtOptsSuite.scala b/tests/unit/src/test/scala/tests/SbtOptsSuite.scala index 6624d8b62e1..86f6a51a4f8 100644 --- a/tests/unit/src/test/scala/tests/SbtOptsSuite.scala +++ b/tests/unit/src/test/scala/tests/SbtOptsSuite.scala @@ -12,8 +12,8 @@ class SbtOptsSuite extends BaseSuite { test(name) { val root = FileLayout.fromString(original) val obtained = - SbtOpts.fromWorkspace(root).mkString("\n") ++ - JvmOpts.fromWorkspace(root).mkString("\n") + SbtOpts.fromWorkspaceOrEnv(root).mkString("\n") ++ + JvmOpts.fromWorkspaceOrEnv(root).mkString("\n") assertNoDiff(obtained, expected) } }