From 82b7e0fd0bb929d82e612327f58215313dc29897 Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Fri, 18 Mar 2022 14:46:25 +0100 Subject: [PATCH 1/3] Make BSP build configurations for IDEs be consistent with command line scala-cli builds --- .../scala/scala/cli/commands/SetupIde.scala | 8 +--- website/docs/guides/ide.md | 47 +++++++++++++++---- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/modules/cli/src/main/scala/scala/cli/commands/SetupIde.scala b/modules/cli/src/main/scala/scala/cli/commands/SetupIde.scala index 32c7b7750d..0a0a7ed19e 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/SetupIde.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/SetupIde.scala @@ -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" diff --git a/website/docs/guides/ide.md b/website/docs/guides/ide.md index b191ee31f1..9bc0aa39f6 100644 --- a/website/docs/guides/ide.md +++ b/website/docs/guides/ide.md @@ -46,16 +46,47 @@ In an ideal world we would replace the rest of this guide with something along t Once Metals picks up the project structure that’s created by Scala CLI, basic features like navigation, diagnostics, and code completion should work. - - - ## 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. + +## 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. From 0aacc80cac7e8527a2272a3595266f412f4baec1 Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Fri, 18 Mar 2022 14:56:22 +0100 Subject: [PATCH 2/3] Adjust the docs regarding Metals & IntelliJ --- website/docs/guides/ide.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/website/docs/guides/ide.md b/website/docs/guides/ide.md index 9bc0aa39f6..f45f2a6dfb 100644 --- a/website/docs/guides/ide.md +++ b/website/docs/guides/ide.md @@ -45,12 +45,13 @@ 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 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. From 6cca8eef118828424e6b4c37d16970fad8898a64 Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Mon, 21 Mar 2022 10:04:46 +0100 Subject: [PATCH 3/3] Fix relevant BspTest --- .../test/scala/scala/cli/integration/BspTestDefinitions.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala index 011a75d691..69377a627a 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala @@ -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 @@ -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) }