Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dap-debug not working in small project, while lsp-lens functions well. #113

Open
gkfabs opened this issue Jan 2, 2025 · 3 comments
Open

Comments

@gkfabs
Copy link

gkfabs commented Jan 2, 2025

Describe the bug
dap-debug not working in small project, while lsp-lens functions well.

To Reproduce
A minimal Main to reproduce would be

package com.fabien.test

object Main {

  val a = 0

  def main(args: Array[String]) = {
    println(s"a = ${a}")
    val b = a + 10
    println(s"b = ${b}")
  }
}

Expected behavior
I am expecting the same behaviour with lsp-lens and dap-debug

Logs
The error message I see when running dap-debug is

helm-M-x-execute-command: ‘workspace/executeCommand’ with ‘debug-adapter-start’ failed.

(error "Could not find folder for build targets: BuildTargetIdentifier [
  uri = \"file:///home/fabs/test?id=root\"
]")
@gkfabs
Copy link
Author

gkfabs commented Jan 3, 2025

I debug the lsp calls to metals.

In the case of lsp-lens which is working I have

    [Trace - 01:39:40 PM] Sending request 'workspace/executeCommand - (132)'.
Params: {
  "command": "debug-adapter-start",
  "arguments": [
    {
      "targets": [
        {
          "uri": "file:/home/fabs/test/?id=root"
        }
      ],
      "dataKind": "scala-main-class",
      "data": {
        "class": "com.fabien.test.SmallMain",
        "arguments": [],
        "jvmOptions": [
          "-Duser.dir=/home/fabs/test"
        ],
        "environmentVariables": [
          "SHELL=/bin/bash", .....
        ],
        "shellCommand": "/\"usr\"/\"lib\"/\"jvm\"/\"java-17-openjdk-amd64\"/\"bin\"/\"java\" \"-Duser.dir=/home/fabs/test\" -classpath \"/home/fabs/test/.metals/.tmp/classpath_BE22971E1A1B89048D68DDA762B603A7.jar\" com.fabien.test.SmallMain "
      }
    }
  ]
}

In the case of dap-debug which is not working, I have

[Trace - 01:45:22 PM] Sending request 'workspace/executeCommand - (149)'.
Params: {
  "command": "debug-adapter-start",
  "arguments": [
    {
      "data": {
        "type": "scala",
        "class": "<main.class>",
        "name": "Scala Main Class",
        "arguments": [],
        "jvmOptions": [],
        "environmentVariables": []
      },
      "dataKind": "scala-main-class",
      "targets": [
        {
          "uri": "file:///home/fabs/test?id=root"
        }
      ]
    }
  ]
}

@gkfabs
Copy link
Author

gkfabs commented Jan 5, 2025

Using this template

  (dap-register-debug-template
    "Scala Launch Main"
    (list :type "scala"
          :request "launch"
          :class "com.fabien.test.SmallMain"
          :name "Scala Launch Main"
          :arguments []
          :jvmOptions []
          ))

and applying this patch

$ diff lsp-metals.el lsp-metals.el~
795,798c795,797
<                                                       "file:"
<                                                       (or (lsp-workspace-root)
<                                                           (error "The debug provide can be called under project root"))
<                                                       "/?id="
---
>                                                       (lsp--path-to-uri (or (lsp-workspace-root)
>                                                                             (error "The debug provide can be called under project root")))
>                                                       "?id="

makes it works with dap-debug

@gkfabs
Copy link
Author

gkfabs commented Jan 6, 2025

Actually to make it work for any build target, I had to apply this patch

$ diff lsp-metals.el lsp-metals.el~
795,798c795,797
<                                                       "file:"
<                                                       (or (lsp-workspace-root)
<                                                           (error "The debug provide can be called under project root"))
<                                                       "/"
<                                                       (or
<                                                        (plist-get conf :buildTarget)
<                                                        "")
<                                                       "/?id="
---
>                                                       (lsp--path-to-uri (or (lsp-workspace-root)
>                                                                             (error "The debug provide can be called under project root")))
>                                                       "?id="

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant