Skip to main content

Setup a Scala CLI project in VSCode

Scala CLI can generate the files that are necessary for providing IDE support in Visual Studio Code.

For example, here is a simple project in scala-cli which contains only one main and one test class.

HelloWorld.scala
@main
def hello() = println("Hello, world")
MyTests.test.scala
//> using lib "org.scalameta::munit::1.0.0-M1"

class MyTests extends munit.FunSuite {
test("test") {
val x = 2
assertEquals(x, 2)
}
}

The following command generates configuration files for VSCode support:

scala-cli setup-ide .

There is also another way. The first time you run the run|compile|test commands, the configuration files for the VSCode will be also generated.

scala-cli run .
# "Hello, world"

and then, we launch Visual Studio Code

code .

After starting metals, you will see the run/debug buttons in HelloWorld.scala and test/debug in MyTests.test.scala ( assuming the following directory layout).

layout

Pressing the run button will run the Main.scala, the output will be visible in DebugConsole.

And the similar effect after pressing the test button.