-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add setting to choose preferred build server #6121
Changes from 5 commits
4c59ad7
dcb090a
418060d
c7ee595
aa74d1e
fbf7933
26deddf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -56,8 +56,12 @@ case class UserConfiguration( | |||||||
verboseCompilation: Boolean = false, | ||||||||
automaticImportBuild: AutoImportBuildKind = AutoImportBuildKind.Off, | ||||||||
scalaCliLauncher: Option[String] = None, | ||||||||
defaultBSPToBuildTool: Boolean = false, | ||||||||
) { | ||||||||
|
||||||||
def shouldAutoImportNewProject: Boolean = | ||||||||
automaticImportBuild != AutoImportBuildKind.Off | ||||||||
|
||||||||
def currentBloopVersion: String = | ||||||||
bloopVersion.getOrElse(BuildInfo.bloopVersion) | ||||||||
|
||||||||
|
@@ -349,6 +353,15 @@ object UserConfiguration { | |||||||
|only automatically import a build when a project is first opened, "all" will automate | ||||||||
|build imports after subsequent changes as well.""".stripMargin, | ||||||||
), | ||||||||
UserConfigurationOption( | ||||||||
"default-bsp-to-build-tool", | ||||||||
"false", | ||||||||
"true", | ||||||||
"If used build server should default to build tool.", | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
"""|If used build server should default to the one provided by the build tool | ||||||||
|instead of the default Bloop. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|""".stripMargin, | ||||||||
), | ||||||||
) | ||||||||
|
||||||||
def fromJson( | ||||||||
|
@@ -570,6 +583,11 @@ object UserConfiguration { | |||||||
case _ => AutoImportBuildKind.Off | ||||||||
} | ||||||||
|
||||||||
val scalaCliLauncher = getStringKey("scala-cli-launcher") | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this because it seems to me it should be there but maybe there was some great scheme behind not adding this that I'm not aware of. |
||||||||
|
||||||||
val defaultBSPToBuildTool = | ||||||||
getBooleanKey("default-bsp-to-build-tool").getOrElse(false) | ||||||||
|
||||||||
if (errors.isEmpty) { | ||||||||
Right( | ||||||||
UserConfiguration( | ||||||||
|
@@ -602,6 +620,8 @@ object UserConfiguration { | |||||||
customProjectRoot, | ||||||||
verboseCompilation, | ||||||||
autoImportBuilds, | ||||||||
scalaCliLauncher, | ||||||||
defaultBSPToBuildTool, | ||||||||
) | ||||||||
) | ||||||||
} else { | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package tests | ||
|
||
import scala.meta.internal.metals.Messages | ||
import scala.meta.internal.metals.UserConfiguration | ||
import scala.meta.internal.metals.{BuildInfo => V} | ||
|
||
class PreferredBuildServer extends BaseLspSuite("preferred-build-server") { | ||
override def userConfig: UserConfiguration = | ||
super.userConfig.copy(defaultBSPToBuildTool = true) | ||
|
||
test("start-sbt-when-preferred-no-bsp") { | ||
cleanWorkspace() | ||
|
||
val importMessage = | ||
Messages.GenerateBspAndConnect.params("sbt", "sbt").getMessage() | ||
|
||
client.showMessageRequestHandler = msg => { | ||
if (msg.getMessage() == importMessage) | ||
Some(Messages.GenerateBspAndConnect.notNow) | ||
else None | ||
} | ||
|
||
val fileLayout = | ||
s"""|/project/build.properties | ||
|sbt.version=${V.sbtVersion} | ||
|/build.sbt | ||
|${SbtBuildLayout.commonSbtSettings} | ||
|ThisBuild / scalaVersion := "${V.scala213}" | ||
|val a = project.in(file("a")) | ||
|/a/src/main/scala/a/A.scala | ||
|package a | ||
|object A { | ||
| val a = 1 | ||
|} | ||
|""".stripMargin | ||
FileLayout.fromString(fileLayout, workspace) | ||
|
||
for { | ||
_ <- server.initialize() | ||
_ <- server.initialized() | ||
_ = assertNoDiff( | ||
client.workspaceMessageRequests, | ||
importMessage, | ||
) | ||
_ = assert(server.server.bspSession.isEmpty) | ||
} yield () | ||
} | ||
|
||
test("start-sbt-when-preferred-with-bsp") { | ||
cleanWorkspace() | ||
|
||
val fileLayout = | ||
s"""|/project/build.properties | ||
|sbt.version=${V.sbtVersion} | ||
|/build.sbt | ||
|${SbtBuildLayout.commonSbtSettings} | ||
|ThisBuild / scalaVersion := "${V.scala213}" | ||
|val a = project.in(file("a")) | ||
|/a/src/main/scala/a/A.scala | ||
|package a | ||
|object A { | ||
| val a = 1 | ||
|} | ||
|""".stripMargin | ||
|
||
FileLayout.fromString(fileLayout, workspace) | ||
SbtServerInitializer.generateBspConfig(workspace, V.sbtVersion) | ||
|
||
for { | ||
_ <- server.initialize() | ||
_ <- server.initialized() | ||
_ <- server.server.buildServerPromise.future | ||
_ = assertNoDiff( | ||
server.server.tables.buildServers.selectedServer().get, | ||
"sbt", | ||
) | ||
_ = assert(server.server.bspSession.exists(_.main.isSbt)) | ||
} yield () | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit