How to set breakpoints in vs code in a scala program
Asked Answered
F

1

11

I want to debug my scala app with vscode.

My gradle run task looks as simple:

task run(type: JavaExec, dependsOn: build) {
    debug true
    main = mainClassFile
    classpath sourceSets.main.runtimeClasspath
    classpath configurations.runtime
}

The launch entry:

{
    "type": "java",
    "name": "Debug (Attach)",
    "request": "attach",
    "hostName": "localhost",
    "port": 5005
 }

Now when I launch the debugger, it waits for the vscode client. But I am not able to set any breakpoints in vscode in order to stop the debugger. For now it runs until the end, after vscode connected.

I am using the Scala and Scala Language Server.

Does someone know how to add breakpoints?

Folder answered 26/3, 2018 at 11:48 Comment(3)
Hi @Matthias, did you figure it out?Wilde
@Wilde Unfortunately not :( This was one reason why we considered not using Scala anymore.Folder
@mattias :( I'm with you. I tried all scala extensions on vscode, but nothing was really usable/good enough. (Scala is probably the worst supported language in vscode.) The best one I found was actually "dotty language server" (for Scala 3). The author has a presentation on YouTube (ScalaDays 2018) and he shows how to debug Scala code. But, unfortunately, I couldn't figure out how he did it. Anyways, thanks for the reply.Wilde
M
2

Latest release of Scala Metals (0.8.0) has a debug support - the release has an animation showing usage of debugging in Visual Studio Code, which works the same way as debugging in other languages.

This is an initial support so some cases might not be supported (see "known limitations" in the release notes of Metals 0.8.0), but you should be able to start using them.

Before that debugging was simply not supported by Scala Metals, and everyone writing Scala in need of such feature was recommended to use IntelliJ with Scala plugin.

Miscount answered 12/2, 2020 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.