Skip to content

Commit

Permalink
Fix K2 mode incompatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Sep 29, 2024
1 parent 3c82c6b commit e97d7e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ tasks.runIde {
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")
Expand Down
17 changes: 14 additions & 3 deletions src/main/kotlin/insight/generation/EventGenHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import com.intellij.psi.PsiElement
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
Expand Down Expand Up @@ -108,15 +112,22 @@ class KotlinEventGenHelper : EventGenHelper {
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)
}
}
}

0 comments on commit e97d7e4

Please sign in to comment.