Skip to content

Commit

Permalink
Presentation Compiler is now loaded with correct Classloader
Browse files Browse the repository at this point in the history
  • Loading branch information
rochala committed Dec 3, 2024
1 parent 1e0d88e commit 0f19bcb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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") ||
Expand Down
56 changes: 56 additions & 0 deletions tests/unit/src/test/scala/tests/ClassloaderModulesSupport.scala
Original file line number Diff line number Diff line change
@@ -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 ()
}
}

0 comments on commit 0f19bcb

Please sign in to comment.