|
1 | 1 | ---
|
2 | 2 | layout: doc-page
|
3 |
| -title: "IDE support for Dotty" |
| 3 | +title: "IDE support for Scala 3" |
4 | 4 | ---
|
5 | 5 |
|
6 |
| -Dotty comes built-in with the Dotty Language Server, an implementation of the |
7 |
| -[Language Server Protocol](https://github.com/Microsoft/language-server-protocol), |
8 |
| -which means that any editor that implements the LSP can be used as a Dotty IDE. |
9 |
| -Currently, the only IDE we officially support is |
10 |
| -[Visual Studio Code](https://code.visualstudio.com/). |
11 |
| - |
12 |
| -Prerequisites |
13 |
| -============ |
14 |
| -To use this in your own Scala project, you must first get it to compile with |
15 |
| -Dotty, please follow the instructions at https://github.com/scala/scala3-example-project |
16 |
| - |
17 |
| -Usage |
18 |
| -===== |
19 |
| -1. Install [Visual Studio Code](https://code.visualstudio.com/). |
20 |
| -2. Make sure `code`, the binary for Visual Studio Code, is on your `$PATH`, this |
21 |
| - is the case if you can start the IDE by running `code` in a terminal. This |
22 |
| - is the default on all systems except Mac where you'll need to follow these |
23 |
| - instructions: https://code.visualstudio.com/docs/setup/mac#_command-line |
24 |
| -3. In your project, run: |
25 |
| -```shell |
26 |
| -sbt launchIDE |
27 |
| -``` |
28 |
| - |
29 |
| -Status |
30 |
| -====== |
31 |
| - |
32 |
| -## Fully supported features: |
33 |
| -- Typechecking as you type to show compiler errors/warnings |
34 |
| -- Type information on hover |
35 |
| -- Go to definition (in the current project) |
36 |
| -- Find all references |
37 |
| -- Documentation on hover |
38 |
| -- [Worksheet mode](worksheet-mode.md) |
39 |
| - |
40 |
| -## Partially working features: |
41 |
| -- Completion |
42 |
| -- Renaming |
43 |
| -- Go to definition in external projects |
44 |
| - |
45 |
| -## Unimplemented features: |
46 |
| -- Formatting code (requires integrating with scalafmt) |
47 |
| -- Quick fixes (probably by integrating with scalafix) |
48 |
| - |
49 |
| -## Current limitations, to be fixed: |
50 |
| -- Projects should be compiled with sbt before starting the IDE, this is |
51 |
| - automatically done for you if you run `sbt launchIDE`. |
52 |
| -- Once the IDE is started, source files that are not opened in the IDE |
53 |
| - should not be modified in some other editor, the IDE won't pick up |
54 |
| - these changes. |
55 |
| -- Not all compiler errors/warnings are displayed, just those occurring |
56 |
| - during typechecking. |
57 |
| - |
58 |
| - |
59 |
| -Feedback |
60 |
| -======== |
61 |
| -Please report issues on https://github.com/lampepfl/dotty/issues, |
62 |
| -you can also come chat with use on the |
63 |
| -[Dotty gitter channel](https://gitter.im/lampepfl/dotty)! |
| 6 | +IDE support for Scala 3 is available in IDEs based on [Scala Metals](https://scalameta.org/metals/) |
| 7 | +(e.g., Visual Studio Code, vim) and in [IntelliJ IDEA](https://www.jetbrains.com/idea/). |
| 8 | + |
| 9 | + |
| 10 | +## Using Visual Studio Code |
| 11 | + |
| 12 | +To use Visual Studio Code on a Scala 3 project, ensure you have the |
| 13 | +[Metals](https://scalameta.org/metals/docs/editors/vscode.html) plugin installed. Then open the |
| 14 | +project directory in VS code and click the "Import build" button in notification. |
| 15 | + |
| 16 | + |
| 17 | +### Under the Hood |
| 18 | + |
| 19 | +VS Code implements semantic features (such as completions, "go to definition") |
| 20 | +using the [Language Server Protocol (LSP)](https://github.com/Microsoft/language-server-protocol), |
| 21 | +so it needs a language server implementation. Metals is the implementation of LSP for Scala. It |
| 22 | +extracts semantic information from [semanticdb](https://scalameta.org/docs/semanticdb/guide.html), |
| 23 | +which is generated directly by the Scala 3 compiler. |
| 24 | + |
| 25 | +You can read more about Scala 3 support in Metals in |
| 26 | +[this blog post](https://medium.com/virtuslab/introduction-to-metals-with-scala-3-79ebf3120a95). |
| 27 | + |
| 28 | +To communicate with the build tool (e.g., to import the project, trigger builds, run tests), |
| 29 | +Metals uses the [Build Server Protocol (BSP)](https://build-server-protocol.github.io/). The |
| 30 | +default BSP implementation used by metals is [Bloop](https://scalacenter.github.io/bloop/), which |
| 31 | +supports Scala 3 projects. Alternatively, |
| 32 | +[sbt can be used as a BSP server](https://scalameta.org/metals/blog/2020/11/06/sbt-BSP-support.html) |
| 33 | +as it directly implements BSP since version 1.4. |
| 34 | + |
| 35 | + |
| 36 | +## Using IntelliJ IDEA |
| 37 | + |
| 38 | +IntelliJ has its own implementation for semantic features, so it does not use Metals or the |
| 39 | +Language Server Protocol (LSP). |
| 40 | + |
| 41 | +In order to import a project into IntelliJ there are two possibilities: |
| 42 | + - Use the built-in feature to import sbt builds |
| 43 | + - Use IntelliJ's support for the |
| 44 | + [Build Server Protocol (BSP)](https://www.jetbrains.com/help/idea/bsp-support.html) |
| 45 | + |
| 46 | + |
| 47 | +### Importing the sbt build |
| 48 | + |
| 49 | +To use IntelliJ's sbt import, go to "File" - "Open..." and select your project's `build.sbt` file. |
| 50 | + |
| 51 | +In this mode, IntelliJ starts sbt with a custom plugin to extract the project structure. After |
| 52 | +importing, IntelliJ no longer interacts with other sbt sessions. Building and running the project |
| 53 | +within the IDE is done by separate processes. |
| 54 | + |
| 55 | + |
| 56 | +### Importing the project using BSP |
| 57 | + |
| 58 | +To import a project using BSP, go to "File" - "New" - "Project from Existing Sources" and select |
| 59 | +the project directory. In the upcoming dialog select "BSP" to import the project. You may be asked |
| 60 | +to choose between "sbt" and "sbt with Bloop", the recommended option is "sbt". |
| 61 | + |
| 62 | +If the project import fails ("Problem executing BSP job"), navigate to your project in a terminal |
| 63 | +and just start `sbt`. Once sbt is running, open the "bsp" tab in IntelliJ click the "Reload" button. |
| 64 | + |
| 65 | +When using IntelliJ's BSP mode, build and run commands from the IDE are executed through sbt, so |
| 66 | +they have the same effect as building or running the project through sbt in the terminal. |
0 commit comments