Skip to content

Commit 86c19cd

Browse files
committed
Use correct parent classloader for worksheets.
Instead of passing in `null` when we extend ClassLoader in our MdocClassLoader this passes in the actual parent since on Java +9 when using `null` that's the bootstrap classloader which doesn't contain modules like java.sql. Bit thanks to @smarter pointing this out in scala/scala3#11658. Fixes scalameta#2187
1 parent f0ccc00 commit 86c19cd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

metals/src/main/scala/scala/meta/internal/worksheets/WorksheetClassLoader.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package scala.meta.internal.worksheets
88
* allowing the Metals server to call mdoc instances from different Scala
99
* versions.
1010
*/
11-
class MdocClassLoader(parent: ClassLoader) extends ClassLoader(null) {
11+
class MdocClassLoader(parent: ClassLoader) extends ClassLoader(parent) {
1212
override def findClass(name: String): Class[_] = {
1313
val isShared =
1414
name.startsWith("mdoc.interfaces") || name.startsWith("coursierapi")

tests/unit/src/test/scala/tests/worksheets/WorksheetLspSuite.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,25 @@ class WorksheetLspSuite extends tests.BaseWorksheetLspSuite(V.scala212) {
9191
)
9292
} yield ()
9393
}
94+
95+
test("classloader") {
96+
val path = "hi.worksheet.sc"
97+
for {
98+
_ <- server.initialize(
99+
s"""
100+
|/metals.json
101+
|{
102+
| "a": {}
103+
|}
104+
|/${path}
105+
|new java.sql.Date(100L)
106+
|""".stripMargin
107+
)
108+
_ <- server.didOpen(path)
109+
_ = assertNoDiff(
110+
client.workspaceDecorations,
111+
"new java.sql.Date(100L) // : java.sql.Date = 1970-01-01"
112+
)
113+
} yield ()
114+
}
94115
}

0 commit comments

Comments
 (0)