Open ncreep opened 5 months ago
Thanks for the report. It seems that loading java.sql.Driver
causes an error in the interactive driver, when inside of a macro.
java.lang.ClassNotFoundException: java.sql.Driver
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:421)
at java.base/java.lang.Class.forName(Class.java:412)
at a.LoadStuff$.makeImpl(LoadStuff.scala:13)
at a.LoadStuff$.inline$makeImpl(LoadStuff.scala:10)
Thanks for the quick response.
How did you get that stack trace? I didn't see it in the logs that I referenced.
Is the classpath for the interactive driver configurable?
How did you get that stack trace?
I got it from diagnostics inside of presentation compiler. It isn't surfaced anywhere.
Is the classpath for the interactive driver configurable?
In Metals we take the classpath for the specific build target according to what the build server (so the build tool really) says. But this error only occurs if Class.forName("org.h2.Driver")
(or Class.forName("java.sql.Driverr")
) in done inside of a macro.
Thanks for the info. If it's the same classpath, I wonder how it diverges from the build tool. Additionally, I can say that this also works correctly when building from sbt (but still broken in Metals).
Actually, thinking about it, this has nothing to do with Selectable
. Apparently just being a transparent
inline with class loading is enough to trigger this behavior:
object LoadStuff:
transparent inline def make: Unit = ${ makeImpl }
private def makeImpl(using Quotes): Expr[Unit] =
Class.forName("org.h2.Driver")
'{()}
This too triggers a loss of type-information at the call-site of make
.
Removing transparent
brings back type information.
Describe the bug
Hello,
I'm trying to connect to a database via JDBC in a macro, for, um, educational purposes. I then want to use
Selectable
to reflect the data from the database in a structural type (in the style of type providers).Despite everything compiling fine, it seems that Metals is having issues when I actually try to touch the database.
Here's a minimized reproduction.
Notice that I'm accessing a class from the H2 driver while running the macro. The result of the macro is a refined type. I can then use it in a separate file as follows:
This compiles and runs correctly. But Metals loses all type information. I can't get member completions on the
load
value. And I cannot automatically insert a type annotations, it fails with an error.Following the logs, I see that I get the following error when trying to insert a type annotation:
And opening one of the error files, I see this:
If I remove the
Class.forName
call everything works as expected, with member completion and generated type annotations.Please let me know if I can provide any further info.
Thanks
Expected behavior
Selectable
types should work correctly, with type member selection hints regardless of the access to library classes.Operating system
None
Editor/Extension
VS Code
Version of Metals
v1.35.5
Extra context or search terms
No response