Metals announced that "It is now possible to run and test directly from VS Code using the new "Run", "Test", "Debug" and "Debug test" buttons." There is a nice gif showing what it can do, and I don't know how to get to that point.
I tried to launch VS Code debugger with the following configurations in launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "scala",
"request": "launch",
"name": "Untitled",
"mainClass": "com.playZip.Unzip",
"args": [],
"jvmOptions": []
}
]
}
and got this error message:
Couldn't find a debug adapter descriptor for debug type 'scala' (extension might have failed to activate)
Somebody on Gitter scalameta/metals had this problem and the answer was that he needs Bloop to support utest and I think mine does because there's a file .bloop/play-zip-test.json
in my sbt project, but I'm not 100% if my Bloop supports utest and what to do if it doesn't. I tried running bloop utest
and it failed because I don't have Bloop CLI installed. I have Bloop that comes with Metals.
To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.
To debug any project in either Chrome or Microsoft Edge, all you need to do is to start a session by pressing F5 or activating the debug icon in the menu bar and selecting “Run and debug”. Alternatively, you can also use the Visual Studio Code command palette and run the “Debug: Open Link” command.
You can simply click on an element, and in a separate pane, you will be shown the corresponding code. You can also link DevTools directly to VS code via the extension debugger for chrome in the VS code marketplace - or debugger for Firefox, etc.
Document how to run or debug applications #2005 added official debugging documentation at Running and debugging your code which documents two approaches
run | debug
launch.json
configurationHere is a hello world example how to debug a test using VSC and Metals via launch.json
approach. We will use
lihaoyi/utest library and set a breakpoint in a test.
Execute sbt new scala/scala-seed.g8
to create correct project structure
Open...
sbt project with VSC or simply cd
into project and execute code .
Replace ScalaTest with utest in build.sbt
libraryDependencies += "com.lihaoyi" %% "utest" % "0.7.2" % "test",
testFrameworks += new TestFramework("utest.runner.Framework")
Replace test/scala/example/HelloSpec.scala
with HelloTests.scala
package example
import utest._
object HelloTests extends TestSuite{
val tests = Tests{
test("test1"){
1
}
}
}
Import sbt build with View | Command Palette... | Metals: Import Build
Put a breakpoint at line 8 and click Run and Debug
Select Test Suite
for Pick the kind of class to debug
Leave empty for Enter the name of the build target
Write example.HelloTests
for Enter the name of the class to debug
Write Debug example.HelloTests
for Enter the name of configuration
This should create .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "scala",
"name": "Debug example.HelloTests",
"request": "launch",
"testClass": "example.HelloTests"
}
]
}
Now you should be able to Start Debugging
by clicking the green triangle and stop at the breakpoint
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With