# Scala 3 worksheet issues in IntelliJ

**URL:** <https://users.scala-lang.org/t/scala-3-worksheet-issues-in-intellij/9624>\
**Category:** Question\
**Created:** [November 19, 2023, 4:16pm UTC](https://users.scala-lang.org/t/scala-3-worksheet-issues-in-intellij/9624 "2023-11-19T16:16:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bersier](https://users.scala-lang.org/user_avatar/users.scala-lang.org/bersier/32/2200_2.png) [@Bersier](https://users.scala-lang.org/u/Bersier)\
**Post date:** [November 19, 2023, 4:16pm UTC](https://users.scala-lang.org/t/scala-3-worksheet-issues-in-intellij/9624/1 "2023-11-19T16:16:18Z")

</div>

I just tried using worksheets in IntelliJ, but immediately encountered several issues:

1. Definitions are compiled in-order (precluding mutual recursion and proper code organization).
2. Method overloading is not supported.
3. Building the project also compiles the worksheet as if it were a normal Scala file, leading to highlighting errors about illegal toplevel definitions.

Does anyone know how such issues can be avoided?

P.S.: I was using Scastie before, but kept running into limitations due to it being browser-based. I have also tried to switch to Visual Studio Code several times over the years, but I simply cannot remember how to do even the most basic things (like creating a new project) in that IDE, as it feels terribly unintuitive to me.

---

<div class="post-metadata">

**Author:** ![spamegg1](https://users.scala-lang.org/user_avatar/users.scala-lang.org/spamegg1/32/2131_2.png) [@spamegg1](https://users.scala-lang.org/u/spamegg1)\
**Post date:** [November 19, 2023, 7:42pm UTC](https://users.scala-lang.org/t/scala-3-worksheet-issues-in-intellij/9624/2 "2023-11-19T19:42:50Z")

</div>

IntelliJ’s Scala 3 support is not very good right now [(they are working on it)](https://www.youtube.com/watch?v=HK9IRmWO7WI).

Try VS Code with Metals extension. Create your project with SBT on the command line / Terminal: `sbt new scala/scala3.g8`, then open the folder with `build.sbt` in it with the “Open Folder” option in VS Code.

You can also use the Command Palette (Ctrl+Shift+P) then type “Metals” and there is an option to create a new worksheet:

 ![Screenshot from 2023-11-19 22-46-33](https://users.scala-lang.org/uploads/default/original/2X/b/b6c0a4ba7da077aeb109808f2a3ed1c0de578b58.png)

Another option is to use [Scala-cli](https://scala-cli.virtuslab.org/) which is an awesome new tool. Install it, then use `scala-cli setup-ide .` in a folder, and then you can open that folder in VS Code and Metals will see it. [Here](https://github.com/spamegg1/scala-toolkit-tutorial) I have an example Scala-cli project where I typed up all the [Toolkit tutorials](https://docs.scala-lang.org/toolkit/introduction.html) including worksheets and test files.

---

<div class="post-metadata">

**Author:** ![Bersier](https://users.scala-lang.org/user_avatar/users.scala-lang.org/bersier/32/2200_2.png) [@Bersier](https://users.scala-lang.org/u/Bersier)\
**Post date:** [December 5, 2023, 7:59pm UTC](https://users.scala-lang.org/t/scala-3-worksheet-issues-in-intellij/9624/3 "2023-12-05T19:59:10Z")

</div>

Regarding `scala-cli`, how can I use it to build and run an sbt project?

---

<div class="post-metadata">

**Author:** ![spamegg1](https://users.scala-lang.org/user_avatar/users.scala-lang.org/spamegg1/32/2131_2.png) [@spamegg1](https://users.scala-lang.org/u/spamegg1)\
**Post date:** [December 5, 2023, 8:22pm UTC](https://users.scala-lang.org/t/scala-3-worksheet-issues-in-intellij/9624/4 "2023-12-05T20:22:25Z")

</div>

Scala-cli is an alternative to sbt for small, single-module projects. It’s not a “full build tool.” This is intended by design. No support for multi-modules or custom tasks like sbt.

If you have a simple, single-module sbt project though, it can also be done with scala-cli. In an empty directory, run `scala-cli setup-ide .` for use with, say VS Code and Metals. Then you can add your dependencies to a file named `project.scala` in the same directory with the [`using`](https://scala-cli.virtuslab.org/docs/guides/using-directives) [directives](https://scala-cli.virtuslab.org/docs/reference/directives/#using-directives). Here’s an example I’m using for some quick scripts:

```plaintext
// this is file project.scala
//> using scala 3.3.1
//> using jvm 17
//> using toolkit latest
//> using dep org.apache.commons:commons-numbers-combinatorics:1.1
//> using dep org.scala-lang.modules::scala-parallel-collections:1.0.4
//> using dep co.computist::augment:0.0.3

```

You can look up the dependencies syntax on [Scaladex](https://index.scala-lang.org/), [for example](https://index.scala-lang.org/garlandus/augment/artifacts/augment/0.0.3):

 ![Screenshot from 2023-12-05 23-12-32](https://users.scala-lang.org/uploads/default/original/2X/2/2310b0d8697d438b741c5bf219fe656ab3780f92.png)

Then either use Metals (which will have a `run` button over `@main` methods) or on the Terminal `scala-cli run .` Same with `scala-cli test .` to run all the tests. This shows using worksheets, and Metals Testing tab, and the Terminal, whichever you prefer:

 ![Screenshot from 2023-12-05 23-20-33](https://users.scala-lang.org/uploads/default/original/2X/a/a67001c09ebba8dc0a9e74dd77c10794156861f3.png)

It works with IntelliJ too but I haven’t used it. If you want to use it _alongside_ an sbt project, there is a [way to do that too.](https://scala-cli.virtuslab.org/docs/cookbooks/intellij-sbt-with-bsp)

There is way more stuff [in the docs](https://scala-cli.virtuslab.org/docs/), also check the [Cookbook](https://scala-cli.virtuslab.org/docs/cookbooks/intro). It’s a really awesome tool. In 3.4 release `scala-cli` will replace the `scala` command.
