Skip to content

Commit b7ef9f6

Browse files
committed
make plugin ready for K2 mode
- starting from 242, the plugin works over AnalysisAPI which hides all details about kotlin engine used inside kotlin plugin itself
1 parent 939012a commit b7ef9f6

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

build.gradle.kts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,11 @@ val runWithCustomSandbox by intellijPlatformTesting.runIde.registering {
111111
}
112112
}
113113

114-
//tasks.named<RunIdeTask>("runIde") {
115-
// jvmArgumentProviders += CommandLineArgumentProvider {
116-
// listOf("-Didea.kotlin.plugin.use.k2=true")
117-
// }
118-
//}
119-
120-
//tasks.test {
121-
// jvmArgumentProviders += CommandLineArgumentProvider {
122-
// listOf("-Didea.kotlin.plugin.use.k2=true")
123-
// }
124-
//}
114+
val runWithK2Mode by intellijPlatformTesting.runIde.registering {
115+
task {
116+
jvmArgs = listOf("-Didea.kotlin.plugin.use.k2=true")
117+
}
118+
}
125119

126120
intellijPlatform {
127121
buildSearchableOptions = false
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.kotest.plugin.intellij.psi
2+
3+
import org.jetbrains.kotlin.analysis.api.analyze
4+
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
5+
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
6+
import org.jetbrains.kotlin.analysis.api.types.symbol
7+
import org.jetbrains.kotlin.name.FqName
8+
import org.jetbrains.kotlin.name.StandardClassIds
9+
import org.jetbrains.kotlin.psi.KtClassOrObject
10+
11+
/**
12+
* Recursively returns the list of classes and interfaces extended or implemented by the class.
13+
*/
14+
@OptIn(KaAllowAnalysisOnEdt::class)
15+
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
16+
return superTypeListEntries.mapNotNull { it.typeReference }
17+
.flatMap { ref ->
18+
// SurroundSelectionWithFunctionIntention.isAvailable is called in EDT before the intention is applied
19+
// unfortunately API to avoid this was introduced in 23.2 only
20+
// this we need to move intentions to the facade or accept EDT here until 23.2- are still supported
21+
allowAnalysisOnEdt {
22+
analyze(this) {
23+
val kaType = ref.type
24+
val superTypes = (kaType.allSupertypes(false) + kaType).toList()
25+
superTypes.mapNotNull {
26+
val classId = it.symbol?.classId?.takeIf { id -> id != StandardClassIds.Any }
27+
classId?.asSingleFqName()
28+
}
29+
}
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)