Browse Source

Intellij compatibility fixes (#2733)

* Set 2022.1.1 as base IJ version

Stable AS is based on 2022.1.1 now,
so we can drop supporting 2021.3

* Update IDE plugin target bytecode version to 11

When 2022.1 is used as a base for IDE plugin,
inline functions from the platform
& the bundled Kotlin plugin cannot be used
unless target bytecode version is set to 11.

* Update Intellij SDK Gradle plugin

* Check editor is not disposed before showing preview toolbar

#2663

* Add preview caret listener only to main editor
pull/2705/merge
Alexey Tsvetkov 2 years ago committed by GitHub
parent
commit
fb441e505d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      idea-plugin/build.gradle.kts
  2. 4
      idea-plugin/gradle.properties
  3. 19
      idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewFloatingToolbarProvider.kt

10
idea-plugin/build.gradle.kts

@ -1,9 +1,9 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
plugins { plugins {
id("java") id("java")
id("org.jetbrains.kotlin.jvm") version "1.5.10" id("org.jetbrains.kotlin.jvm") version "1.5.10"
id("org.jetbrains.intellij") version "1.10.1" id("org.jetbrains.intellij") version "1.12.0"
id("org.jetbrains.changelog") version "1.3.1" id("org.jetbrains.changelog") version "1.3.1"
} }
@ -44,11 +44,11 @@ tasks.buildSearchableOptions {
tasks { tasks {
// Set the compatibility versions to 1.8 // Set the compatibility versions to 1.8
withType<JavaCompile> { withType<JavaCompile> {
sourceCompatibility = "1.8" sourceCompatibility = "11"
targetCompatibility = "1.8" targetCompatibility = "11"
} }
withType<KotlinJvmCompile> { withType<KotlinJvmCompile> {
kotlinOptions.jvmTarget = "1.8" kotlinOptions.jvmTarget = "11"
} }
publishPlugin { publishPlugin {

4
idea-plugin/gradle.properties

@ -7,8 +7,8 @@ deploy.version=0.1-SNAPSHOT
plugin.channels=snapshots plugin.channels=snapshots
# Intellij since-build should be updated directly in src/main/resources/META-INF/plugin.xml # Intellij since-build should be updated directly in src/main/resources/META-INF/plugin.xml
# See https://jb.gg/intellij-platform-builds-list for available build versions. # See https://jb.gg/intellij-platform-builds-list for available build versions.
plugin.verifier.ide.versions=2021.3, 2022.1, 2022.2 plugin.verifier.ide.versions=2022.1, 2022.2, 2022.3
platform.type=IC platform.type=IC
platform.version=2021.3 platform.version=2022.1.1
platform.download.sources=true platform.download.sources=true

19
idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewFloatingToolbarProvider.kt

@ -8,13 +8,17 @@ package org.jetbrains.compose.desktop.ide.preview
import com.intellij.openapi.Disposable import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.diff.impl.DiffUtil
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.event.CaretEvent import com.intellij.openapi.editor.event.CaretEvent
import com.intellij.openapi.editor.event.CaretListener import com.intellij.openapi.editor.event.CaretListener
import com.intellij.openapi.editor.toolbar.floating.AbstractFloatingToolbarProvider import com.intellij.openapi.editor.toolbar.floating.AbstractFloatingToolbarProvider
import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarComponent import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarComponent
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.testFramework.LightVirtualFileBase
import com.intellij.util.concurrency.AppExecutorUtil import com.intellij.util.concurrency.AppExecutorUtil
import org.jetbrains.kotlin.idea.KotlinFileType
class PreviewFloatingToolbarProvider : AbstractFloatingToolbarProvider(PREVIEW_EDITOR_TOOLBAR_GROUP_ID) { class PreviewFloatingToolbarProvider : AbstractFloatingToolbarProvider(PREVIEW_EDITOR_TOOLBAR_GROUP_ID) {
override val autoHideable = false override val autoHideable = false
@ -22,8 +26,10 @@ class PreviewFloatingToolbarProvider : AbstractFloatingToolbarProvider(PREVIEW_E
// todo: disable if not in Compose JVM module // todo: disable if not in Compose JVM module
override fun register(dataContext: DataContext, component: FloatingToolbarComponent, parentDisposable: Disposable) { override fun register(dataContext: DataContext, component: FloatingToolbarComponent, parentDisposable: Disposable) {
val editor = dataContext.getData(CommonDataKeys.EDITOR) ?: return val editor = dataContext.getData(CommonDataKeys.EDITOR) ?: return
if (isInsideMainKtEditor(editor)) {
registerComponent(component, editor, parentDisposable) registerComponent(component, editor, parentDisposable)
} }
}
private fun registerComponent( private fun registerComponent(
component: FloatingToolbarComponent, component: FloatingToolbarComponent,
@ -50,6 +56,7 @@ internal class PreviewEditorToolbarVisibilityUpdater(
} }
private fun updateVisibility() { private fun updateVisibility() {
if (!editor.isDisposed) {
val parentPreviewFun = parentPreviewAtCaretOrNull(editor) val parentPreviewFun = parentPreviewAtCaretOrNull(editor)
if (parentPreviewFun != null) { if (parentPreviewFun != null) {
toolbar.scheduleShow() toolbar.scheduleShow()
@ -57,4 +64,16 @@ internal class PreviewEditorToolbarVisibilityUpdater(
toolbar.scheduleHide() toolbar.scheduleHide()
} }
} }
}
}
private fun isInsideMainKtEditor(editor: Editor): Boolean =
!DiffUtil.isDiffEditor(editor) && editor.isKtFileEditor()
private fun Editor.isKtFileEditor(): Boolean {
val documentManager = FileDocumentManager.getInstance()
val virtualFile = documentManager.getFile(document) ?: return false
return virtualFile !is LightVirtualFileBase
&& virtualFile.isValid
&& virtualFile.fileType == KotlinFileType.INSTANCE
} }
Loading…
Cancel
Save