Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set breakpoints in vs code in a scala program

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?

like image 653
Matthias Avatar asked Mar 26 '18 11:03

Matthias


People also ask

What are conditional breakpoints How do you step through the code using breakpoints?

Conditional breakpoints allow you to break inside a code block when a defined expression evaluates to true. Conditional breakpoints highlight as orange instead of blue. Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression.


1 Answers

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.

like image 101
Mateusz Kubuszok Avatar answered Oct 05 '22 12:10

Mateusz Kubuszok