From 2884775f29b2d38a7ca0991d1b6f4392c2de1814 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 13 Feb 2023 19:04:26 +0100 Subject: [PATCH] docs: Add more info about how to discover main class to run --- docs/integrations/debug-adapter-protocol.md | 29 +++++++++++++++++-- .../meta/internal/metals/ServerCommands.scala | 15 ++++++++++ .../internal/metals/debug/DebugProvider.scala | 2 +- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/docs/integrations/debug-adapter-protocol.md b/docs/integrations/debug-adapter-protocol.md index 39c03910788..3e0be8cbcf0 100644 --- a/docs/integrations/debug-adapter-protocol.md +++ b/docs/integrations/debug-adapter-protocol.md @@ -33,8 +33,8 @@ command. Starting a Debug Adapter Protocol session might take some time, since it needs to set up all the neccesary utilities for debugging. Metals also provides a `shellCommand` field, which will be present in the command attached to the run -main methods code lenses. This field can be used to simply run the process quickly -without the debugging capabilities. +main methods code lenses. This field can be used to simply run the process +quickly without the debugging capabilities. If you can't or won't support DAP, you can use the `runProvider` instead of `debugProvider `option in the initialization options sent from the editor to the @@ -118,11 +118,34 @@ keys that can be sent as well with the same format as above. ```json { - "path": "file:///path/to/my/file.scala" + "path": "file:///path/to/my/file.scala", "runType": "testTarget" } ``` +Instead of `debug-adapter-start` if you only want to get data about the command +to run you can use `discover-jvm-run-command`, which takes the same json as +above, but instead of starting the DAP session it will return the +`DebugSessionParams` object containing targets that this main class can be run +for along with the data about the main class which will take form of: + +```json +{ + "targets": ["id1"], + "dataKind": "scala-main-class", + "data": { + "class": "Foo", + "arguments": [], + "jvmOptions": [], + "environmentVariables": [], + "shellCommand": "java ..." + } +} +``` + +where `shellCommand` will be the exact command to run if you want to run it on +your own without DAP. + ### Wiring it all together No matter which method you use, you still need to connect the debug adapter diff --git a/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala b/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala index 9c985ff74aa..68508b661dd 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ServerCommands.scala @@ -132,6 +132,21 @@ object ServerCommands { | "runType": "run" |} |``` + | + |Response: + |```json + |{ + | "targets": ["id1"], + | "dataKind": "scala-main-class", + | "data": { + | "class": "Foo", + | "arguments": [], + | "jvmOptions": [], + | "environmentVariables": [], + | "shellCommand": "java ..." + | } + |} + |``` |""".stripMargin, ) diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala index 45655588194..65354bb4195 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProvider.scala @@ -41,6 +41,7 @@ import scala.meta.internal.metals.ScalaTestSuitesDebugRequest import scala.meta.internal.metals.SourceMapper import scala.meta.internal.metals.StacktraceAnalyzer import scala.meta.internal.metals.StatusBar +import scala.meta.internal.metals.UserConfiguration import scala.meta.internal.metals.clients.language.MetalsLanguageClient import scala.meta.internal.metals.clients.language.MetalsQuickPickItem import scala.meta.internal.metals.clients.language.MetalsQuickPickParams @@ -64,7 +65,6 @@ import com.google.common.net.InetAddresses import com.google.gson.JsonElement import org.eclipse.lsp4j.MessageParams import org.eclipse.lsp4j.MessageType -import scala.meta.internal.metals.UserConfiguration /** * @param supportsTestSelection test selection hasn't been defined in BSP spec yet.