Skip to content

Commit

Permalink
Intellij compatibility fixes (#2733)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AlexeyTsvetkov authored Feb 13, 2023
1 parent 9fb0ed9 commit fb441e5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
10 changes: 5 additions & 5 deletions idea-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
id("java")
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"
}

Expand Down Expand Up @@ -44,11 +44,11 @@ tasks.buildSearchableOptions {
tasks {
// Set the compatibility versions to 1.8
withType<JavaCompile> {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
sourceCompatibility = "11"
targetCompatibility = "11"
}
withType<KotlinJvmCompile> {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.jvmTarget = "11"
}

publishPlugin {
Expand Down
4 changes: 2 additions & 2 deletions idea-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ deploy.version=0.1-SNAPSHOT
plugin.channels=snapshots
# 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.
plugin.verifier.ide.versions=2021.3, 2022.1, 2022.2
plugin.verifier.ide.versions=2022.1, 2022.2, 2022.3

platform.type=IC
platform.version=2021.3
platform.version=2022.1.1
platform.download.sources=true
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@ package org.jetbrains.compose.desktop.ide.preview
import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.diff.impl.DiffUtil
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.event.CaretEvent
import com.intellij.openapi.editor.event.CaretListener
import com.intellij.openapi.editor.toolbar.floating.AbstractFloatingToolbarProvider
import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarComponent
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.project.Project
import com.intellij.testFramework.LightVirtualFileBase
import com.intellij.util.concurrency.AppExecutorUtil
import org.jetbrains.kotlin.idea.KotlinFileType

class PreviewFloatingToolbarProvider : AbstractFloatingToolbarProvider(PREVIEW_EDITOR_TOOLBAR_GROUP_ID) {
override val autoHideable = false

// todo: disable if not in Compose JVM module
override fun register(dataContext: DataContext, component: FloatingToolbarComponent, parentDisposable: Disposable) {
val editor = dataContext.getData(CommonDataKeys.EDITOR) ?: return
registerComponent(component, editor, parentDisposable)
if (isInsideMainKtEditor(editor)) {
registerComponent(component, editor, parentDisposable)
}
}

private fun registerComponent(
Expand Down Expand Up @@ -50,11 +56,24 @@ internal class PreviewEditorToolbarVisibilityUpdater(
}

private fun updateVisibility() {
val parentPreviewFun = parentPreviewAtCaretOrNull(editor)
if (parentPreviewFun != null) {
toolbar.scheduleShow()
} else {
toolbar.scheduleHide()
if (!editor.isDisposed) {
val parentPreviewFun = parentPreviewAtCaretOrNull(editor)
if (parentPreviewFun != null) {
toolbar.scheduleShow()
} else {
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
}

0 comments on commit fb441e5

Please sign in to comment.