scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.04k stars 318 forks source link

Unable to Goto definition for Sources classes which contains Scala 3 deprecated methods and when the Source Project's version contains number 3 in it #6533

Closed roshith-i closed 1 week ago

roshith-i commented 1 week ago

Bug Description:

I have a Scala Project A  which uses Java 8 and Scala version 2.12.18. I have compiled the project into an Uber jar using maven-shade-plugin and installed the dependency using mvn install along with the sources. There is one more Scala Project B which uses same Java and Scala versions as Project A. I have included the dependency from Project A in pom.xml. I'm able to go into the source definition of all the classes except the ones which contains methods that are deprecated in Scala 3 (Like, do-while loop etc). I have figured out an interesting thing here. When I tried to install an older version of Project A JAR and go-to source definitions, I was able to go into all of the classes even the ones with Scala 3 deprecated methods. Upon closer inspection, I have figured out that, the version of the Project A in the first attempt was 3.0. And in the second attempt, it was 2.0. I felt that there might be an issue with the version number. I tried changing the versions to something like 1.5, 2.5, 4.0 etc. All of these versions are just working as expected. And later, I have tried using 2.3, and it had stopped working. So, whenever the project's version number (in pom.xml) contains '3' in it, I am unable to go into the definitions of the methods which contains Scala 3 deprected methods. I found this really weird, and tried it out with a simple Scala project and it happened the same way.

Reproduction Steps

Create a new scala project. Create two files called class1.scala and class2.scala. Here, the class2.scala consists of a do-while loop (Scala 3 deprecated method). Here's the content of both the classes.

class1.scala >

  def method1(): Unit = {
    print("method1 in class1")
  }
}

class2.scala >

  def method2(): Unit = {
      print("method2 in class2")

      do{
        print("in do-while loop")
      }
      while(true)
    }
}

Make sure to use pom.xml instead of build.sbt (due to some CI/CD configuration, I had to stick with Maven build).

-First Test Case For the first test case, change the version to 1.0 (<version>1.0</version>). Under tag, specify Scala version as 2.12.18 (<scala.version>2.12.18</scala.version>). There is no need of any other dependency. Under plugins, include maven-shade-plugin to create an uber JAR. Use mvn clean compile package and install the JAR using mvn install:install-file and also attach sources using -Dclassifer=sources. Now, open another scala project and make sure to use same Java, Scala versions. Here, in the pom.xml include the dependency. Try to import both the methods class1.scala and class2.scala from the First Project. 'Go to definition' should work fine for both. And in the 'Libraries' section of metals, you should be able to see all the classes listed under the sources jar.

image

-Second Test Case Now change the version of the project from 1.0 to 3.0. And compile into Uber JAR and install the same. Include the dependency with version as 3.0. Upon importing build, try to import the methods from class1.scala and class2.scala. It wouldn't be possible to go to the definition of the method2() in class2.scala because it contains a Scala 3 deprecated method (do-while loop). It would be possible to go to the definition for method1() in class1.scala.

image

Expected behaviour:

The issues will arise not just with 3.0, it happens with any version number combination that contains 3 in it. Just like how it works for all the other cases, irrespective of the version number of the project, we should be able to navigate to the source definitions of the classes that contains Scala 3 deprecated methods.

Operating system: Mac OS X

Java version: 8

Editor/extension: Visual Studio Code v1.90.0

Metals version: 1.3.2

Workspace information:

tgodzik commented 1 week ago

The fix was actually pretty small, thanks for getting to the bottom of it!

roshith-i commented 6 days ago

Thanks for the fix. 😄