Skip to content

Commit

Permalink
fix(intellij): add back compatibility for earlier 2023.* versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fwouts committed Feb 8, 2024
1 parent 659f382 commit 21a7faf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
8 changes: 4 additions & 4 deletions integrations/intellij/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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<MethodHandle> =
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)
}
Expand Down

0 comments on commit 21a7faf

Please sign in to comment.