Skip to content

Commit

Permalink
fix: import from build tools, that aren't build server providers when…
Browse files Browse the repository at this point in the history
… `defaultBspToBuildTool` set to `true`
  • Loading branch information
kasiaMarek committed May 8, 2024
1 parent addef6d commit c3e1e8b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2141,10 +2141,9 @@ class MetalsLspService(
forceImport: Boolean
): Future[BuildChange] = {
val chosenBuildServer = tables.buildServers.selectedServer()
def useBuildToolBsp(buildTool: BuildTool) =
def useBuildToolBsp(buildTool: BloopInstallProvider) =
buildTool match {
case _: BloopInstallProvider => userConfig.defaultBspToBuildTool
case _: BuildServerProvider => true
case _: BuildServerProvider => userConfig.defaultBspToBuildTool
case _ => false
}

Expand Down
21 changes: 21 additions & 0 deletions tests/slow/src/test/scala/tests/PreferredBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import scala.meta.internal.metals.Messages
import scala.meta.internal.metals.UserConfiguration
import scala.meta.internal.metals.{BuildInfo => V}

import tests.maven.MavenLspSuite.defaultPom

class PreferredBuildServer extends BaseLspSuite("preferred-build-server") {
override def userConfig: UserConfiguration =
super.userConfig.copy(defaultBspToBuildTool = true)
Expand Down Expand Up @@ -77,4 +79,23 @@ class PreferredBuildServer extends BaseLspSuite("preferred-build-server") {
_ = assert(server.server.bspSession.exists(_.main.isSbt))
} yield ()
}

test("no-change-in-behavior-for-maven") {
cleanWorkspace()
val fileLayout =
s"""|/pom.xml
|$defaultPom
|/src/main/scala/A.scala
|
|""".stripMargin
FileLayout.fromString(fileLayout, workspace)
for {
_ <- server.initialize()
_ <- server.initialized()
_ = assertNoDiff(
client.workspaceMessageRequests,
Messages.ImportBuild.params("Maven").getMessage,
)
} yield ()
}
}
17 changes: 10 additions & 7 deletions tests/slow/src/test/scala/tests/maven/MavenLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ import scala.meta.io.AbsolutePath
import ch.epfl.scala.bsp4j.DebugSessionParamsDataKind
import ch.epfl.scala.bsp4j.ScalaMainClass
import tests.BaseImportSuite
import tests.maven.MavenLspSuite.defaultPom

class MavenLspSuite extends BaseImportSuite("maven-import") {

def buildTool: MavenBuildTool = MavenBuildTool(() => userConfig, workspace)

val defaultPom: String = new String(
InputStreamIO.readBytes(
this.getClass.getResourceAsStream("/test-pom.xml")
),
StandardCharsets.UTF_8,
).replace("<<>>", V.scala213)

override def currentDigest(
workspace: AbsolutePath
): Option[String] = MavenDigest.current(workspace)
Expand Down Expand Up @@ -254,3 +248,12 @@ class MavenLspSuite extends BaseImportSuite("maven-import") {
}

}

object MavenLspSuite {
val defaultPom: String = new String(
InputStreamIO.readBytes(
this.getClass.getResourceAsStream("/test-pom.xml")
),
StandardCharsets.UTF_8,
).replace("<<>>", V.scala213)
}

0 comments on commit c3e1e8b

Please sign in to comment.