Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into bazel-bsp
Browse files Browse the repository at this point in the history
  • Loading branch information
jkciesluk committed Jul 18, 2023
2 parents 716ae39 + 11e52f9 commit e8f8361
Show file tree
Hide file tree
Showing 117 changed files with 2,896 additions and 1,204 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/check_scala3_nightly.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ jobs:
command: sbt javapc/test
name: Scala javapc tests
os: ubuntu-latest
- type: cross-latest-nightly
command: sbt cross-test-latest-nightly
name: Scala3 latest NIGHTLY cross test
os: ubuntu-latest
- type: scalafix
command: sbt scalafixCheck docs/docusaurusCreateSite
name: Scalafix and docs
Expand Down
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.7.4"
version = "3.7.10"
runner.dialect = scala213
project.git = true
align.preset = none
Expand Down
Binary file modified bin/scalafmt
Binary file not shown.
4 changes: 3 additions & 1 deletion bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ function bloop_version {
grep "val bloop" project/V.scala | sed -n 's/.*"\(.*\)".*/\1/p'
}

export COURSIER_REPOSITORIES="central|sonatype:snapshots"

mkdir -p ~/.bloop
cp bin/bloop.json ~/.bloop/bloop.json
curl -Lo coursier https://git.io/coursier-cli && chmod +x coursier
./coursier launch ch.epfl.scala:bloopgun-core_2.13:$(bloop_version) -- about
./coursier launch -r sonatype:snapshots ch.epfl.scala:bloopgun-core_2.13:$(bloop_version) -- about

rm .jvmopts
touch .jvmopts
Expand Down
26 changes: 12 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,6 @@ commands ++= Seq(
Command.single("test-mtags-dyn") { (s, scalaV) =>
crossTestDyn(s, scalaV)
},
// this is one is needed for `.github/workflows/check_scala3_nightly`
Command.single("save-non-published-nightlies") { (s, path) =>
val versions = Scala3NightlyVersions.nonPublishedNightlyVersions
IO.write(file(path), versions.map(_.original).mkString("\n"))
s
},
)

// -Xlint is unusable because of
Expand Down Expand Up @@ -251,11 +245,11 @@ lazy val mtagsShared = project
crossScalaVersions := {
V.supportedScalaVersions ++ V.nightlyScala3Versions
},
crossVersion := CrossVersion.binary,
crossVersion := CrossVersion.full,
Compile / packageSrc / publishArtifact := true,
libraryDependencies ++= List(
"org.lz4" % "lz4-java" % "1.8.0",
"com.google.protobuf" % "protobuf-java" % "3.23.3",
"com.google.protobuf" % "protobuf-java" % "3.23.4",
"io.get-coursier" % "interface" % V.coursierInterfaces,
),
)
Expand Down Expand Up @@ -311,6 +305,8 @@ val mtagsSettings = List(
.cross(CrossVersion.for3Use2_13)
.exclude("org.scala-lang", "scala-reflect")
.exclude("org.scala-lang", "scala-compiler")
// the correct one should be brought in by the scala 3 compiler
.exclude("org.scala-lang", "scala-library")
.exclude(
"com.lihaoyi",
"geny_2.13",
Expand Down Expand Up @@ -355,6 +351,8 @@ lazy val mtags3 = project
sharedSettings,
mtagsSettings,
Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "mtags" / "src" / "main" / "scala",
Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "mtags-shared" / "src" / "main" / "scala",
Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "mtags-shared" / "src" / "main" / "scala-3",
moduleName := "mtags3",
scalaVersion := V.scala3,
target := (ThisBuild / baseDirectory).value / "mtags" / "target" / "target3",
Expand All @@ -363,7 +361,7 @@ lazy val mtags3 = project
(ThisBuild / baseDirectory).value / ".scalafix3.conf"
),
)
.dependsOn(mtagsShared)
.dependsOn(interfaces)
.enablePlugins(BuildInfoPlugin)

lazy val mtags = project
Expand Down Expand Up @@ -400,12 +398,12 @@ lazy val metals = project
"io.undertow" % "undertow-core" % "2.2.20.Final",
"org.jboss.xnio" % "xnio-nio" % "3.8.9.Final",
// for persistent data like "dismissed notification"
"org.flywaydb" % "flyway-core" % "9.20.0",
"org.flywaydb" % "flyway-core" % "9.20.1",
"com.h2database" % "h2" % "2.1.214",
// for BSP
"org.scala-sbt.ipcsocket" % "ipcsocket" % "1.6.2",
"ch.epfl.scala" % "bsp4j" % V.bsp,
"ch.epfl.scala" %% "bloop-launcher" % V.bloop,
"ch.epfl.scala" %% "bloop-launcher-core" % V.bloop,
// for LSP
V.lsp4j,
// for DAP
Expand Down Expand Up @@ -447,15 +445,15 @@ lazy val metals = project
"com.outr" %% "scribe-file" % V.scribe,
"com.outr" %% "scribe-slf4j" % V.scribe, // needed for flyway database migrations
// for JSON formatted doctor
"com.lihaoyi" %% "ujson" % "2.0.0",
"com.lihaoyi" %% "ujson" % "3.1.2",
// For remote language server
"com.lihaoyi" %% "requests" % "0.7.1",
"com.lihaoyi" %% "requests" % "0.8.0",
// for producing SemanticDB from Scala source files
"org.scalameta" %% "scalameta" % V.scalameta,
"org.scalameta" % "semanticdb-scalac-core" % V.scalameta cross CrossVersion.full,
// For starting Ammonite
"io.github.alexarchambault.ammonite" %% "ammonite-runner" % "0.4.0",
"org.scala-lang.modules" %% "scala-xml" % "2.1.0",
"org.scala-lang.modules" %% "scala-xml" % "2.2.0",
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4",
("org.virtuslab.scala-cli" % "scala-cli-bsp" % V.scalaCli)
.exclude("ch.epfl.scala", "bsp4j"),
Expand Down
3 changes: 1 addition & 2 deletions metals-bench/src/main/scala/bench/SemanticTokensBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bench
import java.net.URI
import java.nio.charset.StandardCharsets
import java.util.concurrent.TimeUnit
import java.{util => ju}

import scala.meta.internal.io.FileIO
import scala.meta.internal.jdk.CollectionConverters._
Expand Down Expand Up @@ -71,7 +70,7 @@ class SemanticTokensBench extends PcBenchmark {
@Benchmark
@BenchmarkMode(Array(Mode.SingleShotTime))
@OutputTimeUnit(TimeUnit.MILLISECONDS)
def semanticHighlight(): ju.List[Integer] = {
def semanticHighlight(): List[Integer] = {
val pc = presentationCompiler()
val text = currentHighlight
val vFile = CompilerVirtualFileParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ case class BazelBuildTool(userConfig: () => UserConfiguration)
BazelDigest.current(workspace)
}

def createBspFileArgs(workspace: AbsolutePath): List[String] =
BazelBuildTool.coursierArgs
def createBspFileArgs(workspace: AbsolutePath): Option[List[String]] =
Option.when(workspaceSupportsBsp(workspace))(BazelBuildTool.coursierArgs)

def workspaceSupportsBsp(workspace: AbsolutePath): Boolean = {
workspace.listRecursive.exists {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.meta.internal.metals.Messages
import scala.meta.io.AbsolutePath

/**
* Helper trait for build tools that also impliment bsp
* Helper trait for build tools that also implement bsp
*/
trait BuildServerProvider extends BuildTool {

Expand All @@ -19,24 +19,18 @@ trait BuildServerProvider extends BuildTool {
workspace: AbsolutePath,
systemProcess: List[String] => Future[BspConfigGenerationStatus],
): Future[BspConfigGenerationStatus] =
if (workspaceSupportsBsp(workspace)) {
systemProcess(createBspFileArgs(workspace))
} else {
createBspFileArgs(workspace).map(systemProcess).getOrElse {
Future.successful(
Failed(Right(Messages.NoBspSupport.toString()))
)
}

/**
* Args necessary for build tool to generate the bsp config file.
*/
def createBspFileArgs(workspace: AbsolutePath): List[String]

/**
* Whether or not the build tool workspace supports BSP. Many times this is
* Args necessary for build tool to generate the bsp config file
* if the build tool workspace supports BSP. Many times this is
* limited by the version of the build tool that introduces BSP support.
*/
def workspaceSupportsBsp(workspace: AbsolutePath): Boolean
protected def createBspFileArgs(workspace: AbsolutePath): Option[List[String]]

/**
* Name of the build server if different than the actual build-tool that is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ final class BuildTools(
}
def isMill: Boolean = workspace.resolve("build.sc").isFile
def isScalaCli: Boolean =
ScalaCliBuildTool.pathsToScalaCliBsp(workspace).exists(_.isFile)
ScalaCliBuildTool
.pathsToScalaCliBsp(workspace)
.exists(_.isFile) || workspace.resolve("project.scala").isFile
def isGradle: Boolean = {
val defaultGradlePaths = List(
"settings.gradle",
Expand All @@ -89,7 +91,7 @@ final class BuildTools(
GradleBuildTool(userConfig),
MavenBuildTool(userConfig),
MillBuildTool(userConfig),
ScalaCliBuildTool(workspace),
ScalaCliBuildTool(workspace, userConfig),
BazelBuildTool(userConfig),
)
}
Expand Down Expand Up @@ -118,7 +120,7 @@ final class BuildTools(
if (isMaven) buf += MavenBuildTool(userConfig)
if (isMill) buf += MillBuildTool(userConfig)
if (isBazel) buf += BazelBuildTool(userConfig)
if (isScalaCli) buf += ScalaCliBuildTool(workspace)
if (isScalaCli) buf += ScalaCliBuildTool(workspace, userConfig)

buf.result()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ case class MillBuildTool(userConfig: () => UserConfiguration)
private def getMillVersion(workspace: AbsolutePath): String = {
import scala.meta.internal.jdk.CollectionConverters._
val millVersionPath = workspace.resolve(".mill-version")
lazy val altMillVersionPath =
workspace.resolve(".config").resolve("mill-version")
lazy val millPath = workspace.resolve("mill")
if (millVersionPath.isFile) {

def readMillVersion(path: AbsolutePath) =
Files
.readAllLines(millVersionPath.toNIO)
.readAllLines(path.toNIO)
.asScala
.headOption
.getOrElse(version)

if (millVersionPath.isFile) {
readMillVersion(millVersionPath)
} else if (altMillVersionPath.isFile) {
readMillVersion(altMillVersionPath)
} else if (millPath.isFile) {
Files
.readAllLines(millPath.toNIO)
Expand Down Expand Up @@ -121,12 +129,15 @@ case class MillBuildTool(userConfig: () => UserConfiguration)
Files.write(tempDir.resolve(predefScriptName), predefScript)
}

override def createBspFileArgs(workspace: AbsolutePath): List[String] = {
val cmd = "mill.bsp.BSP/install" :: Nil
putTogetherArgs(cmd, getMillVersion(workspace), workspace)
}
override def createBspFileArgs(
workspace: AbsolutePath
): Option[List[String]] =
Option.when(workspaceSupportsBsp(workspace: AbsolutePath)) {
val cmd = "mill.bsp.BSP/install" :: Nil
putTogetherArgs(cmd, getMillVersion(workspace), workspace)
}

override def workspaceSupportsBsp(workspace: AbsolutePath): Boolean = {
def workspaceSupportsBsp(workspace: AbsolutePath): Boolean = {
val minimumVersionForBsp = "0.10.0-M4"
val millVersion = getMillVersion(workspace)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import java.nio.file.Files
import java.nio.file.Path
import java.util.Properties

import scala.concurrent.Future

import scala.meta.inputs.Input
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.metals._
Expand Down Expand Up @@ -53,12 +55,28 @@ case class SbtBuildTool(
override val minimumVersion: String = "0.13.17"
override val recommendedVersion: String = BuildInfo.sbtVersion

override def createBspFileArgs(workspace: AbsolutePath): List[String] = {
val bspConfigArgs = List[String](
"bspConfig"
override def createBspFileArgs(
workspace: AbsolutePath
): Option[List[String]] =
Option.when(workspaceSupportsBsp(workspace)) {
val bspConfigArgs = List[String]("bspConfig")
val bspDir = workspace.resolve(".bsp").toNIO
composeArgs(bspConfigArgs, workspace, bspDir)
}

def shutdownBspServer(
shellRunner: ShellRunner,
workspace: AbsolutePath,
): Future[Int] = {
val shutdownArgs =
composeArgs(List("--client", "shutdown"), workspace, workspace.toNIO)
scribe.info(s"running ${shutdownArgs.mkString(" ")}")
shellRunner.run(
"Shutting down sbt server",
shutdownArgs,
workspace,
true,
)
val bspDir = workspace.resolve(".bsp").toNIO
composeArgs(bspConfigArgs, workspace, bspDir)
}

private def composeArgs(
Expand Down
Loading

0 comments on commit e8f8361

Please sign in to comment.