From a84b767eaf6e73db7877b4cd35ad80ed9cee013d Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 7 Nov 2024 17:26:37 +0100 Subject: [PATCH] K2 plugin migration (#321) --- .github/workflows/master.yml | 5 +- .github/workflows/pr.yml | 5 +- .github/workflows/release.yml | 5 +- build.gradle.kts | 17 +++-- gradle.properties | 2 + gradle/libs.versions.toml | 2 +- .../kotlin/io/kotest/plugin/intellij/files.kt | 33 --------- .../plugin/intellij/psi/superClasses.kt | 36 ++++++++++ .../plugin/intellij/psi/superClasses.kt | 36 ++++++++++ .../plugin/intellij/psi/superClasses.kt | 36 ++++++++++ .../plugin/intellij/psi/superClasses.kt | 36 ++++++++++ .../plugin/intellij/psi/superClasses.kt | 32 +++++++++ .../plugin/intellij/psi/superClasses.kt | 32 +++++++++ .../io/kotest/plugin/intellij/psi/classes.kt | 32 --------- .../toolwindow/KotestTestExplorerService.kt | 1 - src/main/resources/META-INF/plugin.xml | 4 ++ .../kotest/plugin/intellij/CallbacksTest.kt | 54 ++++++++------ .../kotest/plugin/intellij/psi/ClassTests.kt | 3 +- .../kotest/plugin/intellij/psi/SpecTests.kt | 71 ++++++++++--------- .../plugin/intellij/styles/TreeModelTest.kt | 52 ++++++++------ 20 files changed, 328 insertions(+), 166 deletions(-) delete mode 100644 src/IC-223/kotlin/io/kotest/plugin/intellij/files.kt create mode 100644 src/IC-231/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt create mode 100644 src/IC-232/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt create mode 100644 src/IC-233/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt create mode 100644 src/IC-241/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt create mode 100644 src/IC-242/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt create mode 100644 src/IC-243/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index db978341..2acb6a2b 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -14,11 +14,8 @@ jobs: strategy: matrix: - product: [ "IC-223", "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ] + product: [ "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ] include: - - product: "IC-223" - java: "17" - distribution: "temurin" - product: "IC-231" java: "17" distribution: "temurin" diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 80ec70a3..a1344c35 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -12,11 +12,8 @@ jobs: strategy: matrix: - product: [ "IC-223", "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ] + product: [ "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ] include: - - product: "IC-223" - java: "17" - distribution: "temurin" - product: "IC-231" java: "17" distribution: "temurin" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f017a0c7..509648c5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,11 +8,8 @@ jobs: strategy: matrix: - product: [ "IC-223", "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ] + product: [ "IC-231", "IC-232", "IC-233", "IC-241", "IC-242", "IC-243" ] include: - - product: "IC-223" - java: "17" - distribution: "temurin" - product: "IC-231" java: "17" distribution: "temurin" diff --git a/build.gradle.kts b/build.gradle.kts index c6d548ca..6258ad49 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,13 +45,6 @@ data class PluginDescriptor( // and 'until' we can use a wildcard eg 213.* val descriptors = listOf( - PluginDescriptor( - since = "223.4884.69", // this version is 2022.3 - until = "223.*", - sdkVersion = "2022.3", - sourceFolder = "IC-223", - useInstaller = true, - ), PluginDescriptor( since = "231.8109.163", // this version is 2023.1 release until = "231.*", @@ -83,7 +76,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, ), @@ -111,6 +104,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 @@ -165,7 +164,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") diff --git a/gradle.properties b/gradle.properties index b571e4f7..f9f6c6b9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,3 +6,5 @@ version=1.1.0 org.gradle.caching=true sandbox = /tmp/ + +kotlin.stdlib.default.dependency = false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 550808d1..d3956899 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -kotlin = "1.9.25" +kotlin = "2.0.21" runtime-kotest = "4.2.0" # We separate these from the actual runtime dependencies test-kotest = "5.9.1" diff --git a/src/IC-223/kotlin/io/kotest/plugin/intellij/files.kt b/src/IC-223/kotlin/io/kotest/plugin/intellij/files.kt deleted file mode 100644 index 3f047009..00000000 --- a/src/IC-223/kotlin/io/kotest/plugin/intellij/files.kt +++ /dev/null @@ -1,33 +0,0 @@ -package io.kotest.plugin.intellij - -import com.intellij.execution.PsiLocation -import com.intellij.openapi.project.Project -import com.intellij.openapi.vfs.VirtualFile -import com.intellij.psi.PsiElement -import com.intellij.psi.search.FilenameIndex -import com.intellij.psi.search.GlobalSearchScope -import io.kotest.plugin.intellij.psi.elementAtLine -import io.kotest.plugin.intellij.psi.isTestFile -import io.kotest.plugin.intellij.psi.toPsiLocation -import io.kotest.plugin.intellij.toolwindow.TagsFilename -import org.jetbrains.kotlin.idea.core.util.toPsiFile - -fun findFiles(project: Project): List { - return FilenameIndex - .getVirtualFilesByName(TagsFilename, false, GlobalSearchScope.allScope(project)) - .toList() -} - -fun getLocationForFile( - project: Project, - scope: GlobalSearchScope, - name: String, - lineNumber: Int -): PsiLocation? { - return FilenameIndex - .getVirtualFilesByName(name, scope) - .firstOrNull { it.isTestFile(project) } - ?.toPsiFile(project) - ?.elementAtLine(lineNumber) - ?.toPsiLocation() -} diff --git a/src/IC-231/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt b/src/IC-231/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt new file mode 100644 index 00000000..a15ccab5 --- /dev/null +++ b/src/IC-231/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt @@ -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 { + 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" } +} diff --git a/src/IC-232/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt b/src/IC-232/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt new file mode 100644 index 00000000..a15ccab5 --- /dev/null +++ b/src/IC-232/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt @@ -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 { + 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" } +} diff --git a/src/IC-233/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt b/src/IC-233/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt new file mode 100644 index 00000000..a15ccab5 --- /dev/null +++ b/src/IC-233/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt @@ -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 { + 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" } +} diff --git a/src/IC-241/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt b/src/IC-241/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt new file mode 100644 index 00000000..a15ccab5 --- /dev/null +++ b/src/IC-241/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt @@ -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 { + 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" } +} diff --git a/src/IC-242/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt b/src/IC-242/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt new file mode 100644 index 00000000..e05bc35f --- /dev/null +++ b/src/IC-242/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt @@ -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 { + 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() + } + } + } + } +} diff --git a/src/IC-243/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt b/src/IC-243/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt new file mode 100644 index 00000000..e05bc35f --- /dev/null +++ b/src/IC-243/kotlin/io/kotest/plugin/intellij/psi/superClasses.kt @@ -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 { + 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() + } + } + } + } +} diff --git a/src/main/kotlin/io/kotest/plugin/intellij/psi/classes.kt b/src/main/kotlin/io/kotest/plugin/intellij/psi/classes.kt index eb17960e..d12e2c95 100644 --- a/src/main/kotlin/io/kotest/plugin/intellij/psi/classes.kt +++ b/src/main/kotlin/io/kotest/plugin/intellij/psi/classes.kt @@ -4,7 +4,6 @@ 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 @@ -12,9 +11,6 @@ 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. @@ -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 { - 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. */ diff --git a/src/main/kotlin/io/kotest/plugin/intellij/toolwindow/KotestTestExplorerService.kt b/src/main/kotlin/io/kotest/plugin/intellij/toolwindow/KotestTestExplorerService.kt index fd86c276..11d07ede 100644 --- a/src/main/kotlin/io/kotest/plugin/intellij/toolwindow/KotestTestExplorerService.kt +++ b/src/main/kotlin/io/kotest/plugin/intellij/toolwindow/KotestTestExplorerService.kt @@ -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 diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index e3661f07..0d2d7945 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -111,4 +111,8 @@ + + + + diff --git a/src/test/kotlin/io/kotest/plugin/intellij/CallbacksTest.kt b/src/test/kotlin/io/kotest/plugin/intellij/CallbacksTest.kt index b1e0d599..e01926c1 100644 --- a/src/test/kotlin/io/kotest/plugin/intellij/CallbacksTest.kt +++ b/src/test/kotlin/io/kotest/plugin/intellij/CallbacksTest.kt @@ -1,5 +1,7 @@ package io.kotest.plugin.intellij +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.runReadAction import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.shouldBe @@ -16,6 +18,10 @@ class CallbacksTest : LightJavaCodeInsightFixtureTestCase() { return path.toString() } + override fun runInDispatchThread(): Boolean { + return false + } + fun testCallbacks() { val psiFile = myFixture.configureByFiles( @@ -23,39 +29,41 @@ class CallbacksTest : LightJavaCodeInsightFixtureTestCase() { "/io/kotest/core/spec/style/specs.kt" )[0] - val ktclass = psiFile.specs()[0] - val callbacks = ktclass.callbacks() + ApplicationManager.getApplication().runReadAction { + val ktclass = psiFile.specs()[0] + val callbacks = ktclass.callbacks() - callbacks.shouldHaveSize(10) + callbacks.shouldHaveSize(10) - callbacks[0].psi.startOffset shouldBe 115 - callbacks[0].type shouldBe CallbackType.BeforeTest + callbacks[0].psi.startOffset shouldBe 115 + callbacks[0].type shouldBe CallbackType.BeforeTest - callbacks[1].psi.startOffset shouldBe 138 - callbacks[1].type shouldBe CallbackType.AfterTest + callbacks[1].psi.startOffset shouldBe 138 + callbacks[1].type shouldBe CallbackType.AfterTest - callbacks[2].psi.startOffset shouldBe 160 - callbacks[2].type shouldBe CallbackType.BeforeSpec + callbacks[2].psi.startOffset shouldBe 160 + callbacks[2].type shouldBe CallbackType.BeforeSpec - callbacks[3].psi.startOffset shouldBe 183 - callbacks[3].type shouldBe CallbackType.AfterSpec + callbacks[3].psi.startOffset shouldBe 183 + callbacks[3].type shouldBe CallbackType.AfterSpec - callbacks[4].psi.startOffset shouldBe 225 - callbacks[4].type shouldBe CallbackType.AfterEach + callbacks[4].psi.startOffset shouldBe 225 + callbacks[4].type shouldBe CallbackType.AfterEach - callbacks[5].psi.startOffset shouldBe 243 - callbacks[5].type shouldBe CallbackType.BeforeEach + callbacks[5].psi.startOffset shouldBe 243 + callbacks[5].type shouldBe CallbackType.BeforeEach - callbacks[6].psi.startOffset shouldBe 261 - callbacks[6].type shouldBe CallbackType.AfterContainer + callbacks[6].psi.startOffset shouldBe 261 + callbacks[6].type shouldBe CallbackType.AfterContainer - callbacks[7].psi.startOffset shouldBe 288 - callbacks[7].type shouldBe CallbackType.BeforeContainer + callbacks[7].psi.startOffset shouldBe 288 + callbacks[7].type shouldBe CallbackType.BeforeContainer - callbacks[8].psi.startOffset shouldBe 311 - callbacks[8].type shouldBe CallbackType.BeforeAny + callbacks[8].psi.startOffset shouldBe 311 + callbacks[8].type shouldBe CallbackType.BeforeAny - callbacks[9].psi.startOffset shouldBe 328 - callbacks[9].type shouldBe CallbackType.AfterAny + callbacks[9].psi.startOffset shouldBe 328 + callbacks[9].type shouldBe CallbackType.AfterAny + } } } diff --git a/src/test/kotlin/io/kotest/plugin/intellij/psi/ClassTests.kt b/src/test/kotlin/io/kotest/plugin/intellij/psi/ClassTests.kt index d5a96056..8469d844 100644 --- a/src/test/kotlin/io/kotest/plugin/intellij/psi/ClassTests.kt +++ b/src/test/kotlin/io/kotest/plugin/intellij/psi/ClassTests.kt @@ -1,5 +1,6 @@ package io.kotest.plugin.intellij.psi +import com.intellij.openapi.actionSystem.ex.ActionUtil import com.intellij.openapi.projectRoots.Sdk import com.intellij.pom.java.LanguageLevel import com.intellij.testFramework.IdeaTestUtil @@ -52,7 +53,7 @@ class ClassTests : LightJavaCodeInsightFixtureTestCase() { "/io/kotest/plugin/intellij/abstractspec.kt", "/io/kotest/core/spec/style/specs.kt" )[0] - val supers = psiFile.elementAtLine(11)?.enclosingKtClass()!!.getAllSuperClasses().map { it.asString() } + val supers = ActionUtil.underModalProgress(myFixture.project, "") { psiFile.elementAtLine(11)?.enclosingKtClass()!!.getAllSuperClasses().map { it.asString() } } // the order varies depending on the intellij version, so using set to compare supers.toSet() shouldBe setOf("io.kotest.plugin.intellij.MyParentSpec", "io.kotest.core.spec.style.FunSpec") } diff --git a/src/test/kotlin/io/kotest/plugin/intellij/psi/SpecTests.kt b/src/test/kotlin/io/kotest/plugin/intellij/psi/SpecTests.kt index 99df69bd..1063e85e 100644 --- a/src/test/kotlin/io/kotest/plugin/intellij/psi/SpecTests.kt +++ b/src/test/kotlin/io/kotest/plugin/intellij/psi/SpecTests.kt @@ -1,5 +1,6 @@ package io.kotest.plugin.intellij.psi +import com.intellij.openapi.application.ApplicationManager import com.intellij.psi.impl.source.tree.LeafPsiElement import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase @@ -16,6 +17,10 @@ class SpecTests : LightJavaCodeInsightFixtureTestCase() { return path.toString() } + override fun runInDispatchThread(): Boolean { + return false + } + fun testasKtClassOrObjectOrNull() { val psiFile = myFixture.configureByFiles( @@ -23,37 +28,39 @@ class SpecTests : LightJavaCodeInsightFixtureTestCase() { "/io/kotest/core/spec/style/specs.kt" ) - (psiFile[0].findElementAt(626) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec1" - (psiFile[0].findElementAt(657) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec2" - (psiFile[0].findElementAt(693) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec3" - (psiFile[0].findElementAt(717) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec4" - (psiFile[0].findElementAt(743) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec5" - (psiFile[0].findElementAt(773) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec6" - (psiFile[0].findElementAt(803) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec7" - (psiFile[0].findElementAt(826) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec8" - (psiFile[0].findElementAt(852) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec9" - (psiFile[0].findElementAt(879) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec10" - (psiFile[0].findElementAt(909) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec11" - (psiFile[0].findElementAt(947) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec12" - (psiFile[0].findElementAt(975) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString().shouldBeNull() - (psiFile[0].findElementAt(1007) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString().shouldBeNull() - (psiFile[0].findElementAt(1035) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString().shouldBeNull() - (psiFile[0].findElementAt(1060) as LeafPsiElement).asKtClassOrObjectOrNull() - ?.takeIfRunnableSpec()?.fqName?.asString().shouldBeNull() + ApplicationManager.getApplication().runReadAction { + (psiFile[0].findElementAt(626) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec1" + (psiFile[0].findElementAt(657) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec2" + (psiFile[0].findElementAt(693) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec3" + (psiFile[0].findElementAt(717) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec4" + (psiFile[0].findElementAt(743) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec5" + (psiFile[0].findElementAt(773) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec6" + (psiFile[0].findElementAt(803) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec7" + (psiFile[0].findElementAt(826) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec8" + (psiFile[0].findElementAt(852) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec9" + (psiFile[0].findElementAt(879) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec10" + (psiFile[0].findElementAt(909) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec11" + (psiFile[0].findElementAt(947) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString() shouldBe "io.kotest.plugin.intellij.Spec12" + (psiFile[0].findElementAt(975) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString().shouldBeNull() + (psiFile[0].findElementAt(1007) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString().shouldBeNull() + (psiFile[0].findElementAt(1035) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString().shouldBeNull() + (psiFile[0].findElementAt(1060) as LeafPsiElement).asKtClassOrObjectOrNull() + ?.takeIfRunnableSpec()?.fqName?.asString().shouldBeNull() + } } } diff --git a/src/test/kotlin/io/kotest/plugin/intellij/styles/TreeModelTest.kt b/src/test/kotlin/io/kotest/plugin/intellij/styles/TreeModelTest.kt index 2101312c..389cba7b 100644 --- a/src/test/kotlin/io/kotest/plugin/intellij/styles/TreeModelTest.kt +++ b/src/test/kotlin/io/kotest/plugin/intellij/styles/TreeModelTest.kt @@ -1,5 +1,7 @@ package io.kotest.plugin.intellij.styles +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.runReadAction import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase import io.kotest.matchers.shouldBe @@ -28,6 +30,10 @@ class TreeModelTest : LightJavaCodeInsightFixtureTestCase() { return path.toString() } + override fun runInDispatchThread(): Boolean { + return false + } + fun testGutterIcons() { myFixture.configureByFiles( @@ -35,34 +41,36 @@ class TreeModelTest : LightJavaCodeInsightFixtureTestCase() { "/io/kotest/core/spec/style/specs.kt" ) - val model = - createTreeModel(myFixture.file.virtualFile, myFixture.project, myFixture.file.specs(), myFixture.module) + ApplicationManager.getApplication().runReadAction { + val model = + createTreeModel(myFixture.file.virtualFile, myFixture.project, myFixture.file.specs(), myFixture.module) - val root = model.root as DefaultMutableTreeNode - val kotest = root.userObject as KotestRootNodeDescriptor - kotest.presentation.presentableText shouldBe Constants().FrameworkName + val root = model.root as DefaultMutableTreeNode + val kotest = root.userObject as KotestRootNodeDescriptor + kotest.presentation.presentableText shouldBe Constants().FrameworkName - val children = root.children().toList() as List - children.size shouldBe 3 - children[0].userObject.shouldBeInstanceOf() + val children = root.children().toList() as List + children.size shouldBe 3 + children[0].userObject.shouldBeInstanceOf() - children[1].userObject.shouldBeInstanceOf() + children[1].userObject.shouldBeInstanceOf() - val testfile = children[2] - testfile.userObject.shouldBeInstanceOf() + val testfile = children[2] + testfile.userObject.shouldBeInstanceOf() - val specs = testfile.children().toList() as List - specs.size shouldBe 1 - val spec = specs[0] - spec.userObject.shouldBeInstanceOf() + val specs = testfile.children().toList() as List + specs.size shouldBe 1 + val spec = specs[0] + spec.userObject.shouldBeInstanceOf() - val elements = spec.children().toList() as List - elements.size shouldBe 5 + val elements = spec.children().toList() as List + elements.size shouldBe 5 - (elements[0].userObject as CallbackNodeDescriptor).presentation.presentableText shouldBe "beforeTest" - (elements[1].userObject as CallbackNodeDescriptor).presentation.presentableText shouldBe "afterTest" - (elements[2].userObject as IncludeNodeDescriptor).presentation.presentableText shouldBe "Include: myfactory" - (elements[3].userObject as IncludeNodeDescriptor).presentation.presentableText shouldBe "Include: myfactory2" - (elements[4].userObject as TestNodeDescriptor).presentation.presentableText shouldBe "a string cannot be blank" + (elements[0].userObject as CallbackNodeDescriptor).presentation.presentableText shouldBe "beforeTest" + (elements[1].userObject as CallbackNodeDescriptor).presentation.presentableText shouldBe "afterTest" + (elements[2].userObject as IncludeNodeDescriptor).presentation.presentableText shouldBe "Include: myfactory" + (elements[3].userObject as IncludeNodeDescriptor).presentation.presentableText shouldBe "Include: myfactory2" + (elements[4].userObject as TestNodeDescriptor).presentation.presentableText shouldBe "a string cannot be blank" + } } }