scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

BSP sets the source folder wrong in the context of the sources' package in IntelliJ

Open Gedochao opened this issue 3 years ago • 0 comments

Version(s) 0.1.12

Describe the bug Scala CLI's BSP marks the sources directory in IDEA IntelliJ to the parent directory of the sources, regardless of the package structure. This messes up the IntelliJ project structure and makes navigating the sources less intuitive. Technically, everything will compile and run as normal, but it's not great UX when working in IntelliJ.

To Reproduce For a structure like this

▶ tree -A
.
└── src
    └── Main.scala

1 directory, 1 file

I setup BSP with scala-cli

scala-cli setup-ide .

then, I add a package declaration in Main.scala and decide to mirror the package structure in directories. image As a result, I have a structure like this:

▶ tree -A              
.
└── src
    └── com
        └── github
            └── gedochao
                └── Main.scala
image

Now, a workspace reload with Scala CLI's BSP messes up my project structure by changing the sources directory to the immediate parent directory of Main.scala

image image

Now, this is curious. If I add another source in the same package, one level higher, BSP will set the sources dir one level higher as well after a reload.

▶ tree -A
.
└── src
    └── com
        └── github
            ├── AnotherObject.scala
            └── gedochao
                └── Main.scala

4 directories, 2 files
image image

So I'm assuming it's setting the sources directory to the parent directory of the source closest to root.

Known workarounds I can theoretically reset the sources directory to the package root's parent directory, but I'd have to redo it after every single BSP reload, which is simply impractical. I can also add a mock source file outside of the package (in (default) package), so that the source root is picked where it should, but that's not ideal, either. So you basically end up ignoring it and accepting that the project structure identified by IntelliJ isn't correct.

Expected behaviour BSP should set the sources directory in IntelliJ to the parent of the package root.

image image

Gedochao avatar Sep 06 '22 07:09 Gedochao