Skip to content
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

chore: Update Bazel BSP #6735

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ lazy val metals = project
"localSnapshotVersion" -> localSnapshotVersion,
"metalsVersion" -> version.value,
"mdocVersion" -> V.mdoc,
"bazelBspVersion" -> V.bazelBsp,
"bspVersion" -> V.bsp,
"sbtVersion" -> sbtVersion.value,
"bloopVersion" -> V.bloop,
Expand Down Expand Up @@ -731,6 +732,7 @@ lazy val metalsDependencies = project
"ch.epfl.scala" %% "gradle-bloop" % V.gradleBloop,
"com.sourcegraph" % "semanticdb-java" % V.javaSemanticdb,
"org.foundweekends.giter8" %% "giter8" % V.gitter8Version intransitive (),
"org.jetbrains.bsp" % "bazel-bsp" % V.bazelBsp intransitive (),
),
)
.disablePlugins(ScalafixPlugin)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package scala.meta.internal.builds

import scala.meta.internal.metals.BuildInfo
import scala.meta.internal.metals.JavaBinary
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.metals.UserConfiguration
Expand Down Expand Up @@ -78,7 +79,7 @@ case class BazelBuildTool(
object BazelBuildTool {
val name: String = "bazel"
val bspName: String = "bazelbsp"
val version: String = "3.2.0-20240629-e3d8bdf-NIGHTLY"
val version: String = BuildInfo.bazelBspVersion

val mainClass = "org.jetbrains.bsp.bazel.install.Install"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ final class Compilations(
val originId = "METALS-$" + UUID.randomUUID().toString
val params = new b.CompileParams(targets.asJava)
params.setOriginId(originId)
if (
userConfiguration().verboseCompilation && (connection.isBloop || connection.isScalaCLI)
) {
params.setArguments(List("--verbose", "--best-effort").asJava)
} else { params.setArguments(List("--best-effort").asJava) }
if (connection.isBloop || connection.isScalaCLI) {
if (userConfiguration().verboseCompilation)
params.setArguments(List("--verbose", "--best-effort").asJava)
else params.setArguments(List("--best-effort").asJava)
}
targets.foreach { target =>
isCompiling(target) = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,8 @@ object MetalsEnrichments
val ld = new l.Diagnostic(
diag.getRange.toLsp,
fansi.Str(diag.getMessage, ErrorMode.Strip).plainText,
diag.getSeverity.toLsp,
if (diag.getSeverity == null) l.DiagnosticSeverity.Error
else diag.getSeverity.toLsp,
if (diag.getSource == null) "scalac" else diag.getSource,
)
Option(diag.getCode()).foreach { code =>
Expand Down
1 change: 1 addition & 0 deletions project/V.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ object V {
val ammonite3Version = "3.3.3"

val ammonite = "3.0.0-M2-15-9bed9700"
val bazelBsp = "3.2.0-20240829-fd286ccb7-NIGHTLY"
val betterMonadicFor = "0.3.1"
val bloop = "2.0.0"
val bloopConfig = "2.0.3"
Expand Down
99 changes: 51 additions & 48 deletions tests/slow/src/test/scala/tests/bazel/BazelLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BazelLspSuite
val buildTool: BazelBuildTool = BazelBuildTool(() => userConfig, workspace)

val bazelVersion = "6.4.0"
val bazel7Version = "7.3.0"

def bazelBspConfig: AbsolutePath = workspace.resolve(".bsp/bazelbsp.json")

Expand All @@ -38,55 +39,57 @@ class BazelLspSuite
val importMessage: String =
GenerateBspAndConnect.params("bazel", "bazelbsp").getMessage()

test("basic") {
cleanWorkspace()
for {
_ <- initialize(
BazelBuildLayout(workspaceLayout, V.bazelScalaVersion, bazelVersion)
)
_ = assertNoDiff(
client.workspaceMessageRequests,
List(
importMessage
).mkString("\n"),
)
_ = assert(bazelBspConfig.exists)
_ = client.messageRequests.clear() // restart
_ = assertStatus(_.isInstalled)
_ = assertNoDiff(client.workspaceDiagnostics, "")
_ <- server.didChange("WORKSPACE")(_ + "\n# comment")
_ <- server.didSave("WORKSPACE")(identity)
// Comment changes do not trigger "re-import project" request
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didChange("Hello.scala") { text =>
text.replace("def hello: String", "def hello: Int")
}
_ <- server.didSave("Hello.scala")(identity)
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|Hello.scala:4:20: error: type mismatch;
| found : String("Hello")
| required: Int
| def hello: Int = "Hello"
| ^
| def hello: Int = "Hello"
| ^
|""".stripMargin,
)
_ <- server.didChange(s"BUILD") { text =>
text.replace("\"hello\"", "\"hello1\"")
for (bazelVersion <- List(bazelVersion, bazel7Version)) {
test(s"basic-$bazelVersion") {
cleanWorkspace()
for {
_ <- initialize(
BazelBuildLayout(workspaceLayout, V.bazelScalaVersion, bazelVersion)
)
_ = assertNoDiff(
client.workspaceMessageRequests,
List(
importMessage
).mkString("\n"),
)
_ = assert(bazelBspConfig.exists)
_ = client.messageRequests.clear() // restart
_ = assertStatus(_.isInstalled)
_ = assertNoDiff(client.workspaceDiagnostics, "")
_ <- server.didChange("WORKSPACE")(_ + "\n# comment")
_ <- server.didSave("WORKSPACE")(identity)
// Comment changes do not trigger "re-import project" request
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didChange("Hello.scala") { text =>
text.replace("def hello: String", "def hello: Int")
}
_ <- server.didSave("Hello.scala")(identity)
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|Hello.scala:4:20: error: type mismatch;
| found : String("Hello")
| required: Int
| def hello: Int = "Hello"
| ^
| def hello: Int = "Hello"
| ^
|""".stripMargin,
)
_ <- server.didChange(s"BUILD") { text =>
text.replace("\"hello\"", "\"hello1\"")
}
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ = client.generateBspAndConnect = GenerateBspAndConnect.yes
_ <- server.didSave(s"BUILD")(identity)
} yield {
assertNoDiff(
client.workspaceMessageRequests,
List(
importBuildChangesMessage
).mkString("\n"),
)
server.assertBuildServerConnection()
}
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ = client.generateBspAndConnect = GenerateBspAndConnect.yes
_ <- server.didSave(s"BUILD")(identity)
} yield {
assertNoDiff(
client.workspaceMessageRequests,
List(
importBuildChangesMessage
).mkString("\n"),
)
server.assertBuildServerConnection()
}
}

Expand Down
Loading