Skip to content

Commit

Permalink
build(deps): Update org.eclipse.lsp4j, ... from 0.20.1 to 0.22.0 (#6126)
Browse files Browse the repository at this point in the history
* build(deps): Update org.eclipse.lsp4j, ... from 0.20.1 to 0.22.0

* chore: Fix issues after update of lsp4j

* bugfix: Make sure body is properly deserialized

---------

Co-authored-by: Tomasz Godzik <tgodzik@virtuslab.com>
Co-authored-by: Tomasz Godzik <tgodzik@users.noreply.github.com>
  • Loading branch information
3 people authored May 24, 2024
1 parent bc45ce2 commit b73ea1c
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 9 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ lazy val mtagsShared = project
libraryDependencies ++= List(
"org.lz4" % "lz4-java" % "1.8.0",
"com.google.protobuf" % "protobuf-java" % "4.27.0",
V.guava,
"io.get-coursier" % "interface" % V.coursierInterfaces,
),
)
Expand Down Expand Up @@ -372,6 +373,7 @@ lazy val mtags3 = project
scalaVersion := V.scala3,
target := (ThisBuild / baseDirectory).value / "mtags" / "target" / "target3",
publish / skip := true,
libraryDependencies += V.guava,
scalafixConfig := Some(
(ThisBuild / baseDirectory).value / ".scalafix3.conf"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scala.meta.internal.metals.debug

import scala.reflect.ClassTag
import scala.util.Failure
import scala.util.Success
import scala.util.Try

import scala.meta.internal.metals.MetalsEnrichments._
Expand Down Expand Up @@ -221,6 +222,7 @@ object DebugProtocol {

def parse[A: ClassTag](params: Any): Try[A] = {
params match {
case a: A => Success(a)
case json: JsonElement =>
json.as[A]
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@ package scala.meta.internal.metals.debug
import java.io.BufferedInputStream
import java.io.BufferedOutputStream
import java.net.Socket
import java.util.Collections

import scala.meta.internal.metals.debug.SocketEndpoint._
import scala.collection.concurrent.TrieMap

import org.eclipse.lsp4j.debug.services.IDebugProtocolServer
import org.eclipse.lsp4j.jsonrpc.MessageConsumer
import org.eclipse.lsp4j.jsonrpc.debug.json.DebugMessageJsonHandler
import org.eclipse.lsp4j.jsonrpc.json.MethodProvider
import org.eclipse.lsp4j.jsonrpc.json.StreamMessageConsumer
import org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer
import org.eclipse.lsp4j.jsonrpc.messages.Message
import org.eclipse.lsp4j.jsonrpc.messages.RequestMessage
import org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints

private[debug] final class SocketEndpoint(socket: Socket)
extends RemoteEndpoint {
private val methods =
ServiceEndpoints.getSupportedMethods(classOf[IDebugProtocolServer])
private val handler = new DebugMessageJsonHandler(methods)
private val source = messageSource(socket)
private val target = messageTarget(socket)
private val ongoingRequests = TrieMap.empty[String, String]

override def consume(message: Message): Unit = {
message match {
case msg: RequestMessage =>
ongoingRequests.put(msg.getId(), msg.getMethod())
case _ =>
}
target.consume(message)
}

Expand All @@ -30,10 +42,18 @@ private[debug] final class SocketEndpoint(socket: Socket)
source.close()
socket.close()
}
}

private[debug] object SocketEndpoint {
private val handler = new DebugMessageJsonHandler(Collections.emptyMap())
handler.setMethodProvider {
new MethodProvider {
def resolveMethod(requestId: String): String = {
val result = ongoingRequests.get(requestId).getOrElse {
throw new RuntimeException(s"Unknown request $requestId")
}
ongoingRequests.remove(requestId)
result
}
}
}

private def messageSource(socket: Socket): StreamMessageProducer = {
val stream = new BufferedInputStream(socket.getInputStream)
Expand Down
2 changes: 1 addition & 1 deletion project/V.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object V {
val javaSemanticdb = "0.9.10"
val jsoup = "1.17.2"
val kindProjector = "0.13.3"
val lsp4jV = "0.20.1"
val lsp4jV = "0.22.0"
val mavenBloop = "2.0.0"
val mill = "0.11.7"
val mdoc = "2.5.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ private[debug] final class RemoteServer(
json.as[A].map(f).recover { case e =>
scribe.error(s"Could not handle notification [msg]", e)
}
case a: A =>
f(a)
case _ =>
scribe.error(s"Not a json: ${msg.getParams}")
}
Expand All @@ -187,6 +189,8 @@ private[debug] final class RemoteServer(
Future[Void](null).asInstanceOf[Future[B]]
case json: JsonElement =>
Future.fromTry(json.as[B])
case b: B =>
Future.successful(b)
case _ if response.getError != null =>
Future.failed(new IllegalStateException(response.getError.getMessage))
case result =>
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/src/main/scala/tests/TestingServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ final case class TestingServer(
case Some(workspaceFolders) =>
params.setWorkspaceFolders(
workspaceFolders
.map(file => new WorkspaceFolder(toPath(file).toURI.toString))
.map(file => new WorkspaceFolder(toPath(file).toURI.toString, file))
.asJava
)
case None =>
Expand Down
10 changes: 8 additions & 2 deletions tests/unit/src/test/scala/tests/DebugProtocolSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class DebugProtocolSuite
}

test("broken-workspace") {
cleanWorkspace()

def startDebugging() =
server.startDebugging(
Expand All @@ -93,8 +94,12 @@ class DebugProtocolSuite
failed = startDebugging()
debugger <- failed.recoverWith { case _: ResponseErrorException =>
server
.didSave("a/src/main/scala/a/Main.scala") { text => text + "}" }
.flatMap(_ => startDebugging())
.didSave("a/src/main/scala/a/Main.scala") { text =>
text + "}"
}
.flatMap { _ =>
startDebugging()
}
}
_ <- debugger.initialize
_ <- debugger.launch
Expand Down Expand Up @@ -136,6 +141,7 @@ class DebugProtocolSuite
}

test("restart") {
cleanWorkspace()
for {
_ <- initialize(
s"""/metals.json
Expand Down

0 comments on commit b73ea1c

Please sign in to comment.