nbadal / ktlint-intellij-plugin

Ktlint plugin for IntelliJ IDEA + Android Studio
MIT License
158 stars 23 forks source link

IllegalStateException when starting IntelliJ with 0.20.0-beta3 plugin installed #373

Closed DennisVredeveld closed 8 months ago

DennisVredeveld commented 9 months ago

When starting IntelliJ (version 2023.2.5 Ultimate) with the Ktlint plugin version 0.20.0-beta3 installed, the following exception occurs: java.lang.IllegalStateException: Must not start write action from within read action in the other thread - deadlock is coming at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:118) at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:360) at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:348) at com.nbadal.ktlint.KtlintFormatKt.ktlintFormat(KtlintFormat.kt:31) at com.nbadal.ktlint.KtlintPostFormatProcessor.processText(KtlintPostFormatProcessor.kt:20) at com.intellij.psi.impl.source.codeStyle.CoreCodeStyleUtil.postProcessRange(CoreCodeStyleUtil.java:147) at com.intellij.psi.impl.source.codeStyle.CoreCodeStyleUtil.postProcessEnabledRanges(CoreCodeStyleUtil.java:138) at com.intellij.psi.impl.source.codeStyle.CoreCodeStyleUtil.postProcessText(CoreCodeStyleUtil.java:126) at com.intellij.formatting.service.CoreFormattingService.lambda$formatRanges$0(CoreFormattingService.java:64) at com.intellij.psi.impl.source.codeStyle.CoreCodeStyleUtil.postProcessRanges(CoreCodeStyleUtil.java:114) at com.intellij.formatting.service.CoreFormattingService.formatRanges(CoreFormattingService.java:64) at com.intellij.formatting.service.FormattingServiceUtil.formatRanges(FormattingServiceUtil.java:98) at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.reformatText(CodeStyleManagerImpl.java:147) at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.reformatText(CodeStyleManagerImpl.java:112) at com.intellij.psi.impl.source.codeStyle.CodeStyleManagerImpl.reformatText(CodeStyleManagerImpl.java:105) at com.intellij.lang.javascript.refactoring.FormatFixer.fixFormat(FormatFixer.java:139) at com.intellij.lang.javascript.documentation.JSHtmlHighlightingUtil.lambda$highlightTypeOrStmtToTooltipHtmlInner$3(JSHtmlHighlightingUtil.java:506) at com.intellij.application.options.CodeStyle.doWithTemporarySettings(CodeStyle.java:367) at com.intellij.lang.javascript.documentation.JSHtmlHighlightingUtil.lambda$highlightTypeOrStmtToTooltipHtmlInner$4(JSHtmlHighlightingUtil.java:502) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:923) at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:76) at com.intellij.lang.javascript.documentation.JSHtmlHighlightingUtil.highlightTypeOrStmtToTooltipHtmlInner(JSHtmlHighlightingUtil.java:481) at com.intellij.lang.javascript.documentation.JSHtmlHighlightingUtil.highlightTypeOrStmtToTooltipHtml(JSHtmlHighlightingUtil.java:469) at com.intellij.lang.typescript.compiler.languageService.DiagnosticMessageParser.highlightCode(DiagnosticMessageParser.kt:73) at com.intellij.lang.typescript.compiler.languageService.DiagnosticMessageParser.access$highlightCode(DiagnosticMessageParser.kt:11) at com.intellij.lang.typescript.compiler.languageService.DiagnosticMessageParser$fragmentsToHtml$1.invoke(DiagnosticMessageParser.kt:16) at com.intellij.lang.typescript.compiler.languageService.DiagnosticMessageParser$fragmentsToHtml$1.invoke(DiagnosticMessageParser.kt:14) at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210) at kotlin.sequences.SequencesKt___SequencesKt.joinTo(_Sequences.kt:2874) at kotlin.sequences.SequencesKt___SequencesKt.joinToString(_Sequences.kt:2896) at kotlin.sequences.SequencesKt___SequencesKt.joinToString$default(_Sequences.kt:2895) at com.intellij.lang.typescript.compiler.languageService.DiagnosticMessageParser.fragmentsToHtml(DiagnosticMessageParser.kt:20) at com.intellij.lang.typescript.compiler.languageService.TypeScriptLanguageServiceAnnotationResult.parseRelatedErrors(TypeScriptLanguageServiceAnnotationResult.java:110) at com.intellij.lang.typescript.compiler.languageService.TypeScriptLanguageServiceAnnotationResult.buildAnnotation(TypeScriptLanguageServiceAnnotationResult.java:58) at com.intellij.lang.typescript.compiler.languageService.TypeScriptServerServiceImpl.lambda$parseDiagnosticsForFile$42(TypeScriptServerServiceImpl.java:1391) at com.intellij.util.containers.ContainerUtil.map(ContainerUtil.java:2058) at com.intellij.lang.typescript.compiler.languageService.TypeScriptServerServiceImpl.parseDiagnosticsForFile(TypeScriptServerServiceImpl.java:1391) at com.intellij.lang.typescript.compiler.languageService.TypeScriptServerServiceImpl.parseGetErrorResult(TypeScriptServerServiceImpl.java:1219) at com.intellij.lang.typescript.compiler.languageService.TypeScriptServerServiceImpl$3.process(TypeScriptServerServiceImpl.java:1146) at com.intellij.lang.typescript.compiler.languageService.TypeScriptServerServiceImpl$3.process(TypeScriptServerServiceImpl.java:1140) at com.intellij.lang.javascript.service.JSLanguageServiceQueueImpl.executeWithCacheImpl(JSLanguageServiceQueueImpl.java:97) at com.intellij.lang.javascript.service.JSLanguageServiceQueueImpl.lambda$executeWithCache$0(JSLanguageServiceQueueImpl.java:47) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:840)

paul-dingemans commented 9 months ago

@DennisVredeveld Without a reproducer this is really hard to fix/analyze. When reading the stacktrace, I do see a few things that might help you to reproduce the issue:

DennisVredeveld commented 9 months ago

@DennisVredeveld Without a reproducer this is really hard to fix/analyze. When reading the stacktrace, I do see a few things that might help you to reproduce the issue:

  • I see quite some references to TypeScript. Can you recall whether a typescript file had to be opened in an editor window when starting your IDEA?

Yes, this was probably the case. However, I can also reproduce the issue by opening a project that does not contain any JS/TS files. Having a project with TS/JS files in an editor when opening a new project seems to be enough to trigger the issue.

  • JSHtmlHighlightingUtil.highlightTypeOrStmtToTooltipHtmlInner Did the error occur when you were highlight some JavaScript? If so, was this javascript embedded in some kotlin code?

As said, the JS was in an already opened project, not in the one I was opening when the stack trace occurred. It is React/Nextjs project which also contains Kotlin code. However, the JS is not nested in the Kotlin code afaik. I can point you to the repository offline if you want (you should be able to access it as you are working for the same company)

paul-dingemans commented 9 months ago

@DennisVredeveld Would you mind trying out the new 0.20.0-beta-6 version? It can be installed via Intellij IDEA marketplace after adding the additional plugin repository for ktlint.

Steps:

paul-dingemans commented 8 months ago

Please test with new stable version 0.20.0.