Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make BSP build configurations for IDEs be consistent with command line Scala CLI builds #794

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions modules/cli/src/main/scala/scala/cli/commands/SetupIde.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,7 @@ object SetupIde extends ScalaCommand[SetupIdeOptions] {
val scalaCliBspJsonDestination =
inputs.workspace / Constants.workspaceDirName / "ide-options-v2.json"

val inputArgs = inputs.elements.collect {
case d: Inputs.OnDisk =>
val path = d.path
if (os.isFile(path))
path.toString().stripSuffix(s"${path.last}")
else path.toString
}
val inputArgs = inputs.elements.collect { case d: Inputs.OnDisk => d.path.toString }

val debugOpt = options.shared.jvm.bspDebugPort.toSeq.map(port =>
s"-J-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:$port,suspend=y"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.eed3si9n.expecty.Expecty.expect
import com.github.plokhotnyuk.jsoniter_scala.core._
import com.github.plokhotnyuk.jsoniter_scala.macros._

import java.io.File
import java.net.URI
import java.nio.file.Paths

Expand Down Expand Up @@ -225,7 +224,7 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])
"bsp",
"--json-options",
(root / "directory" / Constants.workspaceDirName / "ide-options-v2.json").toString,
s"${(root / "directory").toString}${File.separator}"
(root / "directory" / "simple.sc").toString
)
expect(details.argv == expectedArgv)
}
Expand Down
50 changes: 41 additions & 9 deletions website/docs/guides/ide.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,49 @@ In an ideal world we would replace the rest of this guide with something along t
## Metals

Once Metals picks up the project structure that’s created by Scala CLI, basic features like navigation, diagnostics, and code completion should work.



However, picking up source files newly included in the project structure by Scala CLI may require restarting the build server manually. (Closing & reopening the project should also be sufficient)

## IntelliJ

Here are a few notes related to IntelliJ support:

- IntelliJ operates strictly on directories (and not just individual source files, as allowed by `scala-cli`).
- This means that even if you pass a single file to Scala CLI (for example by running `scala-cli setup-ide some-dir/A.scala`), all the other files within the same directory (`some-dir`) would be imported to IntelliJ.
This might change the behaviour of your builds in IntelliJ (or even break them), even though they run just fine in `scala-cli`.
- As a result, it is recommended to isolate Scala CLI builds' source files in separate directories before importing to IntelliJ.
- 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.
- We currently don’t advise using IntelliJ as a source of truth, and we recommend falling back to command line in such cases.
- Similarly to Metals, picking up source files newly included in the project structure by Scala CLI may require restarting the build server manually. (Closing & reopening the project should also be sufficient)

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

```shell
scala-cli setup-ide some-directory
```

Of course, nothing is stopping you from working with whatever you like as normal,
but please do keep in mind that the IDE will import the exact build that you have set up,
without second-guessing the user's intentions. In many IDEs, IDEA IntelliJ & Visual Studio Code included,
everything within a given project root directory is at least implicitly treated as
a part of the project (and probably shown as part of your project structure).

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

So if you want to include another file in your build, let's say `some-directory/B.scala`
alongside the previously configured `some-directory/A.scala`, it is probably not enough
to create the file within the same directory in your IDE.

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

Still, if you want to add/remove files like this a lot while working in an IDE,
it may be a lot simpler to work on the whole directory instead:
```shell
cd some-directory
scala-cli setup-ide .
```
That way all the contents of `some-directory` will be treated as a part of the project as you go,
without the need to jump into the command line whenever you create a new file.