Exclude compilation artifacts from searchable filesSee original GitHub issue
IDEs usually provide a fast search feature, which allows you to search for some text in all the source files of your project. In the case of sbt projects, sbt generates a lot of small files in the
target/ directory. When we import a project via BSP in an IDE, these compilation artifacts (the content of
target/) are included in the scope of a search, making it slow, and showing irrelevant results.
I think the developer experience would be improved if we introduced a concept of paths excluded from the actual sources of the project, that IDEs could leverage.
Currently, importing a project in IntelliJ via the sbt import feature does exclude the
target/ directories, but this is not the case when we import the same project via the BSP import feature (so, the sbt import does not suffer from this issue).
Here is a concrete example. I did
sbt new scala/scala3.g8, and then imported the project (which uses sbt 1.5.5) in IntelliJ.
By default, IntelliJ imports the project via sbt, and the
target/ directory is excluded from the indexed files, as you can see here:
Then, if I re-import the project via BSP, the
target/ directory is not anymore excluded (it’s interesting to see that
project/target/ is excluded, though…):
As a consequence, when I search something, IntelliJ also searches in the
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
This PR will fix this issue for the protocol itself: https://github.com/build-server-protocol/build-server-protocol/pull/269. Then, this sbt PR https://github.com/sbt/sbt/pull/6985 and intellij-scala PR https://github.com/JetBrains/intellij-scala/pull/627 will fix the problem for IntelliJ IDEA users.
I think it would be nice if BSP had a notion of declaring what directories should be excluded from the IDE. I recall that the Pants IntelliJ plugin works around this limitation by manually excluding Bloop directories when using Pants via BSP. It would be more natural if the protocol had a notion of “exclude directories”, which can cover more broad directories like
target/ instead of only excluding the classes directories.