mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] KTIJ-36850 Split KotlinIntentionPolicy into K1 and K2
GitOrigin-RevId: af770fa567d472dac654134ce11f859c778ce11c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
615a732b75
commit
8c7b187214
+3
@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.idea.fir.propertyBased
|
||||
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.propertyBased.KotlinCodeInsightSanityTest
|
||||
import org.jetbrains.kotlin.idea.propertyBased.KotlinIntentionPolicy
|
||||
import org.jetbrains.kotlin.idea.test.setUpWithKotlinPlugin
|
||||
|
||||
class FirKotlinCodeInsightSanityTest: KotlinCodeInsightSanityTest() {
|
||||
@@ -10,4 +11,6 @@ class FirKotlinCodeInsightSanityTest: KotlinCodeInsightSanityTest() {
|
||||
override fun setUp() {
|
||||
setUpWithKotlinPlugin { super.setUp() }
|
||||
}
|
||||
|
||||
override fun createIntentionPolicy(): KotlinIntentionPolicy = K2IntentionPolicy()
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.fir.propertyBased
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import com.intellij.codeInsight.intention.IntentionActionDelegate
|
||||
import org.jetbrains.kotlin.idea.propertyBased.KotlinIntentionPolicy
|
||||
|
||||
internal class K2IntentionPolicy : KotlinIntentionPolicy() {
|
||||
override fun shouldCheckPreview(action: IntentionAction): Boolean {
|
||||
val unwrapped = IntentionActionDelegate.unwrap(action)
|
||||
val skipPreview =
|
||||
action.familyName == "Create from usage" || // Starts template but may also perform modifications before that; thus not so easy to support
|
||||
unwrapped.javaClass.name in skipPreviewIntentionClassNames
|
||||
return !skipPreview
|
||||
}
|
||||
|
||||
private val skipPreviewIntentionClassNames =
|
||||
setOf(
|
||||
"org.jetbrains.kotlin.idea.k2.codeinsight.intentions.ChangePackageIntention", // Just starts the template; no reasonable preview could be displayed
|
||||
"org.jetbrains.kotlin.idea.k2.codeinsight.fixes.imprt.ImportQuickFix",
|
||||
"org.jetbrains.kotlin.idea.quickfix.K2EnableUnsupportedFeatureFix"
|
||||
)
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.propertyBased
|
||||
|
||||
class K1CodeInsightSanityTest : KotlinCodeInsightSanityTest() {
|
||||
override fun createIntentionPolicy(): KotlinIntentionPolicy = K1IntentionPolicy()
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.propertyBased
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import com.intellij.codeInsight.intention.IntentionActionDelegate
|
||||
import org.jetbrains.kotlin.idea.codeInsight.intentions.shared.ConvertToScopeIntention
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateCallableFromUsageFixBase
|
||||
import org.jetbrains.kotlin.idea.refactoring.move.changePackage.ChangePackageIntention
|
||||
|
||||
class K1IntentionPolicy : KotlinIntentionPolicy() {
|
||||
override fun shouldCheckPreview(action: IntentionAction): Boolean {
|
||||
val unwrapped = IntentionActionDelegate.unwrap(action)
|
||||
val skipPreview =
|
||||
action.familyName == "Create from usage" || // Starts template but may also perform modifications before that; thus not so easy to support
|
||||
unwrapped is ConvertToScopeIntention || // Performs reference search which must be run under progress. Probably we can generate diff excluding references?..
|
||||
unwrapped is CreateCallableFromUsageFixBase<*> || // Performs too much of complex stuff. Not sure whether it should start in write action...
|
||||
unwrapped is ChangePackageIntention // Just starts the template; no reasonable preview could be displayed
|
||||
return !skipPreview
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -19,7 +19,7 @@ import java.util.function.Function
|
||||
import java.util.function.Supplier
|
||||
|
||||
@SkipSlowTestLocally
|
||||
open class KotlinCodeInsightSanityTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
abstract class KotlinCodeInsightSanityTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
private val seed: String? = System.getProperty("seed")
|
||||
|
||||
override fun setUp() {
|
||||
@@ -52,7 +52,7 @@ open class KotlinCodeInsightSanityTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
AbstractImportFixInfo.ignoreModuleError(testRootDisposable)
|
||||
val actionSupplier = actionOnKotlinFiles { file: PsiFile ->
|
||||
Generator.sampledFrom(
|
||||
InvokeIntention(file, KotlinIntentionPolicy()),
|
||||
InvokeIntention(file, createIntentionPolicy()),
|
||||
//TODO: support completion mutators
|
||||
//InvokeCompletion(file, KotlinCompletionPolicy()),
|
||||
StripTestDataMarkup(file),
|
||||
@@ -67,6 +67,8 @@ open class KotlinCodeInsightSanityTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
.checkScenarios(actionSupplier)
|
||||
}
|
||||
|
||||
protected abstract fun createIntentionPolicy(): KotlinIntentionPolicy
|
||||
|
||||
private fun enableInspections() {
|
||||
MadTestingUtil.enableAllInspections(project, KotlinLanguage.INSTANCE)
|
||||
}
|
||||
|
||||
+1
-19
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.idea.codeInsight.intentions.shared.ConvertToScopeInt
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.CreateCallableFromUsageFixBase
|
||||
import org.jetbrains.kotlin.idea.refactoring.move.changePackage.ChangePackageIntention
|
||||
|
||||
internal class KotlinIntentionPolicy : IntentionPolicy() {
|
||||
abstract class KotlinIntentionPolicy : IntentionPolicy() {
|
||||
override fun shouldSkipIntention(actionText: String): Boolean =
|
||||
// These intentions don't modify code (probably should not start in write-action?)
|
||||
actionText == "Enable a trailing comma by default in the formatter" ||
|
||||
@@ -23,22 +23,4 @@ internal class KotlinIntentionPolicy : IntentionPolicy() {
|
||||
override fun mayBreakCode(action: IntentionAction, editor: Editor, file: PsiFile): Boolean = false
|
||||
|
||||
override fun shouldTolerateIntroducedError(info: HighlightInfo): Boolean = false
|
||||
|
||||
override fun shouldCheckPreview(action: IntentionAction): Boolean {
|
||||
val unwrapped = IntentionActionDelegate.unwrap(action)
|
||||
val skipPreview =
|
||||
action.familyName == "Create from usage" || // Starts template but may also perform modifications before that; thus not so easy to support
|
||||
unwrapped is ConvertToScopeIntention || // Performs reference search which must be run under progress. Probably we can generate diff excluding references?..
|
||||
unwrapped is CreateCallableFromUsageFixBase<*> || // Performs too much of complex stuff. Not sure whether it should start in write action...
|
||||
unwrapped is ChangePackageIntention || // Just starts the template; no reasonable preview could be displayed
|
||||
unwrapped.javaClass.name in skipPreviewIntentionClassNames
|
||||
return !skipPreview
|
||||
}
|
||||
|
||||
private val skipPreviewIntentionClassNames =
|
||||
setOf(
|
||||
"org.jetbrains.kotlin.idea.k2.codeinsight.intentions.ChangePackageIntention",
|
||||
"org.jetbrains.kotlin.idea.k2.codeinsight.fixes.imprt.ImportQuickFix",
|
||||
"org.jetbrains.kotlin.idea.quickfix.K2EnableUnsupportedFeatureFix"
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user