how to debug scala sbt project in vs code

Viewed 3419

I am trying to debug sbt project in vs code. I have downloaded vs code extension name scala metals. How to explicitly add build.sbt folder path in scala metal.

2 Answers

How to explicitly add build.sbt folder path in scala metal

Open the root of your Scala project via VSCode, and Metals should detect your build.sbt and ask you if you want to load it. Otherwise you can do it explicitly from the Command Palette (Ctrl+Shift+P) and write "Metals Import Build"

how to debug scala sbt project in vs code

Not sure how to do it via metals. But the way I do it, is to open sbt myself from the terminal, via sbt -jvm-debug 5005. Then I attach VSCode remote debugger. You'll have to install "Debugger for Java" VSCode plugin too.

Here is the official documents: https://scalameta.org/metals/docs/editors/vscode.html,

See the "Running and debugging your code" sections.

But I found it's hard for me to debug the web project based on play framework.

So I use inntelij instead.

  1. Start the project in sbt with: sbt --jvm-debug 5006

You can run it in the terminal:

enter image description here

  1. After entered sbt, type "run" to start the proejct.

  2. Add a new debug configuration, set port to: 5006

enter image description here

  1. And then click "run->debug...", you can add the breakpoint.

enter image description here

Related