From 08867f9c33273ec505395764f82f288abb807e35 Mon Sep 17 00:00:00 2001 From: Jakub Ciesluk <323892@uwr.edu.pl> Date: Fri, 3 Nov 2023 13:47:10 +0100 Subject: [PATCH] bugfix: Add output classes directory to classpath for PC It was there already for bloop and sbt, but not for mill. Because of this, presentation compiler didn't see symbols from workspace. --- .../internal/metals/MetalsEnrichments.scala | 8 ++- .../scala/tests/mill/MillServerSuite.scala | 54 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala index 9260bec34eb..36c9f258afc 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsEnrichments.scala @@ -1015,8 +1015,12 @@ object MetalsEnrichments .map(_.stripPrefix(flag)) } - def classpath: List[String] = - item.getClasspath.asScala.toList + def classpath: List[String] = { + val outputClasses = item.getClassDirectory + val classes = item.getClasspath.asScala.toList + if (classes.contains(outputClasses)) classes + else outputClasses :: classes + } def jarClasspath: List[AbsolutePath] = classpath diff --git a/tests/slow/src/test/scala/tests/mill/MillServerSuite.scala b/tests/slow/src/test/scala/tests/mill/MillServerSuite.scala index aa37ce29641..71d18cad900 100644 --- a/tests/slow/src/test/scala/tests/mill/MillServerSuite.scala +++ b/tests/slow/src/test/scala/tests/mill/MillServerSuite.scala @@ -118,4 +118,58 @@ class MillServerSuite } } } + + test(s"presentation-compiler") { + def millBspConfig = workspace.resolve(".bsp/mill-bsp.json") + writeLayout( + s""" + |/.mill-version + |$supportedBspVersion + |/build.sc + |import mill._, scalalib._ + |object foo extends ScalaModule { + | def scalaVersion = "${V.scala213}" + |} + |/foo/src/Main.scala + |package foo + | + |import foo.A + |object Main extends App { + | println(A.msg) + |} + | + |/foo/src/A.scala + |package foo + | + |object A { + | def msg = "Hello" + |} + |""".stripMargin + ) + for { + _ <- server.initialize() + _ <- server.initialized() + _ = assertNoDiff( + client.workspaceMessageRequests, + importBuildMessage, + ) + _ = client.messageRequests.clear() // restart + _ = assert(!millBspConfig.exists) + _ = server.server.buildServerPromise = Promise() + _ <- server.executeCommand(ServerCommands.GenerateBspConfig) + _ <- server.server.buildServerPromise.future + _ = assert(millBspConfig.exists) + _ = server.assertBuildServerConnection() + _ <- server.didOpen("foo/src/Main.scala") + _ <- server.assertHoverAtLine( + "foo/src/Main.scala", + "println(A.m@@sg)", + """|```scala + |def msg: String + |``` + |""".stripMargin, + ) + + } yield {} + } }