diff --git a/src/main/kotlin/io/kotest/plugin/intellij/KotestTestFinder.kt b/src/main/kotlin/io/kotest/plugin/intellij/KotestTestFinder.kt index 28a0f42..0f304a6 100644 --- a/src/main/kotlin/io/kotest/plugin/intellij/KotestTestFinder.kt +++ b/src/main/kotlin/io/kotest/plugin/intellij/KotestTestFinder.kt @@ -38,8 +38,8 @@ class KotestTestFinder : TestFinder { } /** - * This is used by the navivation menu to determine if it should show "navigate to tests" or - * "nagivate to test subjects". Depending on the response, [findClassesForTest] or + * This is used by the navigation menu to determine if it should show "navigate to tests" or + * "navigate to test subjects". Depending on the response, [findClassesForTest] or * [findTestsForClass] will be called. */ override fun isTest(element: PsiElement): Boolean = element.isContainedInSpec() diff --git a/src/main/kotlin/io/kotest/plugin/intellij/psi/offsets.kt b/src/main/kotlin/io/kotest/plugin/intellij/psi/offsets.kt index 98fcd72..e0c85a3 100644 --- a/src/main/kotlin/io/kotest/plugin/intellij/psi/offsets.kt +++ b/src/main/kotlin/io/kotest/plugin/intellij/psi/offsets.kt @@ -4,6 +4,7 @@ import com.intellij.execution.PsiLocation import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile +import com.intellij.psi.util.PsiUtilCore /** * Returns the offsets for the given line in this file, or -1 if the document cannot be loaded for this file. @@ -21,14 +22,13 @@ fun PsiFile.offsetForLine(line: Int): IntRange? { /** * Finds the first [PsiElement] for the given offset range by iterating over - * the values in the range until an element is found. + * the values in the range until an element that is not a whitespace is found. */ fun PsiElement.findElementInRange(offsets: IntRange): PsiElement? { return offsets.asSequence() - .mapNotNull { findElementAt(it) } + .mapNotNull { offset -> findElementAt(offset)?.takeIf { it.text?.isNotBlank() == true } } .firstOrNull() } - /** * Returns the first element for the given line in this file, * or null if the document cannot be loaded for this file. diff --git a/src/test/kotlin/io/kotest/plugin/intellij/psi/OffsetsTest.kt b/src/test/kotlin/io/kotest/plugin/intellij/psi/OffsetsTest.kt index 5787a04..0b7df65 100644 --- a/src/test/kotlin/io/kotest/plugin/intellij/psi/OffsetsTest.kt +++ b/src/test/kotlin/io/kotest/plugin/intellij/psi/OffsetsTest.kt @@ -29,8 +29,8 @@ class OffsetsTest : LightJavaCodeInsightFixtureTestCase() { val psiFile = myFixture.configureByFile("/funspec.kt") val element: PsiElement? = psiFile.elementAtLine(24) element.shouldNotBeNull() - element.node.shouldBeInstanceOf() - element.startOffset shouldBe 361 - element.endOffset shouldBe 369 + element.node.shouldBeInstanceOf() + element.startOffset shouldBe 369 + element.endOffset shouldBe 373 } } 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 6dd56a4..99df69b 100644 --- a/src/test/kotlin/io/kotest/plugin/intellij/psi/SpecTests.kt +++ b/src/test/kotlin/io/kotest/plugin/intellij/psi/SpecTests.kt @@ -16,45 +16,6 @@ class SpecTests : LightJavaCodeInsightFixtureTestCase() { return path.toString() } - fun testIsContainedInSpecFunSpec() { - - val psiFile = myFixture.configureByFiles( - "/funspec.kt", - "/io/kotest/core/spec/style/specs.kt" - ) - - psiFile[0].elementAtLine(3)!!.isContainedInSpec() shouldBe false - for (k in 10..40) { - psiFile[0].elementAtLine(k)!!.isContainedInSpec() shouldBe true - } - } - - fun testIsContainedInSpecStringSpec() { - - val psiFile = myFixture.configureByFiles( - "/stringspec.kt", - "/io/kotest/core/spec/style/specs.kt" - ) - - psiFile[0].elementAtLine(4)!!.isContainedInSpec() shouldBe false - for (k in 7..13) { - psiFile[0].elementAtLine(k)!!.isContainedInSpec() shouldBe true - } - } - - fun testIsContainedInSpecFreeSpec() { - - val psiFile = myFixture.configureByFiles( - "/freespec.kt", - "/io/kotest/core/spec/style/specs.kt" - ) - - psiFile[0].elementAtLine(4)!!.isContainedInSpec() shouldBe false - for (k in 7..21) { - psiFile[0].elementAtLine(k)!!.isContainedInSpec() shouldBe true - } - } - fun testasKtClassOrObjectOrNull() { val psiFile = myFixture.configureByFiles(