From c291bd282ca1c37b803d638ad394a90285b05e5f Mon Sep 17 00:00:00 2001 From: rochala Date: Tue, 3 Dec 2024 19:20:45 +0100 Subject: [PATCH] Presentation Compiler is now loaded with correct Classloader --- .../PresentationCompilerClassLoader.scala | 2 +- .../tests/ClassloaderModulesSupport.scala | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/unit/src/test/scala/tests/ClassloaderModulesSupport.scala diff --git a/metals/src/main/scala/scala/meta/internal/metals/PresentationCompilerClassLoader.scala b/metals/src/main/scala/scala/meta/internal/metals/PresentationCompilerClassLoader.scala index b6ae4bfc532..4557f33842b 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/PresentationCompilerClassLoader.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/PresentationCompilerClassLoader.scala @@ -9,7 +9,7 @@ package scala.meta.internal.metals * method signatures of the `PresentationCompiler` class. */ class PresentationCompilerClassLoader(parent: ClassLoader) - extends ClassLoader(null) { + extends ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { override def findClass(name: String): Class[_] = { val isShared = name.startsWith("org.eclipse.lsp4j") || diff --git a/tests/unit/src/test/scala/tests/ClassloaderModulesSupport.scala b/tests/unit/src/test/scala/tests/ClassloaderModulesSupport.scala new file mode 100644 index 00000000000..65895cfa206 --- /dev/null +++ b/tests/unit/src/test/scala/tests/ClassloaderModulesSupport.scala @@ -0,0 +1,56 @@ +package tests + +import scala.meta.internal.metals.BuildInfo + +class ClassloaderModulesSupport + extends BaseLspSuite("classloader-modules-") + with TestHovers { + + test("basic") { + cleanWorkspace() + for { + _ <- initialize( + s"""/metals.json + |{ + | "a": { "scalaVersion": "${BuildInfo.scala3}" }, + | "b": { "dependsOn": ["a"], "scalaVersion": "${BuildInfo.scala3}" } + |} + | + |/a/src/main/scala/a/A.scala + |package a + | + |import scala.quoted._ + | + |object MacroImpl: + | transparent inline def make = $${ makeImpl } + | + | private def makeImpl(using Quotes): Expr[Unit] = + | Class.forName("java.sql.Driver") + | '{()} + | + |/b/src/main/scala/b/B.scala + |package b + | + |object B: + | a.MacroImpl.make + |""".stripMargin + ) + _ <- server.didOpen("a/src/main/scala/a/A.scala") + _ <- server.didOpen("b/src/main/scala/b/B.scala") + _ = assertNoDiagnostics() + _ <- server.assertHover( + "b/src/main/scala/b/B.scala", + """ + |/b/src/main/scala/b/B.scala + |package b + | + |object B: + | a.MacroImpl.ma@@ke + |""".stripMargin, + """| + |inline transparent def make: Unit + |""".stripMargin.hover, + ) + } yield () + } +}