varabyte / kobweb-intellij-plugin

An official IntelliJ IDE plugin to include Kobweb-specific enhancements and understanding to your project
Apache License 2.0
10 stars 2 forks source link

"Outdated stub in index" and "PSI and index do not match." #43

Open bitspittle opened 3 months ago

bitspittle commented 3 months ago

Outdated stub in index

Outdated stub in index: file://C:/Users/IdeaProjects/kobweb/tools/gradle-plugins/extensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/KotlinRenderer.kt, vFileId=766123, indexing timestamp = 1711577686385, binary = false, byte size = 19029, char size = 19029, doc=DocumentImpl[file://C:/Users/IdeaProjects/kobweb/tools/gradle-plugins/extensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/KotlinRenderer.kt], docSaved=true, wasIndexedAlready=true, queried at 1711577686385
doc length=19427
file length=19427
cached PSI class org.jetbrains.kotlin.psi.KtFile
PSI length=19427
projects with file: 1
physical file exists; length = 19427

java.lang.Exception
    at com.intellij.psi.stubs.StubTreeLoaderImpl.diagnoseLengthMismatch(StubTreeLoaderImpl.java:188)
    at com.intellij.psi.stubs.StubTreeLoaderImpl.checkLengthMatch(StubTreeLoaderImpl.java:152)
    at com.intellij.psi.stubs.StubTreeLoaderImpl.readFromVFile(StubTreeLoaderImpl.java:119)
    at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.doCreateCompleteException(StubTreeLoader.java:184)
    at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.lambda$createCompleteException$0(StubTreeLoader.java:178)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$computeInNonCancelableSection$4(CoreProgressManager.java:277)
    at com.intellij.openapi.progress.Cancellation.computeInNonCancelableSection(Cancellation.java:57)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeInNonCancelableSection(CoreProgressManager.java:277)
    at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.createCompleteException(StubTreeLoader.java:177)
    at com.intellij.psi.impl.source.PsiFileImpl.loadTreeElement(PsiFileImpl.java:227)
    at com.intellij.psi.impl.source.PsiFileImpl.calcTreeElement(PsiFileImpl.java:733)
    at com.intellij.extapi.psi.StubBasedPsiElementBase.getNode(StubBasedPsiElementBase.java:126)
    at com.intellij.extapi.psi.ASTDelegatePsiElement.getText(ASTDelegatePsiElement.java:133)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.isKobwebColorFunction(KobwebColorProvider.kt:188)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.tryParseKobwebColorFunctionCall(KobwebColorProvider.kt:110)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor(KobwebColorProvider.kt:84)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor(KobwebColorProvider.kt:93)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor$default(KobwebColorProvider.kt:63)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProvider.getColorFrom(KobwebColorProvider.kt:48)
    at com.intellij.ui.ColorLineMarkerProvider.lambda$collectSlowLineMarkers$0(ColorLineMarkerProvider.java:47)
    at com.intellij.openapi.extensions.ExtensionPointName.computeSafeIfAny(ExtensionPointName.kt:70)
    at com.intellij.ui.ColorLineMarkerProvider.collectSlowLineMarkers(ColorLineMarkerProvider.java:46)
    at com.intellij.codeInsight.daemon.impl.LineMarkersPass.queryProviders(LineMarkersPass.java:226)
    at com.intellij.codeInsight.daemon.impl.LineMarkersPass.lambda$doCollectMarkers$2(LineMarkersPass.java:108)
    at com.intellij.codeInsight.daemon.impl.Divider.divideInsideAndOutsideInOneRoot(Divider.java:98)
    at com.intellij.codeInsight.daemon.impl.LineMarkersPass.doCollectMarkers(LineMarkersPass.java:104)
    at com.intellij.codeInsight.daemon.impl.LineMarkersPass.doCollectInformation(LineMarkersPass.java:77)
    at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:55)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:418)
    at com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.runWithSpanIgnoreThrows(trace.kt:109)
    at com.intellij.platform.diagnostic.telemetry.helpers.TraceUtil.runWithSpanThrows(TraceUtil.java:34)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$3(PassExecutorService.java:413)
    at com.intellij.openapi.application.impl.RwLockHolder.tryRunReadAction(RwLockHolder.kt:310)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:958)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$4(PassExecutorService.java:404)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:403)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:379)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.cacheFileTypesInside(FileTypeManagerImpl.java:795)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$1(PassExecutorService.java:379)
    at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:199)
    at com.intellij.openapi.application.impl.RwLockHolder.executeByImpatientReader(RwLockHolder.kt:491)
    at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:182)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:377)
    at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:190)
    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)```

PSI and index do not match

com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: PSI and index do not match.
Please report the problem to JetBrains with the files attached
 file=KtFile: MarkdownBlock.kt, file.class=class org.jetbrains.kotlin.psi.KtFile, file.lang=Language: kotlin, modStamp=1
 tree consistent
 stub debugInfo=created in getStubTree(), with AST = false; with backReference
 viewProvider=com.intellij.psi.SingleRootFileViewProvider{vFile=file://C:/Users/IdeaProjects/kobweb/tools/gradle-plugins/extensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/MarkdownBlock.kt, vFileId=763947, content=VirtualFileContent{size=6019}, eventSystemEnabled=true}
 viewProvider stamp: 1179455; file stamp: 1179455; file modCount: 1711578271400; file length: 6019
 doc saved: true; doc stamp: 1179455; doc size: 6019; committed: true
indexing info: indexing timestamp = 1711578271400, binary = false, byte size = 6671, char size = 6671
ref: 50cf572587cf
latestIndexedStub=null
    at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.doCreateCompleteException(StubTreeLoader.java:203)
    at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.lambda$createCompleteException$0(StubTreeLoader.java:178)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$computeInNonCancelableSection$4(CoreProgressManager.java:277)
    at com.intellij.openapi.progress.Cancellation.computeInNonCancelableSection(Cancellation.java:57)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeInNonCancelableSection(CoreProgressManager.java:277)
    at com.intellij.psi.stubs.StubTreeLoader$StubTreeAndIndexUnmatchCoarseException.createCompleteException(StubTreeLoader.java:177)
    at com.intellij.psi.impl.source.PsiFileImpl.loadTreeElement(PsiFileImpl.java:227)
    at com.intellij.psi.impl.source.PsiFileImpl.calcTreeElement(PsiFileImpl.java:733)
    at com.intellij.extapi.psi.StubBasedPsiElementBase.getNode(StubBasedPsiElementBase.java:126)
    at com.intellij.extapi.psi.ASTDelegatePsiElement.getText(ASTDelegatePsiElement.java:133)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.isKobwebColorFunction(KobwebColorProvider.kt:188)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.tryParseKobwebColorFunctionCall(KobwebColorProvider.kt:110)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor(KobwebColorProvider.kt:84)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor(KobwebColorProvider.kt:93)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProviderKt.traceColor$default(KobwebColorProvider.kt:63)
    at com.varabyte.kobweb.intellij.colors.KobwebColorProvider.getColorFrom(KobwebColorProvider.kt:48)
    at com.intellij.ui.ColorLineMarkerProvider.lambda$collectSlowLineMarkers$0(ColorLineMarkerProvider.java:47)
    at com.intellij.openapi.extensions.ExtensionPointName.computeSafeIfAny(ExtensionPointName.kt:70)
    at com.intellij.ui.ColorLineMarkerProvider.collectSlowLineMarkers(ColorLineMarkerProvider.java:46)
    at com.intellij.codeInsight.daemon.impl.LineMarkersPass.queryProviders(LineMarkersPass.java:226)
    at com.intellij.codeInsight.daemon.impl.LineMarkersPass.lambda$doCollectMarkers$2(LineMarkersPass.java:108)
    at com.intellij.codeInsight.daemon.impl.Divider.divideInsideAndOutsideInOneRoot(Divider.java:98)
    at com.intellij.codeInsight.daemon.impl.LineMarkersPass.doCollectMarkers(LineMarkersPass.java:104)
    at com.intellij.codeInsight.daemon.impl.LineMarkersPass.doCollectInformation(LineMarkersPass.java:77)
    at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:55)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:418)
    at com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.runWithSpanIgnoreThrows(trace.kt:109)
    at com.intellij.platform.diagnostic.telemetry.helpers.TraceUtil.runWithSpanThrows(TraceUtil.java:34)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$3(PassExecutorService.java:413)
    at com.intellij.openapi.application.impl.RwLockHolder.tryRunReadAction(RwLockHolder.kt:310)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:958)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$4(PassExecutorService.java:404)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:403)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:379)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.cacheFileTypesInside(FileTypeManagerImpl.java:795)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$1(PassExecutorService.java:379)
    at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:199)
    at com.intellij.openapi.application.impl.RwLockHolder.executeByImpatientReader(RwLockHolder.kt:491)
    at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:182)
    at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:377)
    at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:190)
    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)
Caused by: java.lang.AssertionError: Stub count doesn't match stubbed node length
    at com.intellij.psi.impl.source.FileTrees.lambda$reconcilePsi$4(FileTrees.java:182)
    at com.intellij.psi.impl.DebugUtil.performPsiModification(DebugUtil.java:548)
    at com.intellij.psi.impl.source.FileTrees.reconcilePsi(FileTrees.java:175)
    at com.intellij.psi.impl.source.FileTrees.withAst(FileTrees.java:141)
    at com.intellij.psi.impl.source.PsiFileImpl.loadTreeElement(PsiFileImpl.java:213)
    ... 44 more
bitspittle commented 3 months ago

I'll be honest, I'm not really sure what's going on here.

The color provider extension point is just doing some checks using PSI elements passed in from the IJ framework. There's no caching.

I don't think the fundamental issue (outdated stubs, etc.) is something I'm causing. Possibly I can wrap my code in a try / catch Throwable to avoid getting pointed at as a bad extension by IDEA.

Nxllpointer commented 3 months ago

@bitspittle Wrapping the entire parsing function in a try-catch seems a little overkill. From what I can deduce using the stacktrace, stuff goes downhill when accessing this.valueParameterList?.text inside of isKobwebColorFunction. Maybe there is some safe version of fetching the text? Regardless i would rather catch errors inside of isKobwebColorFunction. Also you can use runCatching { ... }.getOrDefault(false) for a nicer way of ignoring errors here.

Nxllpointer commented 3 months ago

I do aggree though that this is probably not the plugin causing the issue

bitspittle commented 3 months ago

Thanks @Nxllpointer for also taking a look.

It's possible the best course of action is to actually remove the code I introduced entirely. This seems like such a fundamental error that there's no way we could catch all places.

It's also unfortunately very timing specific and hard (impossible?) for us to reproduce.

Here are some more interesting links that LoP surfaced:

LoP saw the error two times when they were doing rebase / merges.

Nxllpointer commented 3 months ago

Could this perhaps be due to a race condition? I am pretty certain our getColorFrom gets called on some other thread, so the PSI tree could possibly be updated while our method is running. That might explain why the error surfaced when rebasing/merging, since a lot of code gets changed in an instant by an external source. Very wild speculation though.