diff --git a/integrations/intellij/gradle.properties b/integrations/intellij/gradle.properties index c0ddce2cbd5..abc73a72c6c 100644 --- a/integrations/intellij/gradle.properties +++ b/integrations/intellij/gradle.properties @@ -7,16 +7,16 @@ pluginVersion = 1.28.0 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. -pluginSinceBuild = 233 +pluginSinceBuild = 231 pluginUntilBuild = 233.* # Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl # See https://jb.gg/intellij-platform-builds-list for available build versions. -pluginVerifierIdeVersions = 2023.3 +pluginVerifierIdeVersions = 2023.1,2023.2,2023.3 platformType = IC -platformVersion = 2023.3 -platformDownloadSources = true +platformVersion = 2023.1 +platformDownloadSources = false # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 diff --git a/integrations/intellij/src/main/kotlin/com/previewjs/intellij/plugin/services/ProjectService.kt b/integrations/intellij/src/main/kotlin/com/previewjs/intellij/plugin/services/ProjectService.kt index dddc3d10b04..075212444bf 100644 --- a/integrations/intellij/src/main/kotlin/com/previewjs/intellij/plugin/services/ProjectService.kt +++ b/integrations/intellij/src/main/kotlin/com/previewjs/intellij/plugin/services/ProjectService.kt @@ -1,6 +1,5 @@ package com.previewjs.intellij.plugin.services -import com.intellij.codeInsight.daemon.impl.InlayHintsPassFactoryInternal import com.intellij.execution.filters.TextConsoleBuilderFactory import com.intellij.execution.ui.ConsoleView import com.intellij.execution.ui.ConsoleViewContentType @@ -43,6 +42,8 @@ import org.apache.commons.lang.StringUtils import org.cef.browser.CefBrowser import org.cef.browser.CefFrame import org.cef.handler.CefLoadHandlerAdapter +import java.lang.invoke.MethodHandle +import java.lang.invoke.MethodHandles import java.net.URLEncoder import kotlin.math.max @@ -234,11 +235,42 @@ class ProjectService(private val project: Project) : Disposable { crawlFile(file) { components -> componentMap[file.path] = Pair(text, components) app.invokeLater { - InlayHintsPassFactoryInternal.restartDaemonUpdatingHints(project) + restartDaemonUpdatingHints.getOrNull()?.invoke(project) } } } + /** + * Locate the `InlayHintsPassFactory` class. + * + * This class was moved to a different package in 233.6745.305 (2023.3 EAP 1). + * + * See [IDEA-333164](https://youtrack.jetbrains.com/issue/IDEA-333164/Breaking-change-with-InlayHintsPassFactory-class-moved-in-another-package) + * + * Note this initialization bias by looking first at the latest known name supposing users tend to have the latest version. + */ + @Suppress("LocalVariableName") + private val restartDaemonUpdatingHints: Result = + runCatching { + // Most recent name, since 233.13135 (2023.3.3) + Class.forName("com.intellij.codeInsight.daemon.impl.InlayHintsPassFactoryInternal") + }.recoverCatching { + // fallback to new package in 233.6745.305 (2023.3 EAP 1 up to 2023.3.2) + Class.forName("com.intellij.codeInsight.daemon.impl.InlayHintsPassFactory") + }.recoverCatching { + // fallback to package prior 233.6745.305 e.g. 2023.2 + Class.forName("com.intellij.codeInsight.hints.InlayHintsPassFactory____") + }.mapCatching { InlayHintsPassFactory_Class -> + @Suppress("ktlint:standard:property-naming") + val InlayHintsPassFactory_Companion_Instance = + InlayHintsPassFactory_Class.getField("Companion").get(null) + val InlayHintsPassFactory_Companion_Class = InlayHintsPassFactory_Companion_Instance.javaClass + + MethodHandles.lookup().unreflect( + InlayHintsPassFactory_Companion_Class.getMethod("restartDaemonUpdatingHints", Project::class.java), + ).bindTo(InlayHintsPassFactory_Companion_Instance) + } + private fun onFileClosed(file: VirtualFile) { componentMap.remove(file.path) }