cashapp / sqldelight

SQLDelight - Generates typesafe Kotlin APIs from SQL
https://cashapp.github.io/sqldelight/
Apache License 2.0
6.01k stars 502 forks source link

Endless loop when loading SQLDelight plugin in Android Studio #4179

Open mipastgt opened 1 year ago

mipastgt commented 1 year ago

For quite some time now AndroidStudio seems to go into an endless loop when trying to load the SQLDelight plugin. See attached screen recording. Although there seems to be a problem the plugin works as expected but this constant blinking is very annoying and a waste of precious CPU time. The blinking stops as soon as I disable the plugin and starts again when I enable it again.

My project is a Kotlin multiplatform project in case this should matter. Other plugins don't show this behaviour. I am using version 2.0.0-alpha05 of SQLDelight.

https://github.com/cashapp/sqldelight/assets/16735714/3209b044-c722-4de7-b5dd-f4ed9534a2b9

hfhbd commented 1 year ago

What's your version of IDE/AS?

mipastgt commented 1 year ago

Android Studio Giraffe | 2022.3.1 Beta 3 Build #AI-223.8836.35.2231.10075884, built on May 5, 2023 Runtime version: 17.0.6+0-17.0.6b829.9-10027231 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 12.6.6 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 12 Metal Rendering is ON Registry: external.system.auto.import.disabled=true debugger.new.tool.window.layout=true ide.text.editor.with.preview.show.floating.toolbar=false ide.experimental.ui=true

Non-Bundled Plugins: org.asciidoctor.intellij.asciidoc (0.38.13) com.squareup.sqldelight (1.5.5) com.jetbrains.kmm (0.5.3(223)-16)

hfhbd commented 1 year ago

Could you please use a 2.0.0-alpha version of the idea plugin too? Using different Gradle plugin versions and ide plugins isn't supported. https://plugins.jetbrains.com/plugin/8191-sqldelight/versions/alpha

mipastgt commented 1 year ago

Many thanks. It seems to work now. But shouldn't it be mentioned on the website that the currently promoted latest version of SQLDelight is not compatible with the latest plugin version that you can install normally?

mipastgt commented 1 year ago

I probably was a little bit too quick to say that everything is OK now. Although it is true that the plugin now does not seem to enter an endless loop anymore another problem is showing up. If I now open an .sq file it shows, also after some blinking, this:

error_message_on_top_of_editor

So, the alpha05 build of the plugin also seems to have a few bugs.

AlecKazakova commented 11 months ago

If things are still problematic can you try this version of the IDE plugin? It allows you to show the exception that caused the error message to appear so we can debug further from there. SQLDelight-2.0.0-SNAPSHOT.zip

mipastgt commented 11 months ago

They are! Is that the output you are looking for?

  In file: file:///Users/mpaus/Projects/mpMediaSoft/apps/AIPBrowserDE/shared/src/commonMain/sqldelight/aipde/de/mpmediasoft/aipbrowserde/aipde.sq

  java.lang.NoSuchMethodException: org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelTypeAliasFqNameIndex$Helper.getInstance()
at java.base/java.lang.Class.getMethod(Class.java:2227)
at app.cash.sqldelight.intellij.SqlDelightReferenceContributorKt.getKotlinTopLevelTypeAliasFqNameIndex(SqlDelightReferenceContributor.kt:89)
at app.cash.sqldelight.intellij.SqlDelightReferenceContributorKt.access$getKotlinTopLevelTypeAliasFqNameIndex(SqlDelightReferenceContributor.kt:1)
at app.cash.sqldelight.intellij.SqlDelightReferenceContributor$JavaTypeReference.resolve(SqlDelightReferenceContributor.kt:65)
at com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference.resolve(PsiMultiReference.java:121)
at app.cash.sqldelight.intellij.SqlDelightClassNameElementAnnotator.annotate(SqlDelightClassNameElementAnnotator.kt:41)
at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.runAnnotators(DefaultHighlightVisitor.java:130)
at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.visit(DefaultHighlightVisitor.java:107)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.runVisitors(GeneralHighlightingPass.java:360)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.lambda$collectHighlights$7(GeneralHighlightingPass.java:299)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.analyzeByVisitors(GeneralHighlightingPass.java:320)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.lambda$analyzeByVisitors$8(GeneralHighlightingPass.java:323)
at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.analyze(DefaultHighlightVisitor.java:92)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.analyzeByVisitors(GeneralHighlightingPass.java:323)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.collectHighlights(GeneralHighlightingPass.java:286)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.collectInformationWithProgress(GeneralHighlightingPass.java:234)
at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:95)
at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:57)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$1(PassExecutorService.java:390)
at com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.runWithSpanIgnoreThrows(trace.kt:77)
at com.intellij.platform.diagnostic.telemetry.helpers.TraceUtil.runWithSpanThrows(TraceUtil.java:24)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:386)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1133)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$3(PassExecutorService.java:377)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:604)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:679)
at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:635)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:603)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:61)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:376)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:352)
at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:201)
at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:207)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:350)
at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:185)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
mipastgt commented 11 months ago

And here the corresponding info on my IntelliJ version:

IntelliJ IDEA 2023.2 Beta (Community Edition) Build #IC-232.8660.48, built on July 12, 2023 Runtime version: 17.0.7+7-b1000.6 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 13.4.1 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 12 Metal Rendering is ON Registry: debugger.new.tool.window.layout=true ide.experimental.ui=true

Non-Bundled Plugins: com.intellij.javafx (1.0.4) com.gluonhq.plugin.intellij (2.8.6) org.asciidoctor.intellij.asciidoc (0.38.20) com.squareup.sqldelight (2.0.0-SNAPSHOT-1689605958532) androidx.compose.plugins.idea (232.8660.48) org.jetbrains.compose.desktop.ide (1.4.1)

Kotlin: 232-1.8.21-release-380-IJ8660.48

morki commented 11 months ago

The same exception for me, repeatadly, also on IDEA 2023.2 Beta:

java.lang.NoSuchMethodException: org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelTypeAliasFqNameIndex$Helper.getInstance()
mipastgt commented 11 months ago

I now found what triggers this error although I have no idea how these things are related to each other.

I have a compose multiplatform project. In the desktop build.gradle.kts file there is a section like this

compose.desktop {
    application {
        mainClass = "MainKt"
        javaHome = System.getenv("JAVA_HOME")
//        javaHome = "/Library/Java/JavaVirtualMachines/jdk-17/Contents/Home"

When I try to open a .sq file in the IDE the plugin seems to stumble over getenv("JAVA_HOME") must not be nullThe supplied build action failed with an exception. See attached error log from the plugin for details.

This does not make any sense to me because I don't know why the plugin cares for this gradle script and, even more confusing, why it thinks that JAVA_HOME is null. That's nonsense. It definitely is not null and set correctly because otherwise the later project build would not work but it does. As soon as I replace that line with the corresponding string value the plugin works.

plugin_error_message.txt config.txt

AlecKazakova commented 11 months ago

I see! Thanks for the investigation. I fixed the KotlinTopLevelTypeAliasFqNameIndex exception that was showing up, so this may be different

kratho commented 3 weeks ago

Like @mipastgt, I am also facing the problem where the IDE plugin states an environment variable accessed from build.gradle is null. However, the variable is definitely set. Are there any updates on this?

IDE Plugin Version: 2.1.0-SNAPSHOT-1717252877172