Skip to content

Commit

Permalink
Merge branch 'main' into multi-root
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Apr 7, 2023
2 parents b3cdb83 + d38973c commit d0b1151
Show file tree
Hide file tree
Showing 29 changed files with 590 additions and 193 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ lazy val interfaces = project
moduleName := "mtags-interfaces",
autoScalaLibrary := false,
mimaPreviousArtifacts := Set(
"org.scalameta" % "mtags-interfaces" % "0.11.10"
"org.scalameta" % "mtags-interfaces" % "0.11.11"
),
crossPaths := false,
libraryDependencies ++= List(
Expand Down
2 changes: 1 addition & 1 deletion docs/contributors/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ you will need to make sure everything is included there.

### Update Metals version

- `build.sbt` - update `localSnapshotVersion`
- `build.sbt` - update `localSnapshotVersion` and `mimaPreviousArtifacts`
- `.github/ISSUE_TEMPLATE/bug_report.yml` - update `Version of Metals`
- `./bin/test-release.sh` - remove any unsupported Scala versions and
add newly supported ones. This will be needed later to test the new release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State

@State(Scope.Benchmark)
class SemanticHighlightBench extends PcBenchmark {
class SemanticTokensBench extends PcBenchmark {
var highlightRequests: Map[String, String] = Map.empty

private def fromZipPath(zip: AbsolutePath, path: String) = {
Expand Down
10 changes: 8 additions & 2 deletions metals/src/main/scala/scala/meta/internal/bsp/BspConnector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ class BspConnector(
bloopServers.newServer(workspace, userConfiguration).map(Some(_))
case ResolvedBspOne(details)
if details.getName() == SbtBuildTool.name =>
SbtBuildTool.writeSbtMetalsPlugins(workspace)
val connectionF = bspServers.newServer(workspace, details)
val shouldReload = SbtBuildTool.writeSbtMetalsPlugins(workspace)
val connectionF =
for {
connection <- bspServers.newServer(workspace, details)
_ <-
if (shouldReload) connection.workspaceReload()
else Future.successful(())
} yield connection
statusBar
.trackFuture("Connecting to sbt", connectionF, showTimer = true)
.map(Some(_))
Expand Down
24 changes: 22 additions & 2 deletions metals/src/main/scala/scala/meta/internal/bsp/BspServers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.security.MessageDigest
import scala.concurrent.ExecutionContextExecutorService
import scala.concurrent.Future
import scala.concurrent.Promise
import scala.util.Properties
import scala.util.Try

import scala.meta.internal.io.FileIO
Expand All @@ -21,6 +22,7 @@ import scala.meta.internal.metals.SocketConnection
import scala.meta.internal.metals.Tables
import scala.meta.internal.metals.clients.language.MetalsLanguageClient
import scala.meta.internal.mtags.MD5
import scala.meta.internal.mtags.URIEncoderDecoder
import scala.meta.internal.process.SystemProcess
import scala.meta.io.AbsolutePath

Expand Down Expand Up @@ -66,10 +68,28 @@ final class BspServers(
): Future[BuildServerConnection] = {

def newConnection(): Future[SocketConnection] = {
scribe.info(s"Running BSP server ${details.getArgv}")

val args = details.getArgv.asScala.toList
/* When running on Windows, the sbt script is passed as an argument to the
* BSP server. If the script path is encoded using URI encoding the server
* will fail to start. The workaround is to add `file://`.
* https://github.com/scalameta/metals/issues/5027
* and also:
* https://learn.microsoft.com/en-us/troubleshoot/windows-client/networking/url-encoding-unc-paths-not-url-decoded
*/
.map { arg =>
if (
Properties.isWin && arg.contains("-Dsbt.script=") &&
!arg.contains("file://") && URIEncoderDecoder.decode(arg) != arg
)
arg.replace("-Dsbt.script=", "-Dsbt.script=file://")
else
arg
}

scribe.info(s"Running BSP server $args")
val proc = SystemProcess.run(
details.getArgv.asScala.toList,
args,
projectDirectory,
redirectErrorOutput = false,
Map(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ case class SbtBuildTool(
case Some(version) =>
scribe.info(s"sbt ${version} found for workspace.")
val valid = isCompatibleVersion(firstVersionWithBsp, version)
if (valid) {
writeSbtMetalsPlugins(workspace)
} else {
if (!valid) {
scribe.warn(
s"Unable to start sbt bsp server. Make sure you have sbt >= $firstVersionWithBsp defined in your build.properties file."
)
Expand Down Expand Up @@ -184,11 +182,12 @@ object SbtBuildTool {

/**
* Write the sbt plugin in the sbt project directory
* Return true if the metals plugin file changed.
*/
def writePlugins(
projectDir: AbsolutePath,
plugins: PluginDetails*
): Unit = {
): Boolean = {
val content =
s"""|// DO NOT EDIT! This file is auto-generated.
|
Expand All @@ -203,18 +202,24 @@ object SbtBuildTool {
if (pluginFileShouldChange) {
Files.write(metalsPluginFile.toNIO, bytes)
}
pluginFileShouldChange
}

/**
* Write all the plugins used by Metals when connected to sbt server:
* - the sbt-metals plugin in the project directory
* - the sbt-jdi-tools plugin in the project/project directory
*
* Return true if any plugin file changed, meaning we should reload
*/
def writeSbtMetalsPlugins(workspace: AbsolutePath): Unit = {
def writeSbtMetalsPlugins(workspace: AbsolutePath): Boolean = {
val mainMeta = workspace.resolve("project")
val metaMeta = workspace.resolve("project").resolve("project")
writePlugins(mainMeta, metalsPluginDetails, debugAdapterPluginDetails)
writePlugins(metaMeta, metalsPluginDetails, jdiToolsPluginDetails)
val writtenPlugin =
writePlugins(mainMeta, metalsPluginDetails, debugAdapterPluginDetails)
val writtenMeta =
writePlugins(metaMeta, metalsPluginDetails, jdiToolsPluginDetails)
writtenPlugin || writtenMeta
}

private case class PluginDetails private (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BuildServerConnection private (

def isMill: Boolean = name == MillBuildTool.name

def isScalaCLI: Boolean = name == ScalaCli.name
def isScalaCLI: Boolean = ScalaCli.names(name)

def isAmmonite: Boolean = name == Ammonite.name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ class MetalsLspService(
trees,
referencesProvider,
buffers,
definitionProvider,
)

private val newFileProvider: NewFileProvider = new NewFileProvider(
Expand Down
Loading

0 comments on commit d0b1151

Please sign in to comment.