Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ val descriptors = listOf(
PluginDescriptor(
since = "242.*", // this version is 2024.2.x
until = "243.*",
sdkVersion = "2024.2",
sdkVersion = "2024.2.2",
sourceFolder = "IC-242",
useInstaller = true,
),
Expand Down Expand Up @@ -111,6 +111,12 @@ val runWithCustomSandbox by intellijPlatformTesting.runIde.registering {
}
}

val runWithK2Mode by intellijPlatformTesting.runIde.registering {
task {
jvmArgs = listOf("-Didea.kotlin.plugin.use.k2=true")
}
}

intellijPlatform {
buildSearchableOptions = false
projectName = project.name
Expand Down Expand Up @@ -165,7 +171,7 @@ dependencies {
// testRuntimeOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
}

configurations.all {
configurations.runtimeOnly {
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core-jvm")
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-core")
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-jdk8")
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ version=1.1.0

org.gradle.caching=true
sandbox = /tmp/

kotlin.stdlib.default.dependency = false
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
kotlin = "1.9.25"
kotlin = "2.0.21"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this impact users or does it not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's impossible to use 1.9.x version with kotlin jars from 243 platform anymore, because they were compiled with 2.1 already. Unfortunately, I think, I missed one version indeed: it seems, 223 was build with 1.8 and it won't be compatible with 2.0. Can we drop 223 or do I need to provide logic to make the version dependant on the platform version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can drop 223

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then there should be no problems with later versions

runtime-kotest = "4.2.0"
# We separate these from the actual runtime dependencies
test-kotest = "5.9.1"
Expand Down
36 changes: 36 additions & 0 deletions src/IC-223/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.typeUtil.supertypes

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries
.mapNotNull { it.typeReference }
.mapNotNull {
runCatching {
val bindingContext = it.analyze()
bindingContext.get(BindingContext.TYPE, it)
}.getOrNull()
}.flatMap {
runCatching {
it.supertypes() + it
}.getOrElse { emptyList() }
}.mapNotNull {
runCatching {
it.constructor.declarationDescriptor.classId
}.getOrNull()
}.mapNotNull {
runCatching {
val packageName = it.packageFqName
val simpleName = it.relativeClassName
FqName("$packageName.$simpleName")
}.getOrNull()
}.filterNot { it.toString() == "kotlin.Any" }
}
36 changes: 36 additions & 0 deletions src/IC-231/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.typeUtil.supertypes

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries
.mapNotNull { it.typeReference }
.mapNotNull {
runCatching {
val bindingContext = it.analyze()
bindingContext.get(BindingContext.TYPE, it)
}.getOrNull()
}.flatMap {
runCatching {
it.supertypes() + it
}.getOrElse { emptyList() }
}.mapNotNull {
runCatching {
it.constructor.declarationDescriptor.classId
}.getOrNull()
}.mapNotNull {
runCatching {
val packageName = it.packageFqName
val simpleName = it.relativeClassName
FqName("$packageName.$simpleName")
}.getOrNull()
}.filterNot { it.toString() == "kotlin.Any" }
}
36 changes: 36 additions & 0 deletions src/IC-232/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.typeUtil.supertypes

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries
.mapNotNull { it.typeReference }
.mapNotNull {
runCatching {
val bindingContext = it.analyze()
bindingContext.get(BindingContext.TYPE, it)
}.getOrNull()
}.flatMap {
runCatching {
it.supertypes() + it
}.getOrElse { emptyList() }
}.mapNotNull {
runCatching {
it.constructor.declarationDescriptor.classId
}.getOrNull()
}.mapNotNull {
runCatching {
val packageName = it.packageFqName
val simpleName = it.relativeClassName
FqName("$packageName.$simpleName")
}.getOrNull()
}.filterNot { it.toString() == "kotlin.Any" }
}
36 changes: 36 additions & 0 deletions src/IC-233/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.typeUtil.supertypes

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries
.mapNotNull { it.typeReference }
.mapNotNull {
runCatching {
val bindingContext = it.analyze()
bindingContext.get(BindingContext.TYPE, it)
}.getOrNull()
}.flatMap {
runCatching {
it.supertypes() + it
}.getOrElse { emptyList() }
}.mapNotNull {
runCatching {
it.constructor.declarationDescriptor.classId
}.getOrNull()
}.mapNotNull {
runCatching {
val packageName = it.packageFqName
val simpleName = it.relativeClassName
FqName("$packageName.$simpleName")
}.getOrNull()
}.filterNot { it.toString() == "kotlin.Any" }
}
36 changes: 36 additions & 0 deletions src/IC-241/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.typeUtil.supertypes

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries
.mapNotNull { it.typeReference }
.mapNotNull {
runCatching {
val bindingContext = it.analyze()
bindingContext.get(BindingContext.TYPE, it)
}.getOrNull()
}.flatMap {
runCatching {
it.supertypes() + it
}.getOrElse { emptyList() }
}.mapNotNull {
runCatching {
it.constructor.declarationDescriptor.classId
}.getOrNull()
}.mapNotNull {
runCatching {
val packageName = it.packageFqName
val simpleName = it.relativeClassName
FqName("$packageName.$simpleName")
}.getOrNull()
}.filterNot { it.toString() == "kotlin.Any" }
}
32 changes: 32 additions & 0 deletions src/IC-242/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.types.symbol
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.psi.KtClassOrObject

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
@OptIn(KaAllowAnalysisOnEdt::class)
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries.mapNotNull { it.typeReference }
.flatMap { ref ->
// SurroundSelectionWithFunctionIntention.isAvailable is called in EDT before the intention is applied
// unfortunately API to avoid this was introduced in 23.2 only
// this we need to move intentions to the facade or accept EDT here until 23.2- are still supported
allowAnalysisOnEdt {
analyze(this) {
val kaType = ref.type
val superTypes = (kaType.allSupertypes(false) + kaType).toList()
superTypes.mapNotNull {
val classId = it.symbol?.classId?.takeIf { id -> id != StandardClassIds.Any }
classId?.asSingleFqName()
}
}
}
}
}
32 changes: 32 additions & 0 deletions src/IC-243/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.kotest.plugin.intellij.psi

import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.types.symbol
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.psi.KtClassOrObject

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
@OptIn(KaAllowAnalysisOnEdt::class)
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries.mapNotNull { it.typeReference }
.flatMap { ref ->
// SurroundSelectionWithFunctionIntention.isAvailable is called in EDT before the intention is applied
// unfortunately API to avoid this was introduced in 23.2 only
// this we need to move intentions to the facade or accept EDT here until 23.2- are still supported
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you clarify this comment, it doesn't quite make sense to me (about the intention)

Copy link
Contributor Author

@akozlova akozlova Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the comment on allowing resolve on EDT which is prohibited, because it might be slow and lead to freezes of the whole IDE. It's possible to avoid this suppression if we would rewrite SurroundSelectionWithFunctionIntention but the API doesn't exist for older versions and we would need to have it in facade. So I decided to wait until you drop older versions and currently do nothing about it.

allowAnalysisOnEdt {
analyze(this) {
val kaType = ref.type
val superTypes = (kaType.allSupertypes(false) + kaType).toList()
superTypes.mapNotNull {
val classId = it.symbol?.classId?.takeIf { id -> id != StandardClassIds.Any }
classId?.asSingleFqName()
}
}
}
}
}
32 changes: 0 additions & 32 deletions src/main/kotlin/io/kotest/plugin/intellij/psi/classes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtObjectDeclaration
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.isAbstract
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.types.typeUtil.supertypes

/**
* Returns the [KtClass] from this light class, otherwise null.
Expand Down Expand Up @@ -46,34 +42,6 @@ fun PsiElement.enclosingKtClass(): KtClass? = getStrictParentOfType()
fun PsiElement.enclosingKtClassOrObject(): KtClassOrObject? =
PsiTreeUtil.getParentOfType(this, KtClassOrObject::class.java)

/**
* Recursively returns the list of classes and interfaces extended or implemented by the class.
*/
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
return superTypeListEntries
.mapNotNull { it.typeReference }
.mapNotNull {
runCatching {
val bindingContext = it.analyze()
bindingContext.get(BindingContext.TYPE, it)
}.getOrNull()
}.flatMap {
runCatching {
it.supertypes() + it
}.getOrElse { emptyList() }
}.mapNotNull {
runCatching {
it.constructor.declarationDescriptor.classId
}.getOrNull()
}.mapNotNull {
runCatching {
val packageName = it.packageFqName
val simpleName = it.relativeClassName
FqName("$packageName.$simpleName")
}.getOrNull()
}.filterNot { it.toString() == "kotlin.Any" }
}

/**
* Returns true if this [KtClassOrObject] points to a runnable spec object.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import io.kotest.plugin.intellij.psi.specs
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.jetbrains.kotlin.idea.core.util.toPsiFile
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtProperty
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@
</intentionAction>
</extensions>

<extensions defaultExtensionNs="org.jetbrains.kotlin">
<supportsKotlinPluginMode supportsK2="true" />
</extensions>

</idea-plugin>
Loading