Skip to content

Commit

Permalink
bugfix: Use actual method arguments from DAP server interface
Browse files Browse the repository at this point in the history
Previously we would use LaunchRequestArguments, but those are actually not used and what is actually returned is a Map. This become a problem after the fix that deserialized arguments to correct params.

Now, we use Map instead.

Raised the issue here eclipse-lsp4j/lsp4j#842

Also fixed tests to use newest toolkit instead.
  • Loading branch information
tgodzik committed May 27, 2024
1 parent 16c7c66 commit c87e8fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.google.gson.JsonElement
import org.eclipse.lsp4j.debug.CompletionsArguments
import org.eclipse.lsp4j.debug.DisconnectArguments
import org.eclipse.lsp4j.debug.InitializeRequestArguments
import org.eclipse.lsp4j.debug.LaunchRequestArguments
import org.eclipse.lsp4j.debug.OutputEventArguments
import org.eclipse.lsp4j.debug.SetBreakpointsArguments
import org.eclipse.lsp4j.debug.SetBreakpointsResponse
Expand Down Expand Up @@ -137,11 +136,16 @@ object DebugProtocol {
object LaunchRequest {
def unapply(request: DebugRequestMessage): Option[DebugMode] = {
if (request.getMethod != "launch") None
else
parse[LaunchRequestArguments](request.getParams).toOption.map {
case args if args.getNoDebug => DebugMode.Disabled
case _ => DebugMode.Enabled
}
else {
parse[java.util.Map[String, Object]](request.getParams).toOption
.map { map =>
map.asScala.get("noDebug") match {
case Some(value: java.lang.Boolean) if value => DebugMode.Disabled
case Some(value: java.lang.Boolean) if !value => DebugMode.Enabled
case _ => DebugMode.Enabled
}
}
}
}
}

Expand Down
14 changes: 11 additions & 3 deletions tests/slow/src/test/scala/tests/scalacli/ScalaCliSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import scala.meta.internal.metals.ServerCommands
import scala.meta.internal.metals.debug.TestDebugger
import scala.meta.internal.metals.scalacli.ScalaCli
import scala.meta.internal.metals.{BuildInfo => V}
import scala.meta.internal.mtags.CoursierComplete

import org.eclipse.{lsp4j => l}
import tests.FileLayout
Expand Down Expand Up @@ -472,14 +473,21 @@ class ScalaCliSuite extends BaseScalaCliSuite(V.scala3) {
} yield ()
}

val coursierComplete = new CoursierComplete(scalaVersion)
val newestToolkit: String = coursierComplete
.complete("org.scala-lang::toolkit:")
.headOption
.map(_.split(":").last)
.getOrElse("default")

test("properly-reindex") {
cleanWorkspace()
server.client.importBuild = Messages.ImportBuild.yes
for {
_ <- scalaCliInitialize(useBsp = true)(
s"""|/Main.scala
|//> using scala 2.13.11
|// > using toolkit default
|//> using scala ${scalaVersion}
|// > using toolkit ${newestToolkit}
|
|object Main {
| println(os.pwd)
Expand All @@ -491,7 +499,7 @@ class ScalaCliSuite extends BaseScalaCliSuite(V.scala3) {
_ <- server.didOpen("Main.scala")
_ = assertEquals(
server.client.workspaceDiagnostics,
"""|Main.scala:5:13: error: not found: value os
"""|Main.scala:5:13: error: Not found: os
| println(os.pwd)
| ^^
|""".stripMargin,
Expand Down

0 comments on commit c87e8fc

Please sign in to comment.