From ed053784424ce32ba07c0b5c9eddbd8aebb9622e Mon Sep 17 00:00:00 2001 From: Mikhail Pyltsin Date: Mon, 14 Jul 2025 13:45:18 +0200 Subject: [PATCH] [command-completion] IJ-CR-168715 KTIJ-34835 Command completion. Kotlin. Impossible to rename parameters - more tests GitOrigin-RevId: e910003bc2b4cbeccc9dc9f55dd3a0c4d1472ae4 --- .../fir/completion/K2CommandCompletionTest.kt | 70 ++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/plugins/kotlin/fir/tests/test/org/jetbrains/kotlin/idea/fir/completion/K2CommandCompletionTest.kt b/plugins/kotlin/fir/tests/test/org/jetbrains/kotlin/idea/fir/completion/K2CommandCompletionTest.kt index e61f841c1694..a307dda18f94 100644 --- a/plugins/kotlin/fir/tests/test/org/jetbrains/kotlin/idea/fir/completion/K2CommandCompletionTest.kt +++ b/plugins/kotlin/fir/tests/test/org/jetbrains/kotlin/idea/fir/completion/K2CommandCompletionTest.kt @@ -93,7 +93,11 @@ class K2CommandCompletionTest : KotlinLightCodeInsightFixtureTestCase() { myFixture.doHighlighting() myFixture.type(".") val elements = myFixture.completeBasic() - assertNotNull(elements.firstOrNull() { element -> element.lookupString.contains("rename", ignoreCase = true) }) + val lookupElement = elements + .firstOrNull { element -> element.lookupString.contains("rename", ignoreCase = true) } + ?.`as`(CommandCompletionLookupElement::class.java) + assertNotNull(lookupElement) + assertEquals(TextRange(19, 22), (lookupElement as CommandCompletionLookupElement).highlighting?.range) } fun testRenameMethod2() { @@ -109,7 +113,69 @@ class K2CommandCompletionTest : KotlinLightCodeInsightFixtureTestCase() { myFixture.doHighlighting() myFixture.type(".") val elements = myFixture.completeBasic() - assertNotNull(elements.firstOrNull() { element -> element.lookupString.contains("rename", ignoreCase = true) }) + val lookupElement = elements + .firstOrNull { element -> element.lookupString.contains("rename", ignoreCase = true) } + ?.`as`(CommandCompletionLookupElement::class.java) + assertNotNull(lookupElement) + assertEquals(TextRange(19, 22), (lookupElement as CommandCompletionLookupElement).highlighting?.range) + } + + fun testRenameMethod3() { + Registry.get("ide.completion.command.force.enabled").setValue(true, getTestRootDisposable()) + myFixture.configureByText( + "x.kt", """ + class A { + fun foo() { + } + } + """.trimIndent() + ) + myFixture.doHighlighting() + myFixture.type(".") + val elements = myFixture.completeBasic() + val lookupElement = elements + .firstOrNull { element -> element.lookupString.contains("rename", ignoreCase = true) } + ?.`as`(CommandCompletionLookupElement::class.java) + assertNotNull(lookupElement) + assertEquals(TextRange(19, 22), (lookupElement as CommandCompletionLookupElement).highlighting?.range) + } + + fun testRenameMethod4() { + Registry.get("ide.completion.command.force.enabled").setValue(true, getTestRootDisposable()) + myFixture.configureByText( + "x.kt", """ + class A { + fun foo(): String = "1" + } + """.trimIndent() + ) + myFixture.doHighlighting() + myFixture.type(".") + val elements = myFixture.completeBasic() + val lookupElement = elements + .firstOrNull { element -> element.lookupString.contains("rename", ignoreCase = true) } + ?.`as`(CommandCompletionLookupElement::class.java) + assertNotNull(lookupElement) + assertEquals(TextRange(19, 22), (lookupElement as CommandCompletionLookupElement).highlighting?.range) + } + + fun testRenameMethod5() { + Registry.get("ide.completion.command.force.enabled").setValue(true, getTestRootDisposable()) + myFixture.configureByText( + "x.kt", """ + class A { + fun foo() : String = "1" + } + """.trimIndent() + ) + myFixture.doHighlighting() + myFixture.type(".") + val elements = myFixture.completeBasic() + val lookupElement = elements + .firstOrNull { element -> element.lookupString.contains("rename", ignoreCase = true) } + ?.`as`(CommandCompletionLookupElement::class.java) + assertNotNull(lookupElement) + assertEquals(TextRange(19, 22), (lookupElement as CommandCompletionLookupElement).highlighting?.range) } fun testRenameClass() {