File tree Expand file tree Collapse file tree 5 files changed +30
-24
lines changed
IC-242/kotlin/io/kotest/plugin/intellij/psi
IC-243/kotlin/io/kotest/plugin/intellij/psi
IC-251/kotlin/io/kotest/plugin/intellij/psi
main/kotlin/io/kotest/plugin/intellij Expand file tree Collapse file tree 5 files changed +30
-24
lines changed Original file line number Diff line number Diff line change 1
1
package io.kotest.plugin.intellij.psi
2
2
3
- import com.intellij.openapi.application.runReadAction
4
3
import org.jetbrains.kotlin.analysis.api.analyze
5
4
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
5
+ import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
6
6
import org.jetbrains.kotlin.analysis.api.types.symbol
7
7
import org.jetbrains.kotlin.name.FqName
8
8
import org.jetbrains.kotlin.name.StandardClassIds
@@ -15,7 +15,10 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
15
15
fun KtClassOrObject.getAllSuperClasses (): List <FqName > {
16
16
return superTypeListEntries.mapNotNull { it.typeReference }
17
17
.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 {
19
22
analyze(this ) {
20
23
val kaType = ref.type
21
24
val superTypes = (kaType.allSupertypes(false ) + kaType).toList()
Original file line number Diff line number Diff line change @@ -15,12 +15,17 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
15
15
fun KtClassOrObject.getAllSuperClasses (): List <FqName > {
16
16
return superTypeListEntries.mapNotNull { it.typeReference }
17
17
.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
+ }
24
29
}
25
30
}
26
31
}
Original file line number Diff line number Diff line change @@ -15,12 +15,17 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
15
15
fun KtClassOrObject.getAllSuperClasses (): List <FqName > {
16
16
return superTypeListEntries.mapNotNull { it.typeReference }
17
17
.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
+ }
24
29
}
25
30
}
26
31
}
Original file line number Diff line number Diff line change 1
1
package io.kotest.plugin.intellij.intentions
2
2
3
3
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
4
- import com.intellij.openapi.application.ApplicationManager
5
4
import com.intellij.openapi.editor.Editor
6
5
import com.intellij.openapi.project.Project
7
6
import com.intellij.openapi.util.TextRange
@@ -16,9 +15,6 @@ import org.jetbrains.kotlin.resolve.ImportPath
16
15
abstract class SurroundSelectionWithFunctionIntention : PsiElementBaseIntentionAction () {
17
16
18
17
override fun isAvailable (project : Project , editor : Editor ? , element : PsiElement ): Boolean {
19
- if (ApplicationManager .getApplication().isDispatchThread) {
20
- return false
21
- }
22
18
return try {
23
19
editor?.selectionModel?.hasSelection() == true && element.isContainedInSpec()
24
20
} catch (e: Exception ) {
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ import com.intellij.ide.structureView.StructureViewExtension
5
5
import com.intellij.ide.structureView.StructureViewTreeElement
6
6
import com.intellij.ide.util.treeView.smartTree.TreeElement
7
7
import com.intellij.navigation.ItemPresentation
8
- import com.intellij.openapi.application.ApplicationManager
9
8
import com.intellij.openapi.editor.Editor
9
+ import com.intellij.openapi.project.DumbService
10
10
import com.intellij.psi.NavigatablePsiElement
11
11
import com.intellij.psi.PsiElement
12
12
import io.kotest.plugin.intellij.Test
@@ -25,14 +25,11 @@ class KotestStructureViewExtension : StructureViewExtension {
25
25
}
26
26
27
27
override fun getChildren (parent : PsiElement ): Array <StructureViewTreeElement > {
28
- if (ApplicationManager .getApplication().isDispatchThread) {
29
- return emptyArray()
30
- }
28
+ if (DumbService .isDumb(parent.project)) return emptyArray()
31
29
val ktClassOrObject = parent as ? KtClassOrObject ? : return emptyArray()
32
30
val spec = ktClassOrObject.specStyle() ? : return emptyArray()
33
31
val tests = spec.tests(parent, false )
34
- val children = tests.map { KotestTestStructureViewTreeElement (it) }
35
- return children.toTypedArray()
32
+ return tests.map { KotestTestStructureViewTreeElement (it) }.toTypedArray()
36
33
}
37
34
38
35
class KotestTestStructureViewTreeElement (private val testElement : TestElement ) : StructureViewTreeElement {
You can’t perform that action at this time.
0 commit comments