sbt-projectmatrix icon indicating copy to clipboard operation
sbt-projectmatrix copied to clipboard

Within test source, IntelliJ IDEA "Cannot find declaration to go to" for type defined in sources

Open andrew-selvia opened this issue 1 year ago • 2 comments

For an sbt project matrix spanning JS, JVM, and Native, IntelliJ IDEA is capable of fully indexing sources within src/main. Any types defined within the sources can be used by tests within src/test. In other words, sbt test works just fine.

However, the types defined within src/main are seemingly unnavigable from src/test. If you select Navigate > GoTo (i.e., ⌘-click) on a type defined in the sources, an alert says "Cannot find declaration to go to".

Workaround: If the JS & Native axes are removed from the project matrix, navigation to source files works.

It's unclear whether this is an issue with sbt-projectmatrix or the IntelliJ IDEA Scala plugin. It could also easily be user error (apologies, if so). Please let me know if this is a known issue or there is a more appropriate workaround.

Versions:

  • Scala: 3
  • sbt: 1.10.1
  • sbt-projectmatrix: 0.10.0
  • IntelliJ IDEA: 2024.2 Beta

andrew-selvia avatar Jul 26 '24 23:07 andrew-selvia

Same issue here. It seems compiled classes goes under jvm-2.12, jvm-2-13, and jvm-3` and hence it fails recognize classes.

sfali avatar Nov 10 '24 16:11 sfali

I'm inclined to think it's an IntelliJ bug - I was able to reproduce by trying to go to definition of "TypeClass" here: https://github.com/indoorvivants/scala3-library-template/blob/main/modules/core/src/test/scala/ExampleTests.scala#L5, with project imported using SBT BSP.

Metals (using SBT BSP) imported project fine and go to definition works, so sbt-projectmatrix doesn't screw with BSP configuration it seems.

Perhaps IntelliJ is making incorrect assumptions on the position of the target folder – not taking that information from the buildtool, but instead using some pre-defined location.

A bit of spelunking in the intellij-scala repo unearthed this: https://github.com/JetBrains/intellij-scala/blob/8f9bcf8f8239f464af726a85dfea278ecb63209c/sbt/sbt-impl/src/org/jetbrains/sbt/project/ExternalSourceRootResolution.scala#L533-L561 which makes me suspect that this custom configuration is broken somehow.

keynmol avatar Nov 12 '24 15:11 keynmol