-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cookbook - Setup ScalaCLI project in VSCode
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.