From ca17e28672f883261b3bb0fa171de6ad5df1d1c8 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Wed, 28 Aug 2024 19:32:12 +0200 Subject: [PATCH] [kotlin] Provide instructions on how to switch to K2 mode when running a debug instance of IJ #KTIJ-31127 GitOrigin-RevId: d80ea27b9aea7be5485a843452d4d30cee03ef21 --- .../KotlinPreferencesBundle.properties | 1 + .../ui/KotlinPluginKindSwitcherController.kt | 64 +++++++++++-------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/plugins/kotlin/preferences/resources/messages/KotlinPreferencesBundle.properties b/plugins/kotlin/preferences/resources/messages/KotlinPreferencesBundle.properties index 08c4db9f69b4..14a24e8b0099 100644 --- a/plugins/kotlin/preferences/resources/messages/KotlinPreferencesBundle.properties +++ b/plugins/kotlin/preferences/resources/messages/KotlinPreferencesBundle.properties @@ -10,4 +10,5 @@ label.your.current.plugin=Current Kotlin Mode is {0} link.label.cancel.switching=Cancel switching checkbox.enable.k2.based.kotlin.plugin=Enable K2 mode text.k2.based.kotlin.plugin=K2 mode brings stability and code analysis improvements. Some functionality is still a work in progress and will be supported as soon as it\u2019s ready. Read more here. +text.k2.based.kotlin.plugin.vmoptions.are.not.writable.0.1=You are running a debug instance of IntelliJ IDEA.
To switch to {1,choice,1#K1|2#K2} mode, please manually set the VM Option to
{0}{1,choice,1#false|2#true} kotlin.language.configurable=Kotlin diff --git a/plugins/kotlin/preferences/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinPluginKindSwitcherController.kt b/plugins/kotlin/preferences/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinPluginKindSwitcherController.kt index 7b2d3058f8af..8f30571e7887 100644 --- a/plugins/kotlin/preferences/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinPluginKindSwitcherController.kt +++ b/plugins/kotlin/preferences/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinPluginKindSwitcherController.kt @@ -66,23 +66,25 @@ class KotlinPluginKindSwitcherController { ) text(text) } - row { - val text = KotlinPreferencesBundle.message( - "label.plugin.will.be.switched.after.ide.restart", - currentPluginMode.other.pluginModeDescription, - ) - text(text) - } - row { - link( - IdeBundle.message("dialog.message.must.be.restarted.for.changes.to.take.effect", productName) - ) { - suggestRestart(productName) + if (VMOptions.canWriteOptions()) { + row { + val text = KotlinPreferencesBundle.message( + "label.plugin.will.be.switched.after.ide.restart", + currentPluginMode.other.pluginModeDescription, + ) + text(text) } - } - row { - link(KotlinPreferencesBundle.message("link.label.cancel.switching")) { - cancelSwitching() + row { + link( + IdeBundle.message("dialog.message.must.be.restarted.for.changes.to.take.effect", productName) + ) { + suggestRestart(productName) + } + } + row { + link(KotlinPreferencesBundle.message("link.label.cancel.switching")) { + cancelSwitching() + } } } } @@ -90,12 +92,27 @@ class KotlinPluginKindSwitcherController { row { checkBox(KotlinPreferencesBundle.message("checkbox.enable.k2.based.kotlin.plugin")).also { checkBox = it.component + enabled(VMOptions.canWriteOptions()) }.onChanged { chosenKind = KotlinPluginMode.of(it.isSelected) }.gap(RightGap.SMALL) icon(AllIcons.General.Beta).align(AlignY.BOTTOM) updateCheckBoxToChosenKind() - comment(KotlinPreferencesBundle.message("kotlin.plugin.type.restart.required.comment")) + if (VMOptions.canWriteOptions()) { + comment(KotlinPreferencesBundle.message("kotlin.plugin.type.restart.required.comment")) + } + } + + if (!VMOptions.canWriteOptions()) { + row { + icon(AllIcons.General.Warning).align(AlignY.TOP).gap(rightGap = RightGap.SMALL) + text( + KotlinPreferencesBundle.message( + "text.k2.based.kotlin.plugin.vmoptions.are.not.writable.0.1", + USE_K2_PLUGIN_VM_OPTION_PREFIX, + 1.takeIf { useK2Plugin == true } ?: 2) + ) + } } row { @@ -122,21 +139,18 @@ class KotlinPluginKindSwitcherController { } private fun updatePanels() { - currentPluginPanel.visible(pluginKindWillBeSwitchedAfterRestart) - pluginTypeChooserPanel.visible(!pluginKindWillBeSwitchedAfterRestart) + val visible = VMOptions.canWriteOptions() && pluginKindWillBeSwitchedAfterRestart + currentPluginPanel.visible(visible) + pluginTypeChooserPanel.visible(!visible) } private fun updateCheckBoxToChosenKind() { checkBox.isSelected = chosenKind == KotlinPluginMode.K2 } - companion object { - fun createIfPluginSwitchIsPossible(): KotlinPluginKindSwitcherController? { - return if (VMOptions.canWriteOptions()) KotlinPluginKindSwitcherController() - else null - } + fun createIfPluginSwitchIsPossible(): KotlinPluginKindSwitcherController? = KotlinPluginKindSwitcherController() fun suggestRestart(productName: String) { val application = ApplicationManager.getApplication() as ApplicationEx @@ -159,7 +173,7 @@ class KotlinPluginKindSwitcherController { const val USE_K2_PLUGIN_VM_OPTION_PREFIX: @NonNls String = "-D$USE_K2_PLUGIN_PROPERTY_NAME=" private var useK2Plugin: Boolean? - get() = VMOptions.readOption(USE_K2_PLUGIN_VM_OPTION_PREFIX, /*effective=*/ false)?.toBoolean() + get() = VMOptions.readOption(USE_K2_PLUGIN_VM_OPTION_PREFIX, /*effective=*/ KotlinPluginModeProvider.isK2Mode())?.toBoolean() set(value) { VMOptions.setOption(USE_K2_PLUGIN_VM_OPTION_PREFIX, value?.toString()) }