From b2f1df67dd764c220f2179520463417da50ca2c6 Mon Sep 17 00:00:00 2001 From: zmerr Date: Tue, 26 Apr 2022 15:49:22 +0400 Subject: [PATCH 01/10] added Bloop Java Home to User Configuation --- .../main/scala/scala/meta/internal/metals/BloopServers.scala | 4 +++- .../scala/meta/internal/metals/MetalsLanguageServer.scala | 4 +++- .../scala/scala/meta/internal/metals/UserConfiguration.scala | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index 91b46d6e8b7..87cb14b0aa7 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -276,7 +276,9 @@ final class BloopServers( def ensureDesiredJvmSettings( maybeRequestedBloopJvmProperties: Option[List[String]], maybeRunningBloopJvmProperties: Option[List[String]], - maybeJavaHome: Option[String], + maybeRunningMetalsJavaHome: Option[String], + maybeRequestedBloopJavaHome: Option[String], + maybeRunningBloopJavaHome: Option[String], reconnect: () => Future[BuildChange] ): Future[Unit] = { val result = diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala index 094802e56e0..6486ed18350 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala @@ -1310,7 +1310,9 @@ class MetalsLanguageServer( bloopServers.ensureDesiredJvmSettings( userConfig.bloopJvmProperties, old.bloopJvmProperties, - userConfig.javaHome, + old.javaHome, + userConfig.bloopJavaHome, + old.bloopJavaHome, () => autoConnectToBuildServer() ) diff --git a/metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala b/metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala index 98c1e52ab8c..e1390276782 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala @@ -39,6 +39,7 @@ case class UserConfiguration( bloopSbtAlreadyInstalled: Boolean = false, bloopVersion: Option[String] = None, bloopJvmProperties: Option[List[String]] = None, + bloopJavaHome: Option[String] = None, ammoniteJvmProperties: Option[List[String]] = None, superMethodLensesEnabled: Boolean = false, showInferredType: Boolean = false, @@ -449,6 +450,8 @@ object UserConfiguration { val bloopVersion = getStringKey("bloop-version") val bloopJvmProperties = getStringListKey("bloop-jvm-properties") + val bloopJavaHome = + getStringKey("bloop-java-home") val superMethodLensesEnabled = getBooleanKey("super-method-lenses-enabled").getOrElse(false) val showInferredType = @@ -504,6 +507,7 @@ object UserConfiguration { bloopSbtAlreadyInstalled, bloopVersion, bloopJvmProperties, + bloopJavaHome, ammoniteProperties, superMethodLensesEnabled, showInferredType, From 4f3e1c78621dd37d6ff7951e92b20fae136a2b5d Mon Sep 17 00:00:00 2001 From: zmerr Date: Tue, 26 Apr 2022 20:06:59 +0400 Subject: [PATCH 02/10] support for bloop java home setting --- .../meta/internal/metals/BloopServers.scala | 136 ++++++++++-------- .../metals/MetalsLanguageServer.scala | 1 + 2 files changed, 77 insertions(+), 60 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index 87cb14b0aa7..e5d7d8d25df 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -276,78 +276,94 @@ final class BloopServers( def ensureDesiredJvmSettings( maybeRequestedBloopJvmProperties: Option[List[String]], maybeRunningBloopJvmProperties: Option[List[String]], + maybeRequestedMetalsJavaHome: Option[String], maybeRunningMetalsJavaHome: Option[String], maybeRequestedBloopJavaHome: Option[String], maybeRunningBloopJavaHome: Option[String], reconnect: () => Future[BuildChange] ): Future[Unit] = { val result = - for { // if the requestedBloopJvmProperties and bloopGlobalJsonFilePath are defined - requestedBloopJvmProperties <- maybeRequestedBloopJvmProperties + for { // if bloopGlobalJsonFilePath is defined bloopGlobalJsonFilePath <- getBloopFilePath(fileName = "bloop.json") bloopCreatedByMetalsFilePath <- getBloopFilePath(fileName = "created_by_metals.lock" ) - } yield - if ( - maybeRequestedBloopJvmProperties != maybeRunningBloopJvmProperties && - !(requestedBloopJvmProperties.isEmpty && maybeRunningBloopJvmProperties.isEmpty) - ) { // the properties are updated - if ( - bloopGlobalJsonFilePath.exists && - getBloopGlobalJsonLastModifiedTime( - bloopGlobalJsonFilePath - ) > getBloopGlobalJsonLastModifiedByMetalsTime( - bloopCreatedByMetalsFilePath - ) - ) { - // the global json file was previously modified by the user through other means; - // therefore overwriting it requires user input - languageClient - .showMessageRequest( - Messages.BloopGlobalJsonFilePremodified.params() + maybeJavaHome = maybeRequestedBloopJavaHome.orElse( + maybeRequestedMetalsJavaHome + ) + requestedBloopJvmProperties = maybeRequestedBloopJvmProperties + .getOrElse(List.empty) + if maybeRequestedBloopJvmProperties != maybeRunningBloopJvmProperties || + maybeRequestedBloopJavaHome != maybeRunningBloopJavaHome || + maybeRequestedMetalsJavaHome != maybeRunningMetalsJavaHome + } yield updateBloopJvmProperties( + requestedBloopJvmProperties, + bloopGlobalJsonFilePath, + bloopCreatedByMetalsFilePath, + maybeJavaHome, + reconnect + ) + result.getOrElse { Future.successful() } + } + + private def updateBloopJvmProperties( + requestedBloopJvmProperties: List[String], + bloopGlobalJsonFilePath: AbsolutePath, + bloopCreatedByMetalsFilePath: AbsolutePath, + maybeJavaHome: Option[String], + reconnect: () => Future[BuildChange] + ): Future[Unit] = { // the properties are updated + if ( + bloopGlobalJsonFilePath.exists && + getBloopGlobalJsonLastModifiedTime( + bloopGlobalJsonFilePath + ) > getBloopGlobalJsonLastModifiedByMetalsTime( + bloopCreatedByMetalsFilePath + ) + ) { + // the global json file was previously modified by the user through other means; + // therefore overwriting it requires user input + languageClient + .showMessageRequest( + Messages.BloopGlobalJsonFilePremodified.params() + ) + .asScala + .flatMap { + processUserPreferenceForBloopJvmProperties( + _, + bloopGlobalJsonFilePath, + bloopCreatedByMetalsFilePath, + requestedBloopJvmProperties, + maybeJavaHome, + reconnect + ) andThen { + case Failure(exception) => + languageClient.showMessage( + MessageType.Error, + exception.getMessage ) - .asScala - .flatMap { - processUserPreferenceForBloopJvmProperties( - _, - bloopGlobalJsonFilePath, - bloopCreatedByMetalsFilePath, - requestedBloopJvmProperties, - maybeJavaHome, - reconnect - ) andThen { - case Failure(exception) => - languageClient.showMessage( - MessageType.Error, - exception.getMessage - ) - case Success(_) => Future.successful() - } - } - } else { - // bloop global json file did not exist; or it was last modified by metals; - // hence it can get created or overwritten by Metals with no worries - // about overriding the user preferred settings - updateBloopGlobalJsonFileThenRestart( - bloopGlobalJsonFilePath, - bloopCreatedByMetalsFilePath, - requestedBloopJvmProperties, - maybeJavaHome, - reconnect - ) andThen { - case Failure(exception) => - languageClient.showMessage( - MessageType.Error, - exception.getMessage - ) - case Success(_) => Future.successful() - } + case Success(_) => Future.successful() } - } else Future.successful(()) - - result.getOrElse(Future.successful(())) - + } + } else { + // bloop global json file did not exist; or it was last modified by metals; + // hence it can get created or overwritten by Metals with no worries + // about overriding the user preferred settings + updateBloopGlobalJsonFileThenRestart( + bloopGlobalJsonFilePath, + bloopCreatedByMetalsFilePath, + requestedBloopJvmProperties, + maybeJavaHome, + reconnect + ) andThen { + case Failure(exception) => + languageClient.showMessage( + MessageType.Error, + exception.getMessage + ) + case Success(_) => Future.successful() + } + } } private def connectToLauncher( diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala index 6486ed18350..f3f77442073 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala @@ -1310,6 +1310,7 @@ class MetalsLanguageServer( bloopServers.ensureDesiredJvmSettings( userConfig.bloopJvmProperties, old.bloopJvmProperties, + userConfig.javaHome, old.javaHome, userConfig.bloopJavaHome, old.bloopJavaHome, From 9d3ef523613b456b3e216e86228d0baa8eab6d10 Mon Sep 17 00:00:00 2001 From: zmerr Date: Tue, 26 Apr 2022 21:55:48 +0400 Subject: [PATCH 03/10] update Bloop JavaHome to Metals' JavaHome only when Bloop does not have a preferred different one! --- .../scala/scala/meta/internal/metals/BloopServers.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index e5d7d8d25df..678b677bf1a 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -264,9 +264,8 @@ final class BloopServers( * * @param maybeRequestedBloopJvmProperties Bloop JVM Properties requested * through the Metals Extension settings - * @param maybeRunningBloopJvmProperties - * @param maybeJavaHome Metals' `javaHome`, which Bloop - * should also preferebly use + * @param maybeRequestedMetalsJavaHome Metals' requested `javaHome`, which Bloop + * should also preferably use * @param reconnect function to connect back to the * build server. * @return `Future.successful` if the purpose is achieved or `Future.failure` @@ -295,7 +294,9 @@ final class BloopServers( .getOrElse(List.empty) if maybeRequestedBloopJvmProperties != maybeRunningBloopJvmProperties || maybeRequestedBloopJavaHome != maybeRunningBloopJavaHome || - maybeRequestedMetalsJavaHome != maybeRunningMetalsJavaHome + (maybeRequestedMetalsJavaHome != maybeRunningMetalsJavaHome && + maybeRunningBloopJavaHome.isEmpty) // update Bloop JavaHome to Metals' JavaHome + // only when Bloop does not have a preferred different one! } yield updateBloopJvmProperties( requestedBloopJvmProperties, bloopGlobalJsonFilePath, From 5dd108ccbecbc7266d9efc54f8a727f97a12fe94 Mon Sep 17 00:00:00 2001 From: zmerr Date: Mon, 2 May 2022 10:55:18 +0400 Subject: [PATCH 04/10] remove bloop java home --- .../scala/meta/internal/metals/BloopServers.scala | 15 +++------------ .../internal/metals/MetalsLanguageServer.scala | 2 -- .../meta/internal/metals/UserConfiguration.scala | 4 ---- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index 678b677bf1a..79024c4c87b 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -264,8 +264,6 @@ final class BloopServers( * * @param maybeRequestedBloopJvmProperties Bloop JVM Properties requested * through the Metals Extension settings - * @param maybeRequestedMetalsJavaHome Metals' requested `javaHome`, which Bloop - * should also preferably use * @param reconnect function to connect back to the * build server. * @return `Future.successful` if the purpose is achieved or `Future.failure` @@ -277,8 +275,6 @@ final class BloopServers( maybeRunningBloopJvmProperties: Option[List[String]], maybeRequestedMetalsJavaHome: Option[String], maybeRunningMetalsJavaHome: Option[String], - maybeRequestedBloopJavaHome: Option[String], - maybeRunningBloopJavaHome: Option[String], reconnect: () => Future[BuildChange] ): Future[Unit] = { val result = @@ -287,21 +283,16 @@ final class BloopServers( bloopCreatedByMetalsFilePath <- getBloopFilePath(fileName = "created_by_metals.lock" ) - maybeJavaHome = maybeRequestedBloopJavaHome.orElse( - maybeRequestedMetalsJavaHome - ) + requestedBloopJvmProperties = maybeRequestedBloopJvmProperties .getOrElse(List.empty) if maybeRequestedBloopJvmProperties != maybeRunningBloopJvmProperties || - maybeRequestedBloopJavaHome != maybeRunningBloopJavaHome || - (maybeRequestedMetalsJavaHome != maybeRunningMetalsJavaHome && - maybeRunningBloopJavaHome.isEmpty) // update Bloop JavaHome to Metals' JavaHome - // only when Bloop does not have a preferred different one! + (maybeRequestedMetalsJavaHome != maybeRunningMetalsJavaHome) } yield updateBloopJvmProperties( requestedBloopJvmProperties, bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, - maybeJavaHome, + maybeRequestedMetalsJavaHome, reconnect ) result.getOrElse { Future.successful() } diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala index f3f77442073..b0fdadb9aab 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala @@ -1312,8 +1312,6 @@ class MetalsLanguageServer( old.bloopJvmProperties, userConfig.javaHome, old.javaHome, - userConfig.bloopJavaHome, - old.bloopJavaHome, () => autoConnectToBuildServer() ) diff --git a/metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala b/metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala index e1390276782..98c1e52ab8c 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala @@ -39,7 +39,6 @@ case class UserConfiguration( bloopSbtAlreadyInstalled: Boolean = false, bloopVersion: Option[String] = None, bloopJvmProperties: Option[List[String]] = None, - bloopJavaHome: Option[String] = None, ammoniteJvmProperties: Option[List[String]] = None, superMethodLensesEnabled: Boolean = false, showInferredType: Boolean = false, @@ -450,8 +449,6 @@ object UserConfiguration { val bloopVersion = getStringKey("bloop-version") val bloopJvmProperties = getStringListKey("bloop-jvm-properties") - val bloopJavaHome = - getStringKey("bloop-java-home") val superMethodLensesEnabled = getBooleanKey("super-method-lenses-enabled").getOrElse(false) val showInferredType = @@ -507,7 +504,6 @@ object UserConfiguration { bloopSbtAlreadyInstalled, bloopVersion, bloopJvmProperties, - bloopJavaHome, ammoniteProperties, superMethodLensesEnabled, showInferredType, From 0a172ef240865d3d8271d571a828e78f23a3f690 Mon Sep 17 00:00:00 2001 From: zmerr Date: Fri, 6 May 2022 21:31:08 +0400 Subject: [PATCH 05/10] preloading the running jvmOptions and javaHome with the contents of Bloop global json file --- .../meta/internal/metals/BloopServers.scala | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index 79024c4c87b..b05d5ebe9f1 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -241,6 +241,27 @@ final class BloopServers( }.toOption } + private def maybeLoadBloopGlobalJsonFile( + bloopGlobalJsonFilePath: AbsolutePath + ): (Option[String], Option[List[String]]) = { + val maybeData = util.Try { + val source = scala.io.Source.fromFile(bloopGlobalJsonFilePath.toURI) + val jsonString = + try source.mkString + finally source.close() + ujson.read(jsonString) + } + val javaHome = maybeData.flatMap { data => + util.Try(data("javaHome").str) + }.toOption + val javaOptions = maybeData.flatMap { data => + util.Try { + data("javaOptions").arr.toList.map(_.str) + } + } + (javaHome, javaOptions.toOption) + } + private def getBloopGlobalJsonLastModifiedTime( bloopGlobalJsonFilePath: AbsolutePath ): Long = @@ -277,17 +298,21 @@ final class BloopServers( maybeRunningMetalsJavaHome: Option[String], reconnect: () => Future[BuildChange] ): Future[Unit] = { + val result = for { // if bloopGlobalJsonFilePath is defined bloopGlobalJsonFilePath <- getBloopFilePath(fileName = "bloop.json") bloopCreatedByMetalsFilePath <- getBloopFilePath(fileName = "created_by_metals.lock" ) - + (maybeBloopGlobalJsonJavaHome, maybeBloopGlobalJsonJvmProperties) = + maybeLoadBloopGlobalJsonFile(bloopGlobalJsonFilePath) requestedBloopJvmProperties = maybeRequestedBloopJvmProperties .getOrElse(List.empty) - if maybeRequestedBloopJvmProperties != maybeRunningBloopJvmProperties || - (maybeRequestedMetalsJavaHome != maybeRunningMetalsJavaHome) + if (maybeRequestedBloopJvmProperties != maybeRunningBloopJvmProperties + && maybeRequestedBloopJvmProperties != maybeBloopGlobalJsonJvmProperties) || + (maybeRequestedMetalsJavaHome != maybeRunningMetalsJavaHome + && maybeRequestedMetalsJavaHome != maybeBloopGlobalJsonJavaHome) } yield updateBloopJvmProperties( requestedBloopJvmProperties, bloopGlobalJsonFilePath, @@ -295,7 +320,9 @@ final class BloopServers( maybeRequestedMetalsJavaHome, reconnect ) - result.getOrElse { Future.successful() } + result.getOrElse { + Future.successful() + } } private def updateBloopJvmProperties( From 5214f6d58a33c820036696c24fbbebab5d516461 Mon Sep 17 00:00:00 2001 From: zmerr Date: Tue, 10 May 2022 17:42:45 +0400 Subject: [PATCH 06/10] removed running jvm properties and running java home from the bloop restart conditions! --- .../scala/meta/internal/metals/BloopServers.scala | 14 +++++--------- .../internal/metals/MetalsLanguageServer.scala | 2 -- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index b05d5ebe9f1..ba6bfbe5df9 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -244,7 +244,7 @@ final class BloopServers( private def maybeLoadBloopGlobalJsonFile( bloopGlobalJsonFilePath: AbsolutePath ): (Option[String], Option[List[String]]) = { - val maybeData = util.Try { + val maybeData = Try { val source = scala.io.Source.fromFile(bloopGlobalJsonFilePath.toURI) val jsonString = try source.mkString @@ -252,10 +252,10 @@ final class BloopServers( ujson.read(jsonString) } val javaHome = maybeData.flatMap { data => - util.Try(data("javaHome").str) + Try(data("javaHome").str) }.toOption val javaOptions = maybeData.flatMap { data => - util.Try { + Try { data("javaOptions").arr.toList.map(_.str) } } @@ -293,9 +293,7 @@ final class BloopServers( */ def ensureDesiredJvmSettings( maybeRequestedBloopJvmProperties: Option[List[String]], - maybeRunningBloopJvmProperties: Option[List[String]], maybeRequestedMetalsJavaHome: Option[String], - maybeRunningMetalsJavaHome: Option[String], reconnect: () => Future[BuildChange] ): Future[Unit] = { @@ -309,10 +307,8 @@ final class BloopServers( maybeLoadBloopGlobalJsonFile(bloopGlobalJsonFilePath) requestedBloopJvmProperties = maybeRequestedBloopJvmProperties .getOrElse(List.empty) - if (maybeRequestedBloopJvmProperties != maybeRunningBloopJvmProperties - && maybeRequestedBloopJvmProperties != maybeBloopGlobalJsonJvmProperties) || - (maybeRequestedMetalsJavaHome != maybeRunningMetalsJavaHome - && maybeRequestedMetalsJavaHome != maybeBloopGlobalJsonJavaHome) + if maybeRequestedBloopJvmProperties != maybeBloopGlobalJsonJvmProperties || + maybeRequestedMetalsJavaHome != maybeBloopGlobalJsonJavaHome } yield updateBloopJvmProperties( requestedBloopJvmProperties, bloopGlobalJsonFilePath, diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala index b0fdadb9aab..fef5db2fc70 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala @@ -1309,9 +1309,7 @@ class MetalsLanguageServer( bloopServers.ensureDesiredJvmSettings( userConfig.bloopJvmProperties, - old.bloopJvmProperties, userConfig.javaHome, - old.javaHome, () => autoConnectToBuildServer() ) From 6dbd491d4cbffc447f3efc3a249eed3f5c13d98f Mon Sep 17 00:00:00 2001 From: zmerr Date: Mon, 16 May 2022 11:58:06 +0400 Subject: [PATCH 07/10] added the cause to Bloop restart request --- .../meta/internal/metals/BloopServers.scala | 43 +++++++---- .../scala/meta/internal/metals/Messages.scala | 73 ++++++++++++++++++- 2 files changed, 99 insertions(+), 17 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index ba6bfbe5df9..e58a03934d3 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -16,6 +16,7 @@ import scala.util.Success import scala.util.Try import scala.meta.internal.bsp.BuildChange +import scala.meta.internal.metals.BloopJsonUpdateCause.BloopJsonUpdateCause import scala.meta.internal.metals.MetalsEnrichments._ import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.io.AbsolutePath @@ -120,10 +121,10 @@ final class BloopServers( shutdownServer() reconnect().ignoreValue case _ => - Future.successful(()) + Future.unit } } else { - Future.successful(()) + Future.unit } } @@ -195,7 +196,7 @@ final class BloopServers( case item if item == Messages.BloopGlobalJsonFilePremodified.useGlobalFile => - Future.successful(()) + Future.unit } } @@ -204,6 +205,7 @@ final class BloopServers( bloopCreatedByMetalsFilePath: AbsolutePath, requestedBloopJvmProperties: List[String], maybeJavaHome: Option[String], + bloopJsonUpdateCause: BloopJsonUpdateCause, reconnect: () => Future[BuildChange] ): Future[Unit] = { writeJVMPropertiesToBloopGlobalJsonFile( @@ -216,7 +218,7 @@ final class BloopServers( case Success(_) => languageClient .showMessageRequest( - Messages.BloopJvmPropertiesChange.params() + Messages.BloopJvmPropertiesChange.params(bloopJsonUpdateCause) ) .asScala .flatMap { @@ -225,7 +227,7 @@ final class BloopServers( shutdownServer() reconnect().ignoreValue case _ => - Future.successful(()) + Future.unit } } @@ -307,17 +309,24 @@ final class BloopServers( maybeLoadBloopGlobalJsonFile(bloopGlobalJsonFilePath) requestedBloopJvmProperties = maybeRequestedBloopJvmProperties .getOrElse(List.empty) - if maybeRequestedBloopJvmProperties != maybeBloopGlobalJsonJvmProperties || - maybeRequestedMetalsJavaHome != maybeBloopGlobalJsonJavaHome + bloopJsonUpdateCause <- + if ( + maybeRequestedBloopJvmProperties != maybeBloopGlobalJsonJvmProperties + ) Some(BloopJsonUpdateCause.JVM_OPTS) + else if (maybeRequestedMetalsJavaHome != maybeBloopGlobalJsonJavaHome) + Some(BloopJsonUpdateCause.JAVA_HOME) + else None } yield updateBloopJvmProperties( requestedBloopJvmProperties, bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, maybeRequestedMetalsJavaHome, - reconnect + reconnect, + bloopJsonUpdateCause ) + result.getOrElse { - Future.successful() + Future.unit } } @@ -326,7 +335,8 @@ final class BloopServers( bloopGlobalJsonFilePath: AbsolutePath, bloopCreatedByMetalsFilePath: AbsolutePath, maybeJavaHome: Option[String], - reconnect: () => Future[BuildChange] + reconnect: () => Future[BuildChange], + bloopJsonUpdateCause: BloopJsonUpdateCause ): Future[Unit] = { // the properties are updated if ( bloopGlobalJsonFilePath.exists && @@ -340,7 +350,7 @@ final class BloopServers( // therefore overwriting it requires user input languageClient .showMessageRequest( - Messages.BloopGlobalJsonFilePremodified.params() + Messages.BloopGlobalJsonFilePremodified.params(bloopJsonUpdateCause) ) .asScala .flatMap { @@ -357,7 +367,7 @@ final class BloopServers( MessageType.Error, exception.getMessage ) - case Success(_) => Future.successful() + case Success(_) => Future.unit } } } else { @@ -369,6 +379,7 @@ final class BloopServers( bloopCreatedByMetalsFilePath, requestedBloopJvmProperties, maybeJavaHome, + bloopJsonUpdateCause, reconnect ) andThen { case Failure(exception) => @@ -376,7 +387,7 @@ final class BloopServers( MessageType.Error, exception.getMessage ) - case Success(_) => Future.successful() + case Success(_) => Future.unit } } } @@ -457,6 +468,12 @@ final class BloopServers( } } +object BloopJsonUpdateCause extends Enumeration { + type BloopJsonUpdateCause = Value + val JAVA_HOME: Value = Value("Metals Java Home") + val JVM_OPTS: Value = Value("Bloop JVM Properties") +} + object BloopServers { val name = "Bloop" } diff --git a/metals/src/main/scala/scala/meta/internal/metals/Messages.scala b/metals/src/main/scala/scala/meta/internal/metals/Messages.scala index f17aef1e62c..c2cc23b3c5a 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Messages.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Messages.scala @@ -4,6 +4,7 @@ import scala.collection.mutable import scala.meta.internal.builds.BuildTool import scala.meta.internal.jdk.CollectionConverters._ +import scala.meta.internal.metals.BloopJsonUpdateCause.BloopJsonUpdateCause import scala.meta.internal.metals.clients.language.MetalsInputBoxParams import scala.meta.internal.metals.clients.language.MetalsSlowTaskParams import scala.meta.internal.metals.clients.language.MetalsStatusParams @@ -121,15 +122,19 @@ object Messages { def bloopInstallProgress(buildToolExecName: String) = new MetalsSlowTaskParams(s"$buildToolExecName bloopInstall") + def dontShowAgain: MessageActionItem = new MessageActionItem("Don't show again") + def notNow: MessageActionItem = new MessageActionItem("Not now") object ImportBuildChanges { def yes: MessageActionItem = new MessageActionItem("Import changes") + def notNow: MessageActionItem = Messages.notNow + def params(buildToolName: String): ShowMessageRequestParams = { val params = new ShowMessageRequestParams() params.setMessage(s"$buildToolName build needs to be re-imported") @@ -147,7 +152,9 @@ object Messages { object ImportBuild { def yes = new MessageActionItem("Import build") + def notNow: MessageActionItem = Messages.notNow + def params(buildToolName: String): ShowMessageRequestParams = { val params = new ShowMessageRequestParams() params.setMessage( @@ -197,23 +204,31 @@ object Messages { MessageType.Info, "Build is correctly configured now, navigation will work for all build targets." ) + def moreInfo: String = " Select 'More information' to learn how to fix this problem.." + def allProjectsMisconfigured: String = "Navigation will not work for this build due to mis-configuration." + moreInfo + def singleMisconfiguredProject(name: String): String = s"Navigation will not work in project '$name' due to mis-configuration." + moreInfo + def multipleMisconfiguredProjects(count: Int): String = s"Code navigation will not work for $count build targets in this workspace due to mis-configuration. " + moreInfo + val misconfiguredTestFrameworks: String = "Test Explorer won't work due to mis-configuration." + moreInfo def isDoctor(params: ShowMessageRequestParams): Boolean = params.getActions.asScala.contains(moreInformation) + def moreInformation: MessageActionItem = new MessageActionItem("More information") + def dismissForever: MessageActionItem = new MessageActionItem("Don't show again") + def params(problem: String): ShowMessageRequestParams = { val params = new ShowMessageRequestParams() params.setMessage(problem) @@ -232,12 +247,16 @@ object Messages { def dismissForever: MessageActionItem = new MessageActionItem("Don't show again") + def learnMore: MessageActionItem = new MessageActionItem("Learn more") + def learnMoreUrl: String = Urls.docs("import-build") + def params(tool: BuildTool): ShowMessageRequestParams = { def toFixMessage = s"To fix this problem, upgrade to $tool ${tool.recommendedVersion} " + val params = new ShowMessageRequestParams() params.setMessage( s"Automatic build import is not supported for $tool ${tool.version}. $toFixMessage" @@ -256,8 +275,10 @@ object Messages { object DisconnectedServer { def reconnect: MessageActionItem = new MessageActionItem("Reconnect to build server") + def notNow: MessageActionItem = new MessageActionItem("Not now") + def params(): ShowMessageRequestParams = { val params = new ShowMessageRequestParams() @@ -275,11 +296,14 @@ object Messages { params } } + object BloopVersionChange { def reconnect: MessageActionItem = new MessageActionItem("Restart Bloop") + def notNow: MessageActionItem = new MessageActionItem("Not now") + def params(): ShowMessageRequestParams = { val params = new ShowMessageRequestParams() params.setMessage( @@ -299,14 +323,20 @@ object Messages { object BloopGlobalJsonFilePremodified { def applyAndRestart: MessageActionItem = new MessageActionItem("Apply and Restart Bloop") + def useGlobalFile: MessageActionItem = new MessageActionItem("Use the Global File's JVM Properties") + def openGlobalJsonFile: MessageActionItem = new MessageActionItem("Open the Global File") - def params(): ShowMessageRequestParams = { + + def params( + bloopJsonUpdateCause: BloopJsonUpdateCause + ): ShowMessageRequestParams = { val params = new ShowMessageRequestParams() params.setMessage( - s"""|You have previously modified the JVM settings of Bloop in its global json file, + s"""|Setting $bloopJsonUpdateCause will result in updating Bloop's global Json file, by Metals. + |But, you have previously modified this file with other values! |Do you want to replace them with the new properties and restart the running Bloop server?""".stripMargin ) params.setType(MessageType.Warning) @@ -324,12 +354,17 @@ object Messages { object BloopJvmPropertiesChange { def reconnect: MessageActionItem = new MessageActionItem("Restart Bloop") + def notNow: MessageActionItem = new MessageActionItem("Not now") - def params(): ShowMessageRequestParams = { + + def params( + bloopJsonUpdateCause: BloopJsonUpdateCause + ): ShowMessageRequestParams = { val params = new ShowMessageRequestParams() params.setMessage( - s"New Bloop JVM properties detected. Bloop will need to be restarted in order for them to take effect." + s"""|Setting $bloopJsonUpdateCause will result in updating Bloop's global Json file, by Metals. + |Bloop will need to be restarted in order for these changes to take effect.""".stripMargin ) params.setType(MessageType.Warning) params.setActions( @@ -345,8 +380,10 @@ object Messages { object AmmoniteJvmParametersChange { def restart: MessageActionItem = new MessageActionItem("Restart Ammonite") + def notNow: MessageActionItem = new MessageActionItem("Not now") + def params(): ShowMessageRequestParams = { val params = new ShowMessageRequestParams() params.setMessage( @@ -374,10 +411,13 @@ object Messages { object IncompatibleBloopVersion { def manually: MessageActionItem = new MessageActionItem("I'll update manually") + def shutdown: MessageActionItem = new MessageActionItem("Turn off old server") + def dismissForever: MessageActionItem = new MessageActionItem("Don't show again") + def params( bloopVersion: String, minimumBloopVersion: String, @@ -459,26 +499,32 @@ object Messages { def failedToResolve(message: String): MessageParams = { new MessageParams(MessageType.Error, message) } + def fixedVersion(isAgain: Boolean): MessageParams = new MessageParams( MessageType.Info, s"Updated .scalafmt.conf${MissingScalafmtConf.tryAgain(isAgain)}." ) + def isMissingScalafmtVersion(params: ShowMessageRequestParams): Boolean = params.getMessage == messageRequestMessage + def inputBox(): MetalsInputBoxParams = MetalsInputBoxParams( prompt = "No Scalafmt version is configured for this workspace, what version would you like to use?", value = BuildInfo.scalafmtVersion ) + def messageRequestMessage: String = s"No Scalafmt version is configured for this workspace. " + s"To fix this problem, update .scalafmt.conf to include 'version=${BuildInfo.scalafmtVersion}'." + def changeVersion: MessageActionItem = new MessageActionItem( s"Update .scalafmt.conf to use v${BuildInfo.scalafmtVersion}" ) + def messageRequest(): ShowMessageRequestParams = { val params = new ShowMessageRequestParams() params.setMessage(messageRequestMessage) @@ -533,17 +579,22 @@ object Messages { def tryAgain(isAgain: Boolean): String = if (isAgain) ", try formatting again" else "" + def createFile = new MessageActionItem("Create .scalafmt.conf") + def fixedParams(isAgain: Boolean): MessageParams = new MessageParams( MessageType.Info, s"Created .scalafmt.conf${tryAgain(isAgain)}." ) + def isCreateScalafmtConf(params: ShowMessageRequestParams): Boolean = params.getMessage == createScalafmtConfMessage + def createScalafmtConfMessage: String = s"Unable to format since this workspace has no .scalafmt.conf file. " + s"To fix this problem, create an empty .scalafmt.conf and try again." + def params(): ShowMessageRequestParams = { val params = new ShowMessageRequestParams() params.setMessage(createScalafmtConfMessage) @@ -591,6 +642,7 @@ object Messages { object WorkspaceSymbolDependencies { def title: String = "Add ';' to search library dependencies" + def detail: String = """|The workspace/symbol feature ("Go to symbol in workspace") allows you to search for |classes, traits and objects that are defined in your workspace as well as library dependencies. @@ -609,6 +661,7 @@ object Messages { object NewScalaFile { def selectTheKindOfFileMessage = "Select the kind of file to create" + def enterNameMessage(kind: String): String = s"Enter the name for the new $kind" @@ -736,6 +789,7 @@ object Messages { val importAll: String = "Import scripts automatically" val doImport: String = "Import" val dismiss: String = "Dismiss" + def params(): ShowMessageRequestParams = { val params = new ShowMessageRequestParams( List(importAll, doImport, dismiss) @@ -746,6 +800,7 @@ object Messages { params.setType(MessageType.Info) params } + def ImportFailed(script: String) = new MessageParams( MessageType.Error, @@ -755,25 +810,33 @@ object Messages { object NewScalaProject { def selectTheTemplate: String = "Select the template to use" + def enterName: String = "Enter a name or a relative path for the new project" + def enterG8Template: String = "Enter the giter template, for example `scala/hello-world.g8`," + " which corresponds to a github path `github.com/scala/hello-world.g8`" + def creationFailed(what: String, where: String) = new MessageParams( MessageType.Error, s"Could not create $what in $where" ) + def templateDownloadFailed(why: String) = new MessageParams( MessageType.Error, s"Failed to download templates from the web.\n" + why ) + def yes = new MessageActionItem("Yes") + def no = new MessageActionItem("No") + def newWindowMessage = "Do you want to open the new project in a new window?" + def newProjectCreated(path: AbsolutePath) = new MessageParams( MessageType.Info, @@ -802,7 +865,9 @@ object Messages { " Do you want to create a new project?" def inCurrent = new MessageActionItem("In the current directory") + def newWindow = new MessageActionItem("In a new directory") + def dismiss = new MessageActionItem("Not now") def noBuildToolAskForTemplate(): ShowMessageRequestParams = { From 48766235f6541d839eb354f58ef2a35a84ae7a4f Mon Sep 17 00:00:00 2001 From: zmerr Date: Tue, 17 May 2022 19:26:33 +0400 Subject: [PATCH 08/10] applied reviews --- .../meta/internal/metals/BloopServers.scala | 32 +++++++++---------- .../scala/meta/internal/metals/Messages.scala | 3 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index e58a03934d3..1e2b9d7841d 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -246,22 +246,22 @@ final class BloopServers( private def maybeLoadBloopGlobalJsonFile( bloopGlobalJsonFilePath: AbsolutePath ): (Option[String], Option[List[String]]) = { - val maybeData = Try { - val source = scala.io.Source.fromFile(bloopGlobalJsonFilePath.toURI) - val jsonString = - try source.mkString - finally source.close() - ujson.read(jsonString) - } - val javaHome = maybeData.flatMap { data => - Try(data("javaHome").str) - }.toOption - val javaOptions = maybeData.flatMap { data => - Try { - data("javaOptions").arr.toList.map(_.str) - } - } - (javaHome, javaOptions.toOption) + + val maybeLinkedHashMap = + bloopGlobalJsonFilePath.readTextOpt.map(ujson.read(_)).flatMap(_.objOpt) + + val maybeJavaHome = for { + linkedHashMap <- maybeLinkedHashMap + javaHomeValue <- linkedHashMap.get("javaHome") + javaHomeStr <- javaHomeValue.strOpt + } yield javaHomeStr + + val maybeJavaOptions = for { + linkedHashMap <- maybeLinkedHashMap + javaOptionsValue <- linkedHashMap.get("javaOptions") + javaOptionsValueArray <- javaOptionsValue.arrOpt + } yield javaOptionsValueArray.flatMap(_.strOpt).toList + (maybeJavaHome, maybeJavaOptions) } private def getBloopGlobalJsonLastModifiedTime( diff --git a/metals/src/main/scala/scala/meta/internal/metals/Messages.scala b/metals/src/main/scala/scala/meta/internal/metals/Messages.scala index c2cc23b3c5a..aa0eeef5735 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/Messages.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/Messages.scala @@ -335,8 +335,7 @@ object Messages { ): ShowMessageRequestParams = { val params = new ShowMessageRequestParams() params.setMessage( - s"""|Setting $bloopJsonUpdateCause will result in updating Bloop's global Json file, by Metals. - |But, you have previously modified this file with other values! + s"""|Setting $bloopJsonUpdateCause will result in updating Bloop's global Json file by Metals, which has been previously modified manually! |Do you want to replace them with the new properties and restart the running Bloop server?""".stripMargin ) params.setType(MessageType.Warning) From e9e5c820e0236296575a837598eacc27b8bd4051 Mon Sep 17 00:00:00 2001 From: zmerr Date: Wed, 18 May 2022 16:55:26 +0400 Subject: [PATCH 09/10] do nothing when --- .../meta/internal/metals/BloopServers.scala | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index 1e2b9d7841d..4272cb8ecdc 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -131,19 +131,25 @@ final class BloopServers( private def writeJVMPropertiesToBloopGlobalJsonFile( bloopGlobalJsonFilePath: AbsolutePath, bloopCreatedByMetalsFilePath: AbsolutePath, - requestedBloopJvmProperties: List[String], + maybeRequestedBloopJvmProperties: Option[List[String]], maybeJavaHome: Option[String] ): Try[Unit] = Try { - val javaOptionsString = - s"\"javaOptions\": [${requestedBloopJvmProperties.map(property => s"\"$property\"").mkString(", ")}]" + val javaOptionsString = maybeRequestedBloopJvmProperties + .map { requestedBloopJvmProperties => + s"\"javaOptions\": [${requestedBloopJvmProperties.map(property => s"\"$property\"").mkString(", ")}]" + } + .getOrElse("") val jvmPropertiesString = maybeJavaHome .map { javaHome => - s"""|{ - | $javaOptionsString, - | \"javaHome\": \"$javaHome\" - |}""".stripMargin + if (javaOptionsString.isEmpty) + s"{ \"javaHome\": \"$javaHome\"}" + else + s"""|{ + | $javaOptionsString, + | \"javaHome\": \"$javaHome\" + |}""".stripMargin } .getOrElse(s"{$javaOptionsString}") bloopGlobalJsonFilePath.writeText(jvmPropertiesString) @@ -162,7 +168,7 @@ final class BloopServers( messageActionItem: MessageActionItem, bloopGlobalJsonFilePath: AbsolutePath, bloopCreatedByMetalsFilePath: AbsolutePath, - requestedBloopJvmProperties: List[String], + maybeRequestedBloopJvmProperties: Option[List[String]], maybeJavaHome: Option[String], reconnect: () => Future[BuildChange] ): Future[Unit] = { @@ -173,7 +179,7 @@ final class BloopServers( writeJVMPropertiesToBloopGlobalJsonFile( bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, - requestedBloopJvmProperties, + maybeRequestedBloopJvmProperties, maybeJavaHome ) match { case Failure(exception) => Future.failed(exception) @@ -203,7 +209,7 @@ final class BloopServers( private def updateBloopGlobalJsonFileThenRestart( bloopGlobalJsonFilePath: AbsolutePath, bloopCreatedByMetalsFilePath: AbsolutePath, - requestedBloopJvmProperties: List[String], + maybeRequestedBloopJvmProperties: Option[List[String]], maybeJavaHome: Option[String], bloopJsonUpdateCause: BloopJsonUpdateCause, reconnect: () => Future[BuildChange] @@ -211,7 +217,7 @@ final class BloopServers( writeJVMPropertiesToBloopGlobalJsonFile( bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, - requestedBloopJvmProperties, + maybeRequestedBloopJvmProperties, maybeJavaHome ) match { case Failure(exception) => Future.failed(exception) @@ -307,8 +313,7 @@ final class BloopServers( ) (maybeBloopGlobalJsonJavaHome, maybeBloopGlobalJsonJvmProperties) = maybeLoadBloopGlobalJsonFile(bloopGlobalJsonFilePath) - requestedBloopJvmProperties = maybeRequestedBloopJvmProperties - .getOrElse(List.empty) + bloopJsonUpdateCause <- if ( maybeRequestedBloopJvmProperties != maybeBloopGlobalJsonJvmProperties @@ -317,7 +322,7 @@ final class BloopServers( Some(BloopJsonUpdateCause.JAVA_HOME) else None } yield updateBloopJvmProperties( - requestedBloopJvmProperties, + maybeRequestedBloopJvmProperties, bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, maybeRequestedMetalsJavaHome, @@ -331,7 +336,7 @@ final class BloopServers( } private def updateBloopJvmProperties( - requestedBloopJvmProperties: List[String], + maybeRequestedBloopJvmProperties: Option[List[String]], bloopGlobalJsonFilePath: AbsolutePath, bloopCreatedByMetalsFilePath: AbsolutePath, maybeJavaHome: Option[String], @@ -358,7 +363,7 @@ final class BloopServers( _, bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, - requestedBloopJvmProperties, + maybeRequestedBloopJvmProperties, maybeJavaHome, reconnect ) andThen { @@ -377,7 +382,7 @@ final class BloopServers( updateBloopGlobalJsonFileThenRestart( bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, - requestedBloopJvmProperties, + maybeRequestedBloopJvmProperties, maybeJavaHome, bloopJsonUpdateCause, reconnect From 2746098c58382cbf4c9f6367fd249af7fd1bd2fa Mon Sep 17 00:00:00 2001 From: zmerr Date: Tue, 24 May 2022 18:13:40 +0400 Subject: [PATCH 10/10] use contents of blopp global json file, when the requested bloop jvm properties is empty --- .../meta/internal/metals/BloopServers.scala | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala index 4272cb8ecdc..7ecaa228b28 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BloopServers.scala @@ -131,13 +131,13 @@ final class BloopServers( private def writeJVMPropertiesToBloopGlobalJsonFile( bloopGlobalJsonFilePath: AbsolutePath, bloopCreatedByMetalsFilePath: AbsolutePath, - maybeRequestedBloopJvmProperties: Option[List[String]], + maybeBloopJvmProperties: Option[List[String]], maybeJavaHome: Option[String] ): Try[Unit] = Try { - val javaOptionsString = maybeRequestedBloopJvmProperties - .map { requestedBloopJvmProperties => - s"\"javaOptions\": [${requestedBloopJvmProperties.map(property => s"\"$property\"").mkString(", ")}]" + val javaOptionsString = maybeBloopJvmProperties + .map { bloopJvmProperties => + s"\"javaOptions\": [${bloopJvmProperties.map(property => s"\"$property\"").mkString(", ")}]" } .getOrElse("") @@ -168,7 +168,7 @@ final class BloopServers( messageActionItem: MessageActionItem, bloopGlobalJsonFilePath: AbsolutePath, bloopCreatedByMetalsFilePath: AbsolutePath, - maybeRequestedBloopJvmProperties: Option[List[String]], + maybeBloopJvmProperties: Option[List[String]], maybeJavaHome: Option[String], reconnect: () => Future[BuildChange] ): Future[Unit] = { @@ -179,7 +179,7 @@ final class BloopServers( writeJVMPropertiesToBloopGlobalJsonFile( bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, - maybeRequestedBloopJvmProperties, + maybeBloopJvmProperties, maybeJavaHome ) match { case Failure(exception) => Future.failed(exception) @@ -209,7 +209,7 @@ final class BloopServers( private def updateBloopGlobalJsonFileThenRestart( bloopGlobalJsonFilePath: AbsolutePath, bloopCreatedByMetalsFilePath: AbsolutePath, - maybeRequestedBloopJvmProperties: Option[List[String]], + maybeBloopJvmProperties: Option[List[String]], maybeJavaHome: Option[String], bloopJsonUpdateCause: BloopJsonUpdateCause, reconnect: () => Future[BuildChange] @@ -217,7 +217,7 @@ final class BloopServers( writeJVMPropertiesToBloopGlobalJsonFile( bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, - maybeRequestedBloopJvmProperties, + maybeBloopJvmProperties, maybeJavaHome ) match { case Failure(exception) => Future.failed(exception) @@ -317,12 +317,16 @@ final class BloopServers( bloopJsonUpdateCause <- if ( maybeRequestedBloopJvmProperties != maybeBloopGlobalJsonJvmProperties + && maybeRequestedBloopJvmProperties.nonEmpty ) Some(BloopJsonUpdateCause.JVM_OPTS) else if (maybeRequestedMetalsJavaHome != maybeBloopGlobalJsonJavaHome) Some(BloopJsonUpdateCause.JAVA_HOME) else None + maybeBloopJvmProperties = maybeRequestedBloopJvmProperties.orElse( + maybeBloopGlobalJsonJvmProperties + ) } yield updateBloopJvmProperties( - maybeRequestedBloopJvmProperties, + maybeBloopJvmProperties, bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, maybeRequestedMetalsJavaHome, @@ -336,7 +340,7 @@ final class BloopServers( } private def updateBloopJvmProperties( - maybeRequestedBloopJvmProperties: Option[List[String]], + maybeBloopJvmProperties: Option[List[String]], bloopGlobalJsonFilePath: AbsolutePath, bloopCreatedByMetalsFilePath: AbsolutePath, maybeJavaHome: Option[String], @@ -363,7 +367,7 @@ final class BloopServers( _, bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, - maybeRequestedBloopJvmProperties, + maybeBloopJvmProperties, maybeJavaHome, reconnect ) andThen { @@ -382,7 +386,7 @@ final class BloopServers( updateBloopGlobalJsonFileThenRestart( bloopGlobalJsonFilePath, bloopCreatedByMetalsFilePath, - maybeRequestedBloopJvmProperties, + maybeBloopJvmProperties, maybeJavaHome, bloopJsonUpdateCause, reconnect