Skip to content

Commit

Permalink
Add Kotlin BSP integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Oct 8, 2024
1 parent efa473b commit 16f2eb5
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bsp/src/mill/bsp/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ private[mill] object Constants {
val bspProtocolVersion = BuildInfo.bsp4jVersion
val bspWorkerImplClass = "mill.bsp.worker.BspWorkerImpl"
val bspWorkerBuildInfoClass = "mill.bsp.worker.BuildInfo"
val languages: Seq[String] = Seq("java", "scala")
val languages: Seq[String] = Seq("java", "scala", "kotlin")
val serverName = "mill-bsp"
}
3 changes: 2 additions & 1 deletion build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ trait MillBaseTestsModule extends TestModule {
s"-DTEST_SCALATEST_VERSION=${Deps.TestDeps.scalaTest.dep.version}",
s"-DTEST_TEST_INTERFACE_VERSION=${Deps.sbtTestInterface.dep.version}",
s"-DTEST_ZIOTEST_VERSION=${Deps.TestDeps.zioTest.dep.version}",
s"-DTEST_ZINC_VERSION=${Deps.zinc.dep.version}"
s"-DTEST_ZINC_VERSION=${Deps.zinc.dep.version}",
s"-DTEST_KOTLIN_VERSION=${Deps.kotlinCompiler.dep.version}"
)
}

Expand Down
9 changes: 6 additions & 3 deletions integration/ide/bsp-server/resources/project/build.mill
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package build

import mill._
import mill.scalalib._

object `hello-java` extends JavaModule
object `hello-java` extends scalalib.JavaModule

object `hello-scala` extends ScalaModule {
object `hello-scala` extends scalalib.ScalaModule {
def scalaVersion = Option(System.getenv("TEST_SCALA_2_13_VERSION")).getOrElse(???)
}

object `hello-kotlin` extends kotlinlib.KotlinModule {
def kotlinVersion = Option(System.getenv("TEST_KOTLIN_VERSION")).getOrElse(???)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
"file:///workspace/hello-java/compile-resources"
]
},
{
"target": {
"uri": "file:///workspace/hello-kotlin"
},
"classpath": [
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/<kotlin-version>/kotlin-stdlib-<kotlin-version>.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/annotations/<annotations-version>/annotations-<annotations-version>.jar",
"file:///workspace/hello-kotlin/compile-resources"
]
},
{
"target": {
"uri": "file:///workspace/hello-scala"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
},
"modules": []
},
{
"target": {
"uri": "file:///workspace/hello-kotlin"
},
"modules": [
{
"name": "org.jetbrains.kotlin:kotlin-stdlib",
"version": "<kotlin-version>"
}
]
},
{
"target": {
"uri": "file:///workspace/hello-scala"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
},
"sources": []
},
{
"target": {
"uri": "file:///workspace/hello-kotlin"
},
"sources": [
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/<kotlin-version>/kotlin-stdlib-<kotlin-version>-sources.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/annotations/<annotations-version>/annotations-<annotations-version>-sources.jar"
]
},
{
"target": {
"uri": "file:///workspace/hello-scala"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
],
"classDirectory": "file:///workspace/out/hello-java/compile.dest/classes"
},
{
"target": {
"uri": "file:///workspace/hello-kotlin"
},
"options": [],
"classpath": [
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/<kotlin-version>/kotlin-stdlib-<kotlin-version>.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/annotations/<annotations-version>/annotations-<annotations-version>.jar",
"file:///workspace/hello-kotlin/compile-resources"
],
"classDirectory": "file:///workspace/out/hello-kotlin/compile.dest/classes"
},
{
"target": {
"uri": "file:///workspace/hello-scala"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
"environmentVariables": {},
"mainClasses": []
},
{
"target": {
"uri": "file:///workspace/hello-kotlin"
},
"classpath": [
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/<kotlin-version>/kotlin-stdlib-<kotlin-version>.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/annotations/<annotations-version>/annotations-<annotations-version>.jar",
"file:///workspace/hello-kotlin/compile-resources",
"file:///workspace/hello-kotlin/resources",
"file:///workspace/out/hello-kotlin/compile.dest/classes"
],
"jvmOptions": [],
"workingDirectory": "/workspace",
"environmentVariables": {},
"mainClasses": []
},
{
"target": {
"uri": "file:///workspace/hello-scala"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
"environmentVariables": {},
"mainClasses": []
},
{
"target": {
"uri": "file:///workspace/hello-kotlin"
},
"classpath": [
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/<kotlin-version>/kotlin-stdlib-<kotlin-version>.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/annotations/<annotations-version>/annotations-<annotations-version>.jar",
"file:///workspace/hello-kotlin/compile-resources",
"file:///workspace/hello-kotlin/resources",
"file:///workspace/out/hello-kotlin/compile.dest/classes"
],
"jvmOptions": [],
"workingDirectory": "/workspace",
"environmentVariables": {},
"mainClasses": []
},
{
"target": {
"uri": "file:///workspace/hello-scala"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
},
"outputPaths": []
},
{
"target": {
"uri": "file:///workspace/hello-kotlin"
},
"outputPaths": []
},
{
"target": {
"uri": "file:///workspace/hello-scala"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
},
"resources": []
},
{
"target": {
"uri": "file:///workspace/hello-kotlin"
},
"resources": []
},
{
"target": {
"uri": "file:///workspace/hello-scala"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
],
"classDirectory": "file:///workspace/out/hello-java/compile.dest/classes"
},
{
"target": {
"uri": "file:///workspace/hello-kotlin"
},
"options": [],
"classpath": [
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/<kotlin-version>/kotlin-stdlib-<kotlin-version>.jar",
"file:///coursier-cache/https/repo1.maven.org/maven2/org/jetbrains/annotations/<annotations-version>/annotations-<annotations-version>.jar",
"file:///workspace/hello-kotlin/compile-resources"
],
"classDirectory": "file:///workspace/out/hello-kotlin/compile.dest/classes"
},
{
"target": {
"uri": "file:///workspace/hello-scala"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
}
]
},
{
"target": {
"uri": "file:///workspace/hello-kotlin"
},
"sources": [
{
"uri": "file:///workspace/hello-kotlin/src",
"kind": 2,
"generated": false
}
]
},
{
"target": {
"uri": "file:///workspace/hello-scala"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
"compileProvider": {
"languageIds": [
"java",
"scala"
"scala",
"kotlin"
]
},
"testProvider": {
"languageIds": [
"java",
"scala"
"scala",
"kotlin"
]
},
"runProvider": {
"languageIds": [
"java",
"scala"
"scala",
"kotlin"
]
},
"debugProvider": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@
"javaVersion": "<java-version>"
}
},
{
"id": {
"uri": "file:///workspace/hello-kotlin"
},
"displayName": "hello-kotlin",
"baseDirectory": "file:///workspace/hello-kotlin",
"tags": [
"library",
"application"
],
"languageIds": [
"java",
"kotlin"
],
"dependencies": [],
"capabilities": {
"canCompile": true,
"canTest": false,
"canRun": true,
"canDebug": false
},
"dataKind": "jvm",
"data": {
"javaHome": "file:///java-home/",
"javaVersion": "<java-version>"
}
},
{
"id": {
"uri": "file:///workspace/hello-scala"
Expand Down
2 changes: 1 addition & 1 deletion integration/ide/bsp-server/src/BspServerTestUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ object BspServerTestUtil {
BuildInfo.millVersion,
b.Bsp4j.PROTOCOL_VERSION,
workspacePath.toNIO.toUri.toASCIIString,
new b.BuildClientCapabilities(List("java", "scala").asJava)
new b.BuildClientCapabilities(List("java", "scala", "kotlin").asJava)
)
).get()

Expand Down
27 changes: 24 additions & 3 deletions integration/ide/bsp-server/src/BspServerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,30 @@ object BspServerTests extends UtestIntegrationTestSuite {
}
}

val normalizedLocalValues =
normalizeLocalValuesForTesting(workspacePath) ++ scalaTransitiveSubstitutions ++ Seq(
scalaVersion -> "<scala-version>"
val kotlinVersion = sys.props.getOrElse("TEST_KOTLIN_VERSION", ???)
val kotlinTransitiveSubstitutions = {
val scalaFetchRes = coursierapi.Fetch.create()
.addDependencies(coursierapi.Dependency.of(
"org.jetbrains.kotlin",
"kotlin-stdlib",
kotlinVersion
))
.fetchResult()
scalaFetchRes.getDependencies.asScala
.filter(dep => dep.getModule.getOrganization != "org.jetbrains.kotlin")
.map { dep =>
def basePath(version: String) =
s"${dep.getModule.getOrganization.split('.').mkString("/")}/${dep.getModule.getName}/$version/${dep.getModule.getName}-$version"
basePath(dep.getVersion) -> basePath(s"<${dep.getModule.getName}-version>")
}
}

val normalizedLocalValues = normalizeLocalValuesForTesting(workspacePath) ++
scalaTransitiveSubstitutions ++
kotlinTransitiveSubstitutions ++
Seq(
scalaVersion -> "<scala-version>",
kotlinVersion -> "<kotlin-version>"
)

compareWithGsonSnapshot(
Expand Down
3 changes: 2 additions & 1 deletion integration/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ object `package` extends RootModule {
override def moduleDeps = super[IntegrationTestModule].moduleDeps
def forkEnv = super.forkEnv() ++ Seq(
"MILL_PROJECT_ROOT" -> T.workspace.toString,
"TEST_SCALA_2_13_VERSION" -> build.Deps.testScala213Version
"TEST_SCALA_2_13_VERSION" -> build.Deps.testScala213Version,
"TEST_KOTLIN_VERSION" -> build.Deps.kotlinCompiler.dep.version
)
}
trait IdeIntegrationCrossModule extends IntegrationCrossModule {
Expand Down
10 changes: 9 additions & 1 deletion kotlinlib/src/mill/kotlinlib/KotlinModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package mill
package kotlinlib

import mill.api.{Loose, PathRef, Result}
import mill.api.{Loose, PathRef, Result, internal}
import mill.define.{Command, ModuleRef, Task}
import mill.kotlinlib.worker.api.{KotlinWorker, KotlinWorkerTarget}
import mill.scalalib.api.{CompilationResult, ZincWorkerApi}
import mill.scalalib.bsp.{BspBuildTarget, BspModule}
import mill.scalalib.{JavaModule, Lib, ZincWorkerModule}
import mill.util.Jvm
import mill.util.Util.millProjectModule
Expand Down Expand Up @@ -314,6 +315,13 @@ trait KotlinModule extends JavaModule { outer =>

private[kotlinlib] def internalReportOldProblems: Task[Boolean] = zincReportCachedProblems

@internal
override def bspBuildTarget: BspBuildTarget = super.bspBuildTarget.copy(
languageIds = Seq(BspModule.LanguageId.Java, BspModule.LanguageId.Kotlin),
canCompile = true,
canRun = true
)

/**
* A test sub-module linked to its parent module best suited for unit-tests.
*/
Expand Down
1 change: 1 addition & 0 deletions scalalib/src/mill/scalalib/bsp/BspModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ object BspModule {
object LanguageId {
val Java = "java"
val Scala = "scala"
val Kotlin = "kotlin"
}

/** Used to define the [[BspBuildTarget.tags]] field. */
Expand Down

0 comments on commit 16f2eb5

Please sign in to comment.