Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imports-for-non-compiling outline test not working for Scala 3's best effort #6593

Closed
jchyb opened this issue Jul 15, 2024 · 0 comments · Fixed by #6677
Closed

imports-for-non-compiling outline test not working for Scala 3's best effort #6593

jchyb opened this issue Jul 15, 2024 · 0 comments · Fixed by #6677
Assignees
Labels
bug Something that is making a piece of functionality unusable fixed-upstream Tag a ticket with this when a fix upstream has been completed and we can now address the ticket presentation-compiler Something relating to the presentation compiler Scala 3 Generic ticket relating to Scala 3
Milestone

Comments

@jchyb
Copy link
Contributor

jchyb commented Jul 15, 2024

Describe the bug

Running imports-for-non-compiling metals test from CompilersLspSuite.scala (before merging #5219) / OutlineLspSuite (after merging):

  test("imports-for-non-compiling") {
    cleanWorkspace()
    for {
      _ <- initialize(
        s"""/metals.json
           |{
           |  "a": { $scalaVersionConfig }
           |}
           |/a/src/main/scala/a/A.scala
           |package a
           |
           |/a/src/main/scala/b/B.scala
           |package b
           |
           |object O {
           |  class UniqueObject {
           |  }
           |}
           |""".stripMargin
      )
      _ <- server.didOpen("a/src/main/scala/b/B.scala")
      _ <- server.didChange("a/src/main/scala/b/B.scala") { _ =>
        """|package b
           |object W {
           |  class UniqueObject {
           |    val i: Int = "aaa"
           |  }
           |}
           |""".stripMargin
      }
      _ <- server.didSave("a/src/main/scala/b/B.scala")(identity)
      // check if the change name is picked up despite the file not compiling
      newText = """|package a
                   |
                   |object A {
                   |  // @@
                   |  val k: <<UniqueObject>> = ???
                   |}
                   |""".stripMargin
      input = newText.replace("<<", "").replace(">>", "")
      _ <- server.didChange("a/src/main/scala/a/A.scala")(_ => input)
      _ <- server.didSave("a/src/main/scala/a/A.scala")(identity)
      codeActions <-
        server
          .assertCodeAction(
            "a/src/main/scala/a/A.scala",
            newText,
            s"""|${ImportMissingSymbol.title("UniqueObject", "b.W")}
                |${CreateNewSymbol.title("UniqueObject")}
                |""".stripMargin,
            kind = Nil,
          )
      _ <- assertCompletionEdit(
        "UniqueObject@@",
        """|package a
           |
           |import b.W.UniqueObject
           |
           |object A {
           |  UniqueObject
           |  val k: UniqueObject = ???
           |}
           |""".stripMargin,
      )
    } yield ()

fails with an error:

java.util.NoSuchElementException: head of empty ArrayBuffer
    at scala.collection.IndexedSeqOps.head(IndexedSeq.scala:99)
    at scala.collection.IndexedSeqOps.head$(IndexedSeq.scala:94)
    at scala.collection.mutable.ArrayBuffer.head(ArrayBuffer.scala:42)
    at tests.BaseCompletionLspSuite.$anonfun$withCompletionEdit$3(BaseCompletionLspSuite.scala:67)
    at tests.BaseCompletionLspSuite.$anonfun$withCompletionEdit$3$adapted(BaseCompletionLspSuite.scala:63)
    at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:467)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.lang.Thread.run(Thread.java:829)

empty ArrayBuffer in assertCodeAction

Expected behavior

Should pass

Operating system

None

Editor/Extension

None

Version of Metals

c4c1d29

Extra context or search terms

Was asked to submit this here. Importing missing symbols like this works for me on a locally released metals, so not sure what is going wrong here.

@tgodzik tgodzik added bug Something that is making a piece of functionality unusable Scala 3 Generic ticket relating to Scala 3 presentation-compiler Something relating to the presentation compiler labels Jul 15, 2024
@kasiaMarek kasiaMarek self-assigned this Jul 24, 2024
@kasiaMarek kasiaMarek moved this from Triage to In progress in Metals Issue Board Jul 24, 2024
tgodzik added a commit to scala/scala3 that referenced this issue Aug 2, 2024
@tgodzik tgodzik added the fixed-upstream Tag a ticket with this when a fix upstream has been completed and we can now address the ticket label Aug 7, 2024
@github-project-automation github-project-automation bot moved this from In progress to Done in Metals Issue Board Aug 14, 2024
@tgodzik tgodzik added this to the Metals v1.4.0 milestone Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is making a piece of functionality unusable fixed-upstream Tag a ticket with this when a fix upstream has been completed and we can now address the ticket presentation-compiler Something relating to the presentation compiler Scala 3 Generic ticket relating to Scala 3
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants