Skip to content

Commit e14c67b

Browse files
committed
Revert "Fix ProhibitedAnalysisException in KotestStructureViewExtension"
This reverts commit 81bd846.
1 parent 81bd846 commit e14c67b

File tree

5 files changed

+30
-24
lines changed

5 files changed

+30
-24
lines changed

src/IC-242/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package io.kotest.plugin.intellij.psi
22

3-
import com.intellij.openapi.application.runReadAction
43
import org.jetbrains.kotlin.analysis.api.analyze
54
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
5+
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
66
import org.jetbrains.kotlin.analysis.api.types.symbol
77
import org.jetbrains.kotlin.name.FqName
88
import org.jetbrains.kotlin.name.StandardClassIds
@@ -15,7 +15,10 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
1515
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
1616
return superTypeListEntries.mapNotNull { it.typeReference }
1717
.flatMap { ref ->
18-
runReadAction {
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 {
1922
analyze(this) {
2023
val kaType = ref.type
2124
val superTypes = (kaType.allSupertypes(false) + kaType).toList()

src/IC-243/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
1515
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
1616
return superTypeListEntries.mapNotNull { it.typeReference }
1717
.flatMap { ref ->
18-
analyze(this) {
19-
val kaType = ref.type
20-
val superTypes = (kaType.allSupertypes(false) + kaType).toList()
21-
superTypes.mapNotNull {
22-
val classId = it.symbol?.classId?.takeIf { id -> id != StandardClassIds.Any }
23-
classId?.asSingleFqName()
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+
}
2429
}
2530
}
2631
}

src/IC-251/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
1515
fun KtClassOrObject.getAllSuperClasses(): List<FqName> {
1616
return superTypeListEntries.mapNotNull { it.typeReference }
1717
.flatMap { ref ->
18-
analyze(this) {
19-
val kaType = ref.type
20-
val superTypes = (kaType.allSupertypes(false) + kaType).toList()
21-
superTypes.mapNotNull {
22-
val classId = it.symbol?.classId?.takeIf { id -> id != StandardClassIds.Any }
23-
classId?.asSingleFqName()
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+
}
2429
}
2530
}
2631
}

src/main/kotlin/io/kotest/plugin/intellij/intentions/SurroundSelectionWithFunctionIntention.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.kotest.plugin.intellij.intentions
22

33
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
4-
import com.intellij.openapi.application.ApplicationManager
54
import com.intellij.openapi.editor.Editor
65
import com.intellij.openapi.project.Project
76
import com.intellij.openapi.util.TextRange
@@ -16,9 +15,6 @@ import org.jetbrains.kotlin.resolve.ImportPath
1615
abstract class SurroundSelectionWithFunctionIntention : PsiElementBaseIntentionAction() {
1716

1817
override fun isAvailable(project: Project, editor: Editor?, element: PsiElement): Boolean {
19-
if (ApplicationManager.getApplication().isDispatchThread) {
20-
return false
21-
}
2218
return try {
2319
editor?.selectionModel?.hasSelection() == true && element.isContainedInSpec()
2420
} catch (e: Exception) {

src/main/kotlin/io/kotest/plugin/intellij/structure/KotestStructureViewExtension.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import com.intellij.ide.structureView.StructureViewExtension
55
import com.intellij.ide.structureView.StructureViewTreeElement
66
import com.intellij.ide.util.treeView.smartTree.TreeElement
77
import com.intellij.navigation.ItemPresentation
8-
import com.intellij.openapi.application.ApplicationManager
98
import com.intellij.openapi.editor.Editor
9+
import com.intellij.openapi.project.DumbService
1010
import com.intellij.psi.NavigatablePsiElement
1111
import com.intellij.psi.PsiElement
1212
import io.kotest.plugin.intellij.Test
@@ -25,14 +25,11 @@ class KotestStructureViewExtension : StructureViewExtension {
2525
}
2626

2727
override fun getChildren(parent: PsiElement): Array<StructureViewTreeElement> {
28-
if (ApplicationManager.getApplication().isDispatchThread) {
29-
return emptyArray()
30-
}
28+
if (DumbService.isDumb(parent.project)) return emptyArray()
3129
val ktClassOrObject = parent as? KtClassOrObject ?: return emptyArray()
3230
val spec = ktClassOrObject.specStyle() ?: return emptyArray()
3331
val tests = spec.tests(parent, false)
34-
val children = tests.map { KotestTestStructureViewTreeElement(it) }
35-
return children.toTypedArray()
32+
return tests.map { KotestTestStructureViewTreeElement(it) }.toTypedArray()
3633
}
3734

3835
class KotestTestStructureViewTreeElement(private val testElement: TestElement) : StructureViewTreeElement {

0 commit comments

Comments
 (0)