From d075e210a353efc662e4c5a2c6c2e667debc266d Mon Sep 17 00:00:00 2001 From: Frederik Haselmeier Date: Mon, 10 Nov 2025 17:13:00 +0100 Subject: [PATCH] [kotlin] KTIJ-36297 always use expensive renderers in completion handler tests Expensive renderers are used by the Kotlin plugin during completion to calculate expensive entities like shorten commands only on demand. Without using expensive expensive renderers, the tests do not truly reflect what will happen in real IDEA instances. GitOrigin-RevId: 416400de53757f27897464471af1af1e24da1313 --- .../ClassCompletionImportBeforeIfInReturn.kt | 1 - .../ClassCompletionImportBeforeIfInReturn.kt.after | 1 - .../handlers/ClassCompletionImportWithoutPrefix.kt | 3 +-- .../ClassCompletionImportWithoutPrefix.kt.after | 3 +-- .../handlers/AbstractCompletionHandlerTests.kt | 2 -- .../test/handlers/CompletionHandlerTestBase.kt | 14 +++++--------- .../AbstractPerformanceCompletionHandlerTests.kt | 9 +++------ 7 files changed, 10 insertions(+), 23 deletions(-) diff --git a/plugins/kotlin/completion/testData/handlers/ClassCompletionImportBeforeIfInReturn.kt b/plugins/kotlin/completion/testData/handlers/ClassCompletionImportBeforeIfInReturn.kt index 7768580b02c3..ad97b10b3f3d 100644 --- a/plugins/kotlin/completion/testData/handlers/ClassCompletionImportBeforeIfInReturn.kt +++ b/plugins/kotlin/completion/testData/handlers/ClassCompletionImportBeforeIfInReturn.kt @@ -5,4 +5,3 @@ fun test(): Int? { } // ELEMENT: SortedSet -// USE_EXPENSIVE_RENDERER diff --git a/plugins/kotlin/completion/testData/handlers/ClassCompletionImportBeforeIfInReturn.kt.after b/plugins/kotlin/completion/testData/handlers/ClassCompletionImportBeforeIfInReturn.kt.after index c9e53a2bdd16..c2c3dfbd1d0c 100644 --- a/plugins/kotlin/completion/testData/handlers/ClassCompletionImportBeforeIfInReturn.kt.after +++ b/plugins/kotlin/completion/testData/handlers/ClassCompletionImportBeforeIfInReturn.kt.after @@ -7,4 +7,3 @@ fun test(): Int? { } // ELEMENT: SortedSet -// USE_EXPENSIVE_RENDERER diff --git a/plugins/kotlin/completion/testData/handlers/ClassCompletionImportWithoutPrefix.kt b/plugins/kotlin/completion/testData/handlers/ClassCompletionImportWithoutPrefix.kt index ce0fa0895493..2ee27d0e7dfc 100644 --- a/plugins/kotlin/completion/testData/handlers/ClassCompletionImportWithoutPrefix.kt +++ b/plugins/kotlin/completion/testData/handlers/ClassCompletionImportWithoutPrefix.kt @@ -4,5 +4,4 @@ val test : -// ELEMENT: Int -// USE_EXPENSIVE_RENDERER \ No newline at end of file +// ELEMENT: Int \ No newline at end of file diff --git a/plugins/kotlin/completion/testData/handlers/ClassCompletionImportWithoutPrefix.kt.after b/plugins/kotlin/completion/testData/handlers/ClassCompletionImportWithoutPrefix.kt.after index dab8ff69c56b..60cf9f6bc989 100644 --- a/plugins/kotlin/completion/testData/handlers/ClassCompletionImportWithoutPrefix.kt.after +++ b/plugins/kotlin/completion/testData/handlers/ClassCompletionImportWithoutPrefix.kt.after @@ -4,5 +4,4 @@ val test : Int -// ELEMENT: Int -// USE_EXPENSIVE_RENDERER \ No newline at end of file +// ELEMENT: Int \ No newline at end of file diff --git a/plugins/kotlin/completion/tests-shared/test/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt b/plugins/kotlin/completion/tests-shared/test/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt index 5843a4e14983..e8877e0f3f9f 100644 --- a/plugins/kotlin/completion/tests-shared/test/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt +++ b/plugins/kotlin/completion/tests-shared/test/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt @@ -78,7 +78,6 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType: val lookupString = InTextDirectivesUtils.findStringWithPrefixes(fileText, LOOKUP_STRING_PREFIX) val itemText = InTextDirectivesUtils.findStringWithPrefixes(fileText, ELEMENT_TEXT_PREFIX) val tailText = InTextDirectivesUtils.findStringWithPrefixes(fileText, TAIL_TEXT_PREFIX) - val useExpensiveRenderer = InTextDirectivesUtils.isDirectiveDefined(fileText, USE_EXPENSIVE_RENDERER) val completionChars = completionChars(fileText) val typeAfterCompletion = InTextDirectivesUtils.findStringWithPrefixes(fileText, COMPLETION_TYPE_AFTER_COMPLETED_PREFIX) @@ -114,7 +113,6 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType: completionChars, testFile.name + ".after", typeAfterCompletion = typeAfterCompletion, - useExpensiveRenderer = useExpensiveRenderer ) } } diff --git a/plugins/kotlin/completion/tests-shared/test/org/jetbrains/kotlin/idea/completion/test/handlers/CompletionHandlerTestBase.kt b/plugins/kotlin/completion/tests-shared/test/org/jetbrains/kotlin/idea/completion/test/handlers/CompletionHandlerTestBase.kt index 099cde47141e..bb76c0220a31 100644 --- a/plugins/kotlin/completion/tests-shared/test/org/jetbrains/kotlin/idea/completion/test/handlers/CompletionHandlerTestBase.kt +++ b/plugins/kotlin/completion/tests-shared/test/org/jetbrains/kotlin/idea/completion/test/handlers/CompletionHandlerTestBase.kt @@ -27,7 +27,6 @@ abstract class CompletionHandlerTestBase : KotlinLightCodeInsightFixtureTestCase completionChars: String, afterFilePath: String, actions: List? = emptyList(), - useExpensiveRenderer: Boolean = false, typeAfterCompletion: String? = null, afterTypingBlock: () -> Unit = {} ) { @@ -50,7 +49,7 @@ abstract class CompletionHandlerTestBase : KotlinLightCodeInsightFixtureTestCase } if (lookupString != null || itemText != null || tailText != null) { - val item = getExistentLookupElement(fixture.project, lookupString, itemText, tailText, useExpensiveRenderer) + val item = getExistentLookupElement(fixture.project, lookupString, itemText, tailText) if (item != null) { selectItem(item, completionChars.last()) } @@ -82,7 +81,6 @@ abstract class CompletionHandlerTestBase : KotlinLightCodeInsightFixtureTestCase lookupString: String?, itemText: String?, tailText: String?, - useExpensiveRenderer: Boolean ): LookupElement? { val lookup = LookupManager.getInstance(project)?.activeLookup as LookupImpl? ?: return null val items = lookup.items @@ -101,12 +99,10 @@ abstract class CompletionHandlerTestBase : KotlinLightCodeInsightFixtureTestCase if (lookupOk) { lookupElement.renderElement(presentation) - if (useExpensiveRenderer) { - timeoutRunBlocking { - @Suppress("UNCHECKED_CAST") - (lookupElement.expensiveRenderer as? LookupElementRenderer) - ?.renderElement(lookupElement, presentation) - } + timeoutRunBlocking { + @Suppress("UNCHECKED_CAST") + (lookupElement.expensiveRenderer as? LookupElementRenderer) + ?.renderElement(lookupElement, presentation) } val textOk = if (itemText != null) { diff --git a/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/AbstractPerformanceCompletionHandlerTests.kt b/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/AbstractPerformanceCompletionHandlerTests.kt index 2d304ef83ff1..a27675b417c9 100644 --- a/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/AbstractPerformanceCompletionHandlerTests.kt +++ b/plugins/kotlin/performance-tests/test/org/jetbrains/kotlin/idea/perf/synthetic/AbstractPerformanceCompletionHandlerTests.kt @@ -75,7 +75,6 @@ abstract class AbstractPerformanceCompletionHandlerTests( val lookupString = InTextDirectivesUtils.findStringWithPrefixes(fileText, LOOKUP_STRING_PREFIX) val itemText = InTextDirectivesUtils.findStringWithPrefixes(fileText, ELEMENT_TEXT_PREFIX) val tailText = InTextDirectivesUtils.findStringWithPrefixes(fileText, TAIL_TEXT_PREFIX) - val useExpensiveRenderer = InTextDirectivesUtils.isDirectiveDefined(fileText, USE_EXPENSIVE_RENDERER) val completionChars = completionChars(fileText) val completionType = ExpectedCompletionUtils.getCompletionType(fileText) ?: defaultCompletionType @@ -101,7 +100,7 @@ abstract class AbstractPerformanceCompletionHandlerTests( doPerfTestWithTextLoaded( testPath, completionType, invocationCount, lookupString, - itemText, tailText, completionChars, useExpensiveRenderer + itemText, tailText, completionChars ) } } finally { @@ -118,7 +117,6 @@ abstract class AbstractPerformanceCompletionHandlerTests( itemText: String?, tailText: String?, completionChars: String, - useExpensiveRenderer: Boolean, ) { performanceTest { name(name()) @@ -127,7 +125,7 @@ abstract class AbstractPerformanceCompletionHandlerTests( setUpFixture(testPath) } test { - perfTestCore(completionType, time, lookupString, itemText, tailText, completionChars, useExpensiveRenderer) + perfTestCore(completionType, time, lookupString, itemText, tailText, completionChars) } tearDown { runWriteAction { @@ -154,7 +152,6 @@ abstract class AbstractPerformanceCompletionHandlerTests( itemText: String?, tailText: String?, completionChars: String, - useExpensiveRenderer: Boolean, ) { completionChars.let { for (idx in 0 until it.length - 1) { @@ -165,7 +162,7 @@ abstract class AbstractPerformanceCompletionHandlerTests( fixture.complete(completionType, time) if (lookupString != null || itemText != null || tailText != null) { - val item = getExistentLookupElement(project, lookupString, itemText, tailText, useExpensiveRenderer) + val item = getExistentLookupElement(project, lookupString, itemText, tailText) if (item != null) { selectItem(item, completionChars.last()) }