User: rednesto Date: 29 Sep 24 19:10 Revision: e97d7e483f94dcc131f3b55449fda3de71fa2e1a Summary: Fix K2 mode incompatibility TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=9735&personal=false Index: build.gradle.kts =================================================================== --- build.gradle.kts (revision 3c82c6bf279d4eaf8ef909c65f04e1faa429060f) +++ build.gradle.kts (revision e97d7e483f94dcc131f3b55449fda3de71fa2e1a) @@ -322,6 +322,12 @@ systemProperty("idea.ProcessCanceledException", "disabled") systemProperty("idea.debug.mode", "true") } + + // Kotlin K2 is enabled by default, uncomment to switch to K1 + // jvmArgumentProviders += CommandLineArgumentProvider { + // listOf("-Didea.kotlin.plugin.use.k2=false") + // } + // Set these properties to test different languages // systemProperty("user.language", "fr") // systemProperty("user.country", "FR") Index: src/main/kotlin/insight/generation/EventGenHelper.kt =================================================================== --- src/main/kotlin/insight/generation/EventGenHelper.kt (revision 3c82c6bf279d4eaf8ef909c65f04e1faa429060f) +++ src/main/kotlin/insight/generation/EventGenHelper.kt (revision e97d7e483f94dcc131f3b55449fda3de71fa2e1a) @@ -33,6 +33,10 @@ import com.intellij.psi.PsiFile import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.util.parentOfType +import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences +import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferencesInRange +import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode +import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider import org.jetbrains.kotlin.idea.core.ShortenReferences import org.jetbrains.kotlin.psi.KtClassOrObject import org.jetbrains.kotlin.psi.KtFile @@ -108,15 +112,22 @@ val factory = KtPsiFactory.contextual(context) val entry = factory.createSuperTypeEntry(fqn) val insertedEntry = ktClass.addSuperTypeListEntry(entry) - ShortenReferences.DEFAULT.process(insertedEntry) + when (KotlinPluginModeProvider.currentPluginMode) { + KotlinPluginMode.K1 -> ShortenReferences.DEFAULT.process(insertedEntry) + // TODO find a non-internal alternative to this... + KotlinPluginMode.K2 -> shortenReferences(insertedEntry) - } + } + } override fun reformatAndShortenRefs(file: PsiFile, startOffset: Int, endOffset: Int) { file as? KtFile ?: return val project = file.project val marker = JvmEventGenHelper.doReformat(project, file, startOffset, endOffset) ?: return - - ShortenReferences.DEFAULT.process(file, marker.startOffset, marker.endOffset) + when (KotlinPluginModeProvider.currentPluginMode) { + KotlinPluginMode.K1 -> ShortenReferences.DEFAULT.process(file, marker.startOffset, marker.endOffset) + // TODO find a non-internal alternative to this... + KotlinPluginMode.K2 -> shortenReferencesInRange(file, marker.textRange) - } -} + } + } +}