Skip to content

Commit 8a17875

Browse files
authored
Merge pull request #1684 from Gedochao/tweak-ide-docs
Improve IDE support docs
2 parents ae8d960 + 6978a7c commit 8a17875

File tree

5 files changed

+58
-28
lines changed

5 files changed

+58
-28
lines changed

website/docs/cookbooks/intellij-multi-bsp.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class MyTests1 extends munit.FunSuite {
5959

6060
```scala title=app2/test/MyTests2.scala
6161
//> using lib "com.lihaoyi::utest::0.8.1"
62+
6263
import utest.*
64+
6365
object MessagesTests extends TestSuite {
6466
val tests = Tests {
6567
test("my test 2") {

website/docs/cookbooks/intellij-sbt-with-bsp.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ tree -a
7878
</ChainedSnippets>
7979

8080
Now, let's say that at some point you decide you need to occasionally run some scripts relevant to this project. You run
81-
those scripts with Scala CLI and decide it'd be convenient to keep them in the same repository.
81+
those scripts with Scala CLI and decide it'd be convenient to keep them in the same repository.
8282

8383
<ChainedSnippets>
8484
```bash ignore
@@ -92,6 +92,7 @@ scripts
9292
9393
0 directories, 2 files
9494
```
95+
9596
</ChainedSnippets>
9697

9798
However, you already import this repo as an `SBT` project, so what can you do?

website/docs/cookbooks/intellij.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Setup Scala CLI project in IDEA IntelliJ
2+
title: Setup a Scala CLI project in IDEA IntelliJ
33
sidebar_position: 7
44
---
55

@@ -13,7 +13,7 @@ Here's a walk-through for a simple import scenario.
1313

1414
```scala title=src/HelloWorld.scala
1515
@main
16-
def hello() = println("Hello, world")
16+
def hello() = println("Hello, world")
1717
```
1818

1919
```scala title=test/MyTests.test.scala

website/docs/cookbooks/vscode.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For example, here is a simple project in scala-cli which contains only one main
99

1010
```scala title=HelloWorld.scala
1111
@main
12-
def hello() = println("Hello, world")
12+
def hello() = println("Hello, world")
1313
```
1414

1515
```scala title=MyTests.test.scala
@@ -43,8 +43,8 @@ and then, we launch Visual Studio Code
4343
code .
4444
```
4545

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

4949
![layout](/img/source_layout.png)
5050

website/docs/guides/ide.md

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ sidebar_position: 10
44
---
55

66
Scala CLI currently integrates a build server using the [BSP protocol](https://build-server-protocol.github.io/).
7-
At this moment Scala CLI is not automatically detected by IDEs, so we need to use [Build Server Discovery](https://build-server-protocol.github.io/docs/server-discovery.html) from BSP protocol to generate a connection details file (`.bsp/scala-cli.json`).
7+
At this moment Scala CLI is not automatically detected by IDEs, so we need to
8+
use [Build Server Discovery](https://build-server-protocol.github.io/docs/server-discovery.html) from BSP protocol to
9+
generate a connection details file (`.bsp/scala-cli.json`).
810

911
:::note
1012
If none of these commands were run:
@@ -14,45 +16,52 @@ If none of these commands were run:
1416
- `test`
1517
- `setup-ide`
1618

17-
or a previously-generated connection detail file was deleted, your IDE will *not* use Scala CLI to configure your workspace.
19+
or a previously-generated connection detail file was deleted, your IDE will *not* use Scala CLI to configure your
20+
workspace. (Although there are ongoing efforts to improve that situation.)
1821

1922
In this case, just run one of the commands above to recreate the connection details file.
2023
:::
2124

2225
Since Scala CLI has a command-line-first approach, this is reflected in its IDE integration.
23-
By default, Scala CLI stores options passed to the last `compile`, `run`, or `test` command, and uses those options to configure the IDE.
26+
By default, Scala CLI stores options passed to the last `compile`, `run`, or `test` command, and uses those options to
27+
configure the IDE.
2428

25-
For more control we also expose the [`setup-ide` command](../commands/setup-ide.md), which lets you fine-tune the options that are passed to the IDE.
29+
For more control we also expose the [`setup-ide` command](../commands/setup-ide.md), which lets you fine-tune the
30+
options that are passed to the IDE.
2631

2732
But note that once `setup-ide` is used, Scala CLI does not update the configuration based on latest command.
28-
To enable automatic updates again, remove the `.bsp` directory and run `compile`, `run`, or `test` to recreate the connection details file.
29-
30-
<!-- TODO: Does this belong here? Is it related to IDEs? -->
31-
For now non-local sources are supported. What are non-local sources? Gists, URLs or piped sources.
33+
To enable automatic updates again, remove the `.bsp` directory and run `compile`, `run`, or `test` to recreate the
34+
connection details file.
3235

36+
## Specific IDEs supporting Scala CLI
3337

3438
Scala CLI has been tested with two main Scala IDEs:
35-
- [Metals](https://scalameta.org/metals/), which is an LSP server for Scala, and is used with [Visual Studio Code](https://code.visualstudio.com/), [Vim](https://www.vim.org/) and many other editors
36-
- [IntelliJ IDEA](https://www.jetbrains.com/idea/), with the [Scala Plugin](https://confluence.jetbrains.com/display/SCA/Scala+Plugin+for+IntelliJ+IDEA?_ga=2.54176744.1963952405.1634470110-410935139.1631638301) installed
3739

38-
In an ideal world we would replace the rest of this guide with something along the lines of, “Scala CLI works within IDEs above as you would expect.” However, mainly due to how fresh Scala CLI is, and also due to our radical approach to the project structure, using a Scala CLI project with your favourite IDE may not be as amazing as we would like. (That being said, proper IDE integration is our top priority at this moment!)
40+
- [Metals](https://scalameta.org/metals/), which is an LSP server for Scala, and is used
41+
with [Visual Studio Code](https://code.visualstudio.com/), [Vim](https://www.vim.org/) and many other editors
42+
- [IntelliJ IDEA](https://www.jetbrains.com/idea/), with
43+
the [Scala Plugin](https://confluence.jetbrains.com/display/SCA/Scala+Plugin+for+IntelliJ+IDEA?_ga=2.54176744.1963952405.1634470110-410935139.1631638301)
44+
installed
45+
46+
In an ideal world we would replace the rest of this guide with something along the lines of, “Scala CLI works within
47+
IDEs above as you would expect.” However, mainly due to how fresh Scala CLI is, and also due to our radical approach to
48+
the project structure, using a Scala CLI project with your favourite IDE may not be as amazing as we would like. (That
49+
being said, proper IDE integration is our top priority at this moment!)
3950

40-
## Metals
51+
### VS Code with Metals
4152

42-
Once Metals picks up the project structure that’s created by Scala CLI, basic features like navigation, diagnostics, and code completion should work.
43-
Reloading the workspace on project structure changes is currently experimental and should work for most scenarios, we are working on improving its stability.
44-
For some cases it may still be necessary to restart the build server manually.
45-
(Closing & reopening the project should also be sufficient.)
53+
Check the cookbook on [how to set up a Scala CLI project in VSCode with Metals](../cookbooks/vscode.md).
4654

47-
## IntelliJ
55+
### IntelliJ
4856

49-
Here are a few notes related to IntelliJ support:
50-
- IntelliJ currently does not automatically pick up changes in the project structure, so any change in dependencies, compiler options, etc., need to be manually reloaded.
51-
- Similarly to Metals, reloading the workspace on project structure changes is currently experimental and should work for most scenarios.
52-
We are working on improving its stability. For some cases it may still be necessary to restart the build server manually.
53-
(Closing & reopening the project should also be sufficient.)
57+
Cookbooks on how to work with IntelliJ:
58+
59+
- [set up a simple Scala CLI project in IDEA IntelliJ](../cookbooks/intellij.md)
60+
- [set up a Scala CLI project in IntelliJ alongside an existing SBT project](../cookbooks/intellij-sbt-with-bsp.md)
61+
- [set up multiple Scala CLI projects in IDEA IntelliJ as separate modules](../cookbooks/intellij-multi-bsp.md)
5462

5563
## Directories vs single files when working with an IDE
64+
5665
When working with Scala CLI in an IDE, it is generally suggested to use directories rather than single files.
5766

5867
```shell
@@ -66,9 +75,11 @@ everything within a given project root directory is at least implicitly treated
6675
a part of the project (and probably shown as part of your project structure).
6776

6877
This means that when you pass just a single source file to Scala CLI like this:
78+
6979
```shell
7080
scala-cli setup-ide some-directory/A.scala
7181
```
82+
7283
If you open its surrounding directory as a project, any other files present in that directory will be visible
7384
in your IDE project's structure, but they will not be included in your builds.
7485

@@ -77,16 +88,32 @@ alongside the previously configured `some-directory/A.scala`, it is probably not
7788
to create the file within the same directory in your IDE.
7889

7990
What you need to do instead is add it to your build with Scala CLI from the command line:
91+
8092
```shell
8193
scala-cli setup-ide some-directory/A.scala some-directory/B.scala
8294
```
95+
8396
There, now both `A.scala` and `B.scala` should be included in your builds when the IDE picks up the new structure.
8497

8598
Still, if you want to add/remove files like this a lot while working in an IDE,
8699
it may be a lot simpler to work on the whole directory instead:
100+
87101
```shell
88102
cd some-directory
89103
scala-cli setup-ide .
90104
```
105+
91106
That way all the contents of `some-directory` will be treated as a part of the project as you go,
92107
without the need to jump into the command line whenever you create a new file.
108+
109+
## Remote and virtual inputs
110+
111+
Do note that IDEs do not yet support working with Scala CLI's remote and virtual inputs. That includes:
112+
113+
- [piped sources](./piping.md),
114+
- URLs and [GitHub gists](../cookbooks/gists.md),
115+
- [code snippets](./snippets.md).
116+
117+
Beyond that, IDE support for some non-standard (like `.c` and `.h` resources used
118+
with [Scala Native](./scala-native.md)) and experimental inputs (like i.e. [`.md` sources](./markdown.md)) may not yet
119+
be on par with on-disk Scala and Java source files.

0 commit comments

Comments
 (0)