emacs-lsp / lsp-metals

lsp-mode :heart: metals
https://emacs-lsp.github.io/lsp-metals
GNU General Public License v3.0
58 stars 34 forks source link

Debug via attach is supported in metals but not working in lsp-metals. #41

Closed abhijeetsrivastava closed 3 years ago

abhijeetsrivastava commented 3 years ago

Describe the bug Scala in emacs can be debugged via -java-debug option.

Using codelens we can debug a Runnable scala file.

I have a sbt project, where I run sbt -java-debug 1234. From Intellij I can connect to this remote debugger easily. I am unable to attach to this debugger via emacs.

To Reproduce run sbt new playframework/play-scala-seed.g8

start remote debugger sbt -java-debug 1234 (might have to change the port`.

Next step (which is missing). - attach the remote debugger to emacs.

Expected behavior I would like to use remote debugger via emacs. This entire process is supported by metals. I have successfully attached this in intellij.

yyoncho commented 3 years ago

I will try to fix it, for now, I am struggling to make it work even in vscode. I asked for help metals gitter.

yyoncho commented 3 years ago

Before I come up with the full fix, that should work:(after replacing the values I have hardcoded).

(with-current-buffer "Hello.scala"
  (-let (((&DebugSession :name :uri)  
          (lsp-send-execute-command
           "debug-adapter-start"
           '(:targets [(:uri "file:/home/yyoncho/Sources/Scala/hello/?id=root")]
                      :dataKind "scala-attach-remote"
                      :data (:type "scala" :request "attach" :name "Untitled" :hostName "localhost" :port 5005)))))
    (dap-debug
     (list :debugServer (-> uri
                            (split-string ":")
                            cl-third
                            string-to-number)
           :type "scala"
           :name name
           :buildTarget "run"
           :port 5005
           :hostName "localhost"
           :host "localhost"
           :request "attach"))))
yyoncho commented 3 years ago

PR at #51