Skip to content

Commit

Permalink
Add cookbook - Setup ScalaCLI project in VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Nov 9, 2021
1 parent 27b23d4 commit 6dca4fc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions website/docs/cookbooks/vscode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: Setup ScalaCLI project in VSCode
sidebar_position: 7
---

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 test class.

```scala title=HelloWorld.scala
@main
def hello() = println("Hello, world")
```

```scala title=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 configurations files for VSCode support:

```bash
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.

```bash
scala-cli run .
# "Hello, world"
```

and then, we launch Visual Studio Code

```bash ignore
code .
```

After starting metals, you will see `run/debug` buttons in `HelloWorld.scala` and `test/debug` in `MyTests.test.scala`.

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

import VSCodeRun from '@site/static/img/vscode-run.png';

<img src={VSCodeRun} />

And the similar effect after pressing the `test` button.

import VSCodeTest from '@site/static/img/vscode-test.png';

<img src={VSCodeTest} />
Binary file added website/static/img/vscode-run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/vscode-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6dca4fc

Please sign in to comment.