[kotlin] add an action to invalidate Kotlin plugin K2 mode resolve caches

^KTIJ-27430 fixed

GitOrigin-RevId: e63720f56184304af7eafc4c648b21b3054c4217
This commit is contained in:
Ilya Kirillov
2024-10-11 11:01:37 +02:00
committed by intellij-monorepo-bot
parent fa36670220
commit 236e8f653b
11 changed files with 208 additions and 1 deletions

1
.idea/modules.xml generated
View File

@@ -1193,6 +1193,7 @@
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/jvm-debugger/test/compose/kotlin.jvm-debugger.test.compose.k2.iml" filepath="$PROJECT_DIR$/plugins/kotlin/jvm-debugger/test/compose/kotlin.jvm-debugger.test.compose.k2.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/jvm-debugger/test/k2/kotlin.jvm-debugger.test.k2.iml" filepath="$PROJECT_DIR$/plugins/kotlin/jvm-debugger/test/k2/kotlin.jvm-debugger.test.k2.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/jvm-decompiler/kotlin.jvm-decompiler.iml" filepath="$PROJECT_DIR$/plugins/kotlin/jvm-decompiler/kotlin.jvm-decompiler.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/internal/kotlin.k2.internal.iml" filepath="$PROJECT_DIR$/plugins/kotlin/internal/kotlin.k2.internal.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/kotlin.lombok.tests/kotlin.k2.lombok.tests.iml" filepath="$PROJECT_DIR$/plugins/kotlin/kotlin.lombok.tests/kotlin.k2.lombok.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/maven/kotlin.maven.iml" filepath="$PROJECT_DIR$/plugins/kotlin/maven/kotlin.maven.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/maven/tests/kotlin.maven.tests.iml" filepath="$PROJECT_DIR$/plugins/kotlin/maven/tests/kotlin.maven.tests.iml" />

View File

@@ -195,7 +195,8 @@ object KotlinPluginBuilder {
"kotlin.refactorings.rename.k2",
"kotlin.performanceExtendedPlugin",
"kotlin.bundled-compiler-plugins-support",
"kotlin.jsr223"
"kotlin.jsr223",
"kotlin.k2.internal",
)
private val KOTLIN_SCRIPTING_LIBRARIES = java.util.List.of(

View File

@@ -212,5 +212,6 @@
<orderEntry type="module" module-name="kotlin.formatter.minimal" exported="" />
<orderEntry type="module" module-name="kotlin.ide" exported="" />
<orderEntry type="module" module-name="kotlin.jsr223" exported="" />
<orderEntry type="module" module-name="kotlin.k2.internal" exported="" />
</component>
</module>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="library" name="kotlin-stdlib" level="project" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="intellij.platform.editor" />
<orderEntry type="module" module-name="intellij.platform.core" />
<orderEntry type="module" module-name="kotlin.base.util" />
<orderEntry type="module" module-name="kotlin.fir.frontend-independent" />
<orderEntry type="module" module-name="intellij.java" />
<orderEntry type="module" module-name="kotlin.base.plugin" />
<orderEntry type="library" name="kotlinc.low-level-api-fir" level="project" />
<orderEntry type="module" module-name="kotlin.base.analysis" />
<orderEntry type="library" name="kotlinc.analysis-api-platform-interface" level="project" />
<orderEntry type="module" module-name="intellij.platform.ide.impl" />
<orderEntry type="module" module-name="kotlin.base.resources" />
</component>
</module>

View File

@@ -0,0 +1,13 @@
<idea-plugin package="org.jetbrains.kotlin.idea.internal.actions">
<resource-bundle>messages.KotlinInternalBundle</resource-bundle>
<actions>
<action id="InvalidateK2CachesInternalAction" class="org.jetbrains.kotlin.idea.internal.actions.InvalidateK2CachesInternalAction" internal="true">
<add-to-group group-id="KotlinInternalGroup"/>
</action>
</actions>
<extensions defaultExtensionNs="com.intellij">
<notificationGroup id="Internal Kotlin Plugin Actions" displayType="BALLOON" bundle="messages.KotlinInternalBundle"
key="internal.kotlin.plugin.actions.notification.group"/>
</extensions>
</idea-plugin>

View File

@@ -0,0 +1,14 @@
action.InvalidateK2CachesInternalAction.text=Invalidate Kotlin Plugin K2 Mode Caches
internal.kotlin.plugin.actions.notification.group=Internal Kotlin plugin actions
notification.content.kotlin.internal.resolution.caches.were.invalidated.title=Kotlin caches are invalidated.
dialog.title.invalidate.caches=Invalidate Caches
button.source.library.caches=Source and Library Caches
button.source.caches=Source Caches
notification.content.source.caches=Source caches
notification.content.source.library.caches=Source and library caches
invalidate.source.caches.tooltip=Invalidates all K2 plugin source and script caches.<br/>\
Library caches are kept intact.<br/>\
Invoking this action should be equivalent to performing an out-of-block modification in each module simultaneously.<br/>
invalidate.source.library.caches.tooltip=Invalidates all K2 plugin source, script, builtins, and library caches.<br/>\
Invoking this action should be equivalent to removing and re-adding all project libraries, \
as well as performing an out-of-block modification in each module simultaneously.

View File

@@ -0,0 +1,134 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.internal.actions
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.icons.AllIcons
import com.intellij.java.library.JavaLibraryModificationTracker
import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.notification.Notifications
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.util.NlsContexts
import com.intellij.ui.dsl.builder.panel
import org.jetbrains.kotlin.analysis.api.platform.analysisMessageBus
import org.jetbrains.kotlin.analysis.api.platform.modification.KotlinModificationTopics
import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirInternals
import org.jetbrains.kotlin.analysis.low.level.api.fir.projectStructure.LLFirBuiltinsSessionFactory
import org.jetbrains.kotlin.idea.KotlinIcons
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider
import org.jetbrains.kotlin.idea.caches.trackers.KotlinIDEModificationTrackerService
import org.jetbrains.kotlin.idea.util.application.isApplicationInternalMode
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import javax.swing.JComponent
internal class InvalidateK2CachesInternalAction : AnAction() {
override fun getActionUpdateThread() = ActionUpdateThread.BGT
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
val invalidationMode = InvalidateCachesDialog.show() ?: return
invalidateCaches(project, invalidationMode)
DaemonCodeAnalyzer.getInstance(project).restart()
showNotificationAboutInvalidatedCaches(project, invalidationMode)
}
@OptIn(LLFirInternals::class)
@Suppress("TestOnlyProblems")
private fun invalidateCaches(project: Project, invalidationMode: InvalidationMode) = runWriteAction {
if (invalidationMode.invalidateSources) {
KotlinIDEModificationTrackerService.invalidateCaches(project)
project.analysisMessageBus.apply {
syncPublisher(KotlinModificationTopics.GLOBAL_SOURCE_OUT_OF_BLOCK_MODIFICATION).onModification()
syncPublisher(KotlinModificationTopics.GLOBAL_SCRIPT_MODULE_STATE_MODIFICATION).onModification()
}
}
if (invalidationMode.invalidateLibraries) {
LLFirBuiltinsSessionFactory.getInstance(project).clearForTheNextTest()
JavaLibraryModificationTracker.incModificationCount(project)
project.analysisMessageBus.apply {
syncPublisher(KotlinModificationTopics.GLOBAL_MODULE_STATE_MODIFICATION).onModification()
}
}
}
private fun showNotificationAboutInvalidatedCaches(project: Project, invalidationMode: InvalidationMode) {
val content: @NlsContexts.NotificationContent String = when (invalidationMode) {
InvalidationMode.OnlySourceCaches -> KotlinInternalBundle.message("notification.content.source.caches")
InvalidationMode.LibraryAndSourceCaches -> KotlinInternalBundle.message("notification.content.source.library.caches")
}
val notification = Notification(
"Internal Kotlin Plugin Actions",
KotlinInternalBundle.message("notification.content.kotlin.internal.resolution.caches.were.invalidated.title"),
content,
NotificationType.INFORMATION
).apply {
icon = KotlinIcons.FIR
}
Notifications.Bus.notify(notification, project)
}
override fun update(e: AnActionEvent) {
e.presentation.isEnabledAndVisible =
e.project != null
&& isApplicationInternalMode()
&& KotlinPluginModeProvider.isK2Mode()
}
}
private class InvalidateCachesDialog : DialogWrapper(true) {
private var result: InvalidationMode? = null
init {
init()
title = KotlinInternalBundle.message("dialog.title.invalidate.caches")
}
override fun isResizable(): Boolean {
return false
}
override fun createCenterPanel(): JComponent = panel {
row {
button(KotlinInternalBundle.message("button.source.caches")) {
result = InvalidationMode.OnlySourceCaches
close(OK_EXIT_CODE)
}.applyToComponent {
icon = AllIcons.Actions.ModuleDirectory
toolTipText = KotlinInternalBundle.message("invalidate.source.caches.tooltip")
}
button(KotlinInternalBundle.message("button.source.library.caches")) {
result = InvalidationMode.LibraryAndSourceCaches
close(OK_EXIT_CODE)
}.applyToComponent {
icon = AllIcons.Nodes.Library
toolTipText = KotlinInternalBundle.message("invalidate.source.library.caches.tooltip")
}
}
}
override fun createSouthPanel(): JComponent = panel {}
companion object {
fun show(): InvalidationMode? {
val dialog = InvalidateCachesDialog()
if (!dialog.showAndGet()) return null
return dialog.result
}
}
}
private enum class InvalidationMode(
val invalidateSources: Boolean,
val invalidateLibraries: Boolean,
) {
LibraryAndSourceCaches(invalidateSources = true, invalidateLibraries = true),
OnlySourceCaches(invalidateSources = true, invalidateLibraries = false),
}

View File

@@ -0,0 +1,16 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.internal.actions
import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey
import org.jetbrains.kotlin.util.AbstractKotlinBundle
@NonNls
private const val BUNDLE = "messages.KotlinInternalBundle"
internal object KotlinInternalBundle : AbstractKotlinBundle(BUNDLE) {
@Nls
@JvmStatic
fun message(@NonNls @PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any): String = getMessage(key, *params)
}

View File

@@ -123,5 +123,6 @@
<orderEntry type="module" module-name="kotlin.performanceExtendedPlugin" scope="RUNTIME" />
<orderEntry type="module" module-name="kotlin.jvm-debugger.evaluation.k2" scope="RUNTIME" />
<orderEntry type="module" module-name="kotlin.features-trainer" scope="RUNTIME" />
<orderEntry type="module" module-name="kotlin.k2.internal" scope="RUNTIME" />
</component>
</module>

View File

@@ -272,6 +272,7 @@
<module name="kotlin.base.injection"/>
<module name="kotlin.j2k.k2"/>
<module name="kotlin.k2.internal"/>
<module name="kotlin.performanceExtendedPlugin"/>
</content>

View File

@@ -256,6 +256,7 @@
- name: kotlin.performanceExtendedPlugin
- name: kotlin.bundled-compiler-plugins-support
- name: kotlin.jsr223
- name: kotlin.k2.internal
- name: kotlin-ultimate.common-native
- name: kotlin-ultimate.javascript.debugger
- name: kotlin-ultimate.javascript.nodeJs