[kotlin] Fix types inlay hints

#KTIJ-28592 Fixed

GitOrigin-RevId: 4530af4e59e621d9feb8f1100cdb709a3ff1b0e1
This commit is contained in:
Vladimir Dolzhenko
2024-01-24 22:19:13 +00:00
committed by intellij-monorepo-bot
parent 3532216ff4
commit 963bb6ef53
77 changed files with 153 additions and 134 deletions
@@ -11,6 +11,10 @@ import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.annotations.Nls
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.safeAnalyze
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_FUNCTION_PARAMETER_TYPES
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_FUNCTION_RETURN_TYPES
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_LOCAL_VARIABLE_TYPES
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_PROPERTY_TYPES
import org.jetbrains.kotlin.idea.parameterInfo.*
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.getReturnTypeReference
import org.jetbrains.kotlin.idea.util.RangeKtExpressionType.*
@@ -26,6 +30,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import kotlin.enums.EnumEntries
enum class HintType(
@Nls private val description: String,
@@ -41,7 +46,7 @@ enum class HintType(
false
) {
override fun provideHintDetails(e: PsiElement): List<InlayInfoDetails> {
return providePropertyTypeHint(e)
return providePropertyTypeHint(e, SHOW_PROPERTY_TYPES)
}
override fun isApplicable(e: PsiElement): Boolean = e is KtProperty && e.getReturnTypeReference() == null && !e.isLocal
@@ -54,7 +59,7 @@ enum class HintType(
false
) {
override fun provideHintDetails(e: PsiElement): List<InlayInfoDetails> {
return providePropertyTypeHint(e)
return providePropertyTypeHint(e, SHOW_LOCAL_VARIABLE_TYPES)
}
override fun isApplicable(e: PsiElement): Boolean =
@@ -72,7 +77,7 @@ enum class HintType(
override fun provideHintDetails(e: PsiElement): List<InlayInfoDetails> {
e.safeAs<KtNamedFunction>()?.let { namedFunction ->
namedFunction.valueParameterList?.let { paramList ->
provideTypeHint(namedFunction, paramList.endOffset)?.let { return listOf(it) }
provideTypeHint(namedFunction, paramList.endOffset, SHOW_FUNCTION_RETURN_TYPES)?.let { return listOf(it) }
}
}
e.safeAs<KtExpression>()?.let { expression ->
@@ -96,7 +101,7 @@ enum class HintType(
override fun provideHintDetails(e: PsiElement): List<InlayInfoDetails> {
(e as? KtParameter)?.let { param ->
param.nameIdentifier?.let { ident ->
provideTypeHint(param, ident.endOffset)?.let { return listOf(it) }
provideTypeHint(param, ident.endOffset, SHOW_FUNCTION_PARAMETER_TYPES)?.let { return listOf(it) }
}
}
return emptyList()
@@ -218,7 +223,7 @@ enum class HintType(
};
companion object {
private val values = values()
private val values: EnumEntries<HintType> = entries
fun resolve(e: PsiElement): List<HintType> =
values.filter { it.isApplicable(e) }
@@ -241,14 +246,20 @@ enum class HintType(
abstract fun isApplicable(e: PsiElement): Boolean
open fun provideHints(e: PsiElement): List<InlayInfo> = emptyList()
open fun provideHintDetails(e: PsiElement): List<InlayInfoDetails> =
provideHints(e).map { InlayInfoDetails(it, listOf(TextInlayInfoDetail(it.text))) }
provideHints(e).map { InlayInfoDetails(it, listOf(TextInlayInfoDetail(it.text)), NoInlayInfoOption) }
val option = Option("SHOW_${this.name}", { this.description }, defaultEnabled)
val enabled
get() = option.get()
}
data class InlayInfoDetails(val inlayInfo: InlayInfo, val details: List<InlayInfoDetail>, val option: String? = null)
data class InlayInfoDetails(val inlayInfo: InlayInfo, val details: List<InlayInfoDetail>, val option: InlayInfoOption? = NoInlayInfoOption)
sealed class InlayInfoOption
object NoInlayInfoOption: InlayInfoOption()
class NamedInlayInfoOption(val name: String): InlayInfoOption()
sealed class InlayInfoDetail(val text: String)
@@ -19,6 +19,8 @@ import com.intellij.refactoring.suggested.createSmartPointer
import org.jetbrains.kotlin.idea.codeInsight.hints.HintType
import org.jetbrains.kotlin.idea.codeInsight.hints.InlayInfoDetail
import org.jetbrains.kotlin.idea.codeInsight.hints.InlayInfoDetails
import org.jetbrains.kotlin.idea.codeInsight.hints.NamedInlayInfoOption
import org.jetbrains.kotlin.idea.codeInsight.hints.NoInlayInfoOption
import org.jetbrains.kotlin.idea.codeInsight.hints.PsiInlayInfoDetail
import org.jetbrains.kotlin.idea.codeInsight.hints.TextInlayInfoDetail
import org.jetbrains.kotlin.idea.codeInsight.hints.TypeInlayInfoDetail
@@ -46,12 +48,14 @@ abstract class AbstractKotlinInlayHintsProvider(private vararg val hintTypes: Hi
resolved.forEach { hintType ->
hintType.provideHintDetails(element).forEach { details: InlayInfoDetails ->
val inlayInfo: InlayInfo = details.inlayInfo
if (details.option != null) {
sink.whenOptionEnabled(details.option) {
addInlayInfo(sink, inlayInfo, details)
details.option?.let {
when (it) {
is NamedInlayInfoOption -> sink.whenOptionEnabled(it.name) {
addInlayInfo(sink, inlayInfo, details)
}
NoInlayInfoOption -> addInlayInfo(sink, inlayInfo, details)
}
} else {
addInlayInfo(sink, inlayInfo, details)
}
}
}
@@ -2,13 +2,10 @@
package org.jetbrains.kotlin.idea.codeInsight.hints.declarative
import org.jetbrains.kotlin.idea.codeInsight.hints.HintType
import org.jetbrains.kotlin.idea.codeInsight.hints.HintType.*
import org.jetbrains.kotlin.idea.codeInsight.hints.NamedInlayInfoOption
class KotlinLambdasHintsProvider :
AbstractKotlinInlayHintsProvider(HintType.LAMBDA_RETURN_EXPRESSION, HintType.LAMBDA_IMPLICIT_PARAMETER_RECEIVER) {
val SHOW_RETURN_EXPRESSIONS = NamedInlayInfoOption("hints.lambda.return")
val SHOW_IMPLICIT_RECEIVERS_AND_PARAMS = NamedInlayInfoOption("hints.lambda.receivers.parameters")
companion object {
const val SHOW_RETURN_EXPRESSIONS = "hints.lambda.return"
const val SHOW_IMPLICIT_RECEIVERS_AND_PARAMS = "hints.lambda.receivers.parameters"
}
}
class KotlinLambdasHintsProvider : AbstractKotlinInlayHintsProvider(LAMBDA_RETURN_EXPRESSION, LAMBDA_IMPLICIT_PARAMETER_RECEIVER)
@@ -2,16 +2,13 @@
package org.jetbrains.kotlin.idea.codeInsight.hints.declarative
import org.jetbrains.kotlin.idea.codeInsight.hints.HintType
import org.jetbrains.kotlin.idea.codeInsight.hints.NamedInlayInfoOption
val SHOW_PROPERTY_TYPES = NamedInlayInfoOption("hints.type.property")
val SHOW_LOCAL_VARIABLE_TYPES = NamedInlayInfoOption("hints.type.variable")
val SHOW_FUNCTION_RETURN_TYPES = NamedInlayInfoOption("hints.type.function.return")
val SHOW_FUNCTION_PARAMETER_TYPES = NamedInlayInfoOption("hints.type.function.parameter")
class KotlinReferencesTypeHintsProvider : AbstractKotlinInlayHintsProvider(
HintType.PROPERTY_HINT, HintType.LOCAL_VARIABLE_HINT, HintType.FUNCTION_HINT, HintType.PARAMETER_TYPE_HINT
) {
companion object {
const val SHOW_PROPERTY_TYPES = "hints.type.property"
const val SHOW_LOCAL_VARIABLE_TYPES = "hints.type.variable"
const val SHOW_FUNCTION_RETURN_TYPES = "hints.type.function.return"
const val SHOW_FUNCTION_PARAMETER_TYPES = "hints.type.function.parameter"
}
}
)
@@ -8,8 +8,8 @@ import com.intellij.psi.PsiComment
import com.intellij.psi.TokenType
import org.jetbrains.kotlin.idea.caches.resolve.safeAnalyzeNonSourceRootCode
import org.jetbrains.kotlin.idea.codeInsight.hints.InlayInfoDetails
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.KotlinLambdasHintsProvider
import org.jetbrains.kotlin.idea.codeInsight.hints.TextInlayInfoDetail
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_IMPLICIT_RECEIVERS_AND_PARAMS
import org.jetbrains.kotlin.psi.KtLambdaExpression
import org.jetbrains.kotlin.psi.psiUtil.siblings
import org.jetbrains.kotlin.resolve.BindingContext
@@ -30,7 +30,7 @@ fun provideLambdaImplicitHints(lambda: KtLambdaExpression): List<InlayInfoDetail
InlayInfoDetails(
InlayInfo("", lbrace.psi.textRange.endOffset),
listOf(TextInlayInfoDetail("this: ")) + renderedType,
option = KotlinLambdasHintsProvider.SHOW_IMPLICIT_RECEIVERS_AND_PARAMS
option = SHOW_IMPLICIT_RECEIVERS_AND_PARAMS
)
}
@@ -42,7 +42,7 @@ fun provideLambdaImplicitHints(lambda: KtLambdaExpression): List<InlayInfoDetail
InlayInfoDetails(
InlayInfo("", lbrace.textRange.endOffset),
listOf(TextInlayInfoDetail("it: ")) + renderedType,
option = KotlinLambdasHintsProvider.SHOW_IMPLICIT_RECEIVERS_AND_PARAMS
option = SHOW_IMPLICIT_RECEIVERS_AND_PARAMS
)
}
} else null
@@ -8,9 +8,9 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.base.psi.isOneLiner
import org.jetbrains.kotlin.idea.caches.resolve.safeAnalyzeNonSourceRootCode
import org.jetbrains.kotlin.idea.codeInsight.hints.InlayInfoDetails
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.KotlinLambdasHintsProvider
import org.jetbrains.kotlin.idea.codeInsight.hints.PsiInlayInfoDetail
import org.jetbrains.kotlin.idea.codeInsight.hints.TextInlayInfoDetail
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_RETURN_EXPRESSIONS
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
@@ -76,7 +76,7 @@ fun provideLambdaReturnValueHints(expression: KtExpression): InlayInfoDetails? {
InlayInfoDetails(
inlayInfo,
listOf(TextInlayInfoDetail("^"), PsiInlayInfoDetail(lambdaName, lambdaExpression)),
option = KotlinLambdasHintsProvider.SHOW_RETURN_EXPRESSIONS
option = SHOW_RETURN_EXPRESSIONS
)
} else null
}
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.idea.base.psi.isMultiLine
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.caches.resolve.safeAnalyzeNonSourceRootCode
import org.jetbrains.kotlin.idea.codeInsight.hints.InlayInfoDetails
import org.jetbrains.kotlin.idea.codeInsight.hints.InlayInfoOption
import org.jetbrains.kotlin.idea.codeInsight.hints.TextInlayInfoDetail
import org.jetbrains.kotlin.idea.formatter.kotlinCustomSettings
import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention
@@ -30,16 +31,16 @@ import org.jetbrains.kotlin.types.typeUtil.immediateSupertypes
import org.jetbrains.kotlin.types.typeUtil.isEnum
import org.jetbrains.kotlin.types.typeUtil.isUnit
fun providePropertyTypeHint(elem: PsiElement): List<InlayInfoDetails> {
fun providePropertyTypeHint(elem: PsiElement, inlayInfoOption: InlayInfoOption): List<InlayInfoDetails> {
(elem as? KtCallableDeclaration)?.let { property ->
property.nameIdentifier?.let { ident ->
provideTypeHint(property, ident.endOffset)?.let { return listOf(it) }
provideTypeHint(property, ident.endOffset, inlayInfoOption)?.let { return listOf(it) }
}
}
return emptyList()
}
fun provideTypeHint(element: KtCallableDeclaration, offset: Int): InlayInfoDetails? {
fun provideTypeHint(element: KtCallableDeclaration, offset: Int, inlayInfoOption: InlayInfoOption): InlayInfoDetails? {
var type: KotlinType = SpecifyTypeExplicitlyIntention.getTypeForDeclaration(element).unwrap()
if (type.containsError()) return null
val declarationDescriptor = type.constructor.declarationDescriptor
@@ -86,7 +87,7 @@ fun provideTypeHint(element: KtCallableDeclaration, offset: Int): InlayInfoDetai
text = "", offset = offset,
isShowOnlyIfExistedBefore = false, isFilterByBlacklist = true, relatesToPrecedingText = true
)
return InlayInfoDetails(inlayInfo, listOf(TextInlayInfoDetail(prefix)) + renderedType)
return InlayInfoDetails(inlayInfo, listOf(TextInlayInfoDetail(prefix)) + renderedType, inlayInfoOption)
} else {
null
}
@@ -9,9 +9,9 @@ import com.intellij.platform.testFramework.core.FileComparisonFailedError
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.utils.inlays.declarative.DeclarativeInlayHintsProviderTestCase
import junit.framework.ComparisonFailure
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.KotlinLambdasHintsProvider.Companion.SHOW_IMPLICIT_RECEIVERS_AND_PARAMS
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.KotlinLambdasHintsProvider.Companion.SHOW_RETURN_EXPRESSIONS
import org.jetbrains.kotlin.idea.base.test.InTextDirectivesUtils
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_IMPLICIT_RECEIVERS_AND_PARAMS
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_RETURN_EXPRESSIONS
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import java.io.File
@@ -43,15 +43,15 @@ abstract class AbstractKotlinLambdasHintsProvider :
with(org.jetbrains.kotlin.idea.codeInsight.hints.declarative.KotlinLambdasHintsProvider()) {
val fileContents = FileUtil.loadFile(File(fileName), true)
val options = buildMap<String, Boolean> {
put(SHOW_RETURN_EXPRESSIONS, false)
put(SHOW_IMPLICIT_RECEIVERS_AND_PARAMS, false)
put(SHOW_RETURN_EXPRESSIONS.name, false)
put(SHOW_IMPLICIT_RECEIVERS_AND_PARAMS.name, false)
when (InTextDirectivesUtils.findStringWithPrefixes(fileContents, "// MODE: ")) {
"return" -> put(SHOW_RETURN_EXPRESSIONS, true)
"receivers_params" -> put(SHOW_IMPLICIT_RECEIVERS_AND_PARAMS, true)
"return" -> put(SHOW_RETURN_EXPRESSIONS.name, true)
"receivers_params" -> put(SHOW_IMPLICIT_RECEIVERS_AND_PARAMS.name, true)
"return-&-receivers_params" -> {
put(SHOW_IMPLICIT_RECEIVERS_AND_PARAMS, true)
put(SHOW_RETURN_EXPRESSIONS, true)
put(SHOW_IMPLICIT_RECEIVERS_AND_PARAMS.name, true)
put(SHOW_RETURN_EXPRESSIONS.name, true)
}
}
}
@@ -12,11 +12,11 @@ import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.utils.inlays.declarative.DeclarativeInlayHintsProviderTestCase
import com.intellij.util.ThrowableRunnable
import junit.framework.ComparisonFailure
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.KotlinReferencesTypeHintsProvider.Companion.SHOW_FUNCTION_PARAMETER_TYPES
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.KotlinReferencesTypeHintsProvider.Companion.SHOW_FUNCTION_RETURN_TYPES
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.KotlinReferencesTypeHintsProvider.Companion.SHOW_LOCAL_VARIABLE_TYPES
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.KotlinReferencesTypeHintsProvider.Companion.SHOW_PROPERTY_TYPES
import org.jetbrains.kotlin.idea.base.test.InTextDirectivesUtils
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_FUNCTION_PARAMETER_TYPES
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_FUNCTION_RETURN_TYPES
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_LOCAL_VARIABLE_TYPES
import org.jetbrains.kotlin.idea.codeInsight.hints.declarative.SHOW_PROPERTY_TYPES
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.idea.test.runAll
import java.io.File
@@ -56,20 +56,27 @@ abstract class AbstractKotlinReferenceTypeHintsProviderTest :
with(org.jetbrains.kotlin.idea.codeInsight.hints.declarative.KotlinReferencesTypeHintsProvider()) {
val fileContents = FileUtil.loadFile(File(fileName), true)
val options = buildMap<String, Boolean> {
put(SHOW_PROPERTY_TYPES, false)
put(SHOW_LOCAL_VARIABLE_TYPES, false)
put(SHOW_FUNCTION_RETURN_TYPES, false)
put(SHOW_FUNCTION_PARAMETER_TYPES, false)
put(SHOW_PROPERTY_TYPES.name, false)
put(SHOW_LOCAL_VARIABLE_TYPES.name, false)
put(SHOW_FUNCTION_RETURN_TYPES.name, false)
put(SHOW_FUNCTION_PARAMETER_TYPES.name, false)
when (InTextDirectivesUtils.findStringWithPrefixes(fileContents, "// MODE: ")) {
"function_return" -> put(SHOW_FUNCTION_RETURN_TYPES, true)
"local_variable" -> put(SHOW_LOCAL_VARIABLE_TYPES, true)
"parameter" -> put(SHOW_FUNCTION_PARAMETER_TYPES, true)
"property" -> put(SHOW_PROPERTY_TYPES, true)
"function_return" -> {
put(SHOW_PROPERTY_TYPES.name, true)
put(SHOW_FUNCTION_RETURN_TYPES.name, true)
put(SHOW_LOCAL_VARIABLE_TYPES.name, true)
}
"local_variable" -> put(SHOW_LOCAL_VARIABLE_TYPES.name, true)
"parameter" -> put(SHOW_FUNCTION_PARAMETER_TYPES.name, true)
"property" -> {
put(SHOW_PROPERTY_TYPES.name, true)
put(SHOW_FUNCTION_RETURN_TYPES.name, true)
}
"all" -> {
put(SHOW_PROPERTY_TYPES, true)
put(SHOW_LOCAL_VARIABLE_TYPES, true)
put(SHOW_FUNCTION_RETURN_TYPES, true)
put(SHOW_FUNCTION_PARAMETER_TYPES, true)
put(SHOW_PROPERTY_TYPES.name, true)
put(SHOW_LOCAL_VARIABLE_TYPES.name, true)
put(SHOW_FUNCTION_RETURN_TYPES.name, true)
put(SHOW_FUNCTION_PARAMETER_TYPES.name, true)
}
else -> {}
}
@@ -1,6 +1,6 @@
// "Add annotation target" "false"
// WITH_STDLIB
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Make internal
// ACTION: Specify type explicitly
// ERROR: This annotation is not applicable to target 'top level property without backing field or delegate'
@@ -1,5 +1,5 @@
// "Add annotation target" "false"
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Introduce import alias
// ACTION: Make internal
// ACTION: Make private
@@ -1,5 +1,5 @@
// "Add annotation target" "false"
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Introduce import alias
// ACTION: Make internal
// ACTION: Make private
@@ -1,5 +1,5 @@
// "Add else branch" "false"
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Replace property initializer with 'if' expression
// ERROR: 'if' must have both main and 'else' branches if used as an expression
@@ -1,5 +1,5 @@
// "Add else branch" "false"
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Replace property initializer with 'if' expression
// ERROR: 'if' must have both main and 'else' branches if used as an expression
@@ -5,7 +5,8 @@
// ACTION: Add braces to all 'if' statements
// ACTION: Convert property initializer to getter
// ACTION: Convert to lazy property
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Move to constructor
// WITH_STDLIB
fun main() {
@@ -6,7 +6,8 @@
// ACTION: Add braces to all 'if' statements
// ACTION: Convert property initializer to getter
// ACTION: Convert to lazy property
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Go To Super Property
// ACTION: Introduce local variable
// WITH_STDLIB
@@ -3,7 +3,7 @@
// ACTION: Change parameter 'x' type of function 'foo' to 'Array<Int>'
// ACTION: Convert to block body
// ACTION: Create function 'foo'
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// DISABLE-ERRORS
fun foo(vararg x: String) {}
@@ -3,7 +3,7 @@
// ACTION: Change parameter 'x' type of function 'foo' to 'List<String>'
// ACTION: Convert to block body
// ACTION: Create function 'foo'
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// DISABLE-ERRORS
// Fix this test case if https://youtrack.jetbrains.com/issue/KT-12663 is implemented
@@ -3,7 +3,7 @@
// ACTION: Change parameter 'x' type of function 'foo' to 'Array<String>'
// ACTION: Convert to block body
// ACTION: Create function 'foo'
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ERROR: Type mismatch: inferred type is Array<String> but String was expected
fun foo(x: String) {}
@@ -2,7 +2,7 @@
// ERROR: Too many arguments for public constructor G() defined in G
// ACTION: Convert to block body
// ACTION: Create function 'G'
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Remove argument
@@ -3,7 +3,7 @@
// ACTION: Create class 'T'
// ACTION: Create enum 'T'
// ACTION: Create interface 'T'
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ERROR: Unresolved reference: T
val a = fun() {
val b: T<caret>
@@ -1,7 +1,7 @@
// "Create local variable 'foo'" "false"
// ACTION: Add 'f =' to argument
// ACTION: Create function 'foo'
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
fun test(f: (Int) -> Int) {}
@@ -1,7 +1,7 @@
// "Create parameter 'foo'" "false"
// ACTION: Add 'f =' to argument
// ACTION: Create function 'foo'
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
fun test(f: (Int) -> Int) {}
@@ -1,7 +1,7 @@
// "Create property 'foo'" "false"
// ACTION: Add 'f =' to argument
// ACTION: Create function 'foo'
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
fun test(f: (Int) -> Int) {}
@@ -1,7 +1,7 @@
// "Make 'bar' private" "true"
// ACTION: Convert member to extension
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Make 'Data' internal
// ACTION: Make 'Data' public
// ACTION: Make 'bar' private
@@ -1,7 +1,7 @@
// "Make 'bar' private" "true"
// ACTION: Convert member to extension
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Make 'Data' internal
// ACTION: Make 'Data' public
// ACTION: Make 'bar' private
@@ -2,7 +2,7 @@
// ACTION: Compiler warning 'DEPRECATION' options
// ACTION: Compiler warning 'TYPEALIAS_EXPANSION_DEPRECATION' options
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Introduce import alias
// ACTION: Introduce local variable
// ACTION: Replace usages of '`<init>`(): Old /* = OldClass */' in whole project
@@ -1,7 +1,7 @@
// "Replace with 'NewClass'" "false"
// ACTION: Compiler warning 'TYPEALIAS_EXPANSION_DEPRECATION' options
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Introduce import alias
// ACTION: Introduce local variable
@@ -1,6 +1,6 @@
// "Add non-null asserted (!!) call" "false"
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Replace overloaded operator with function call
// WITH_STDLIB
@@ -3,8 +3,8 @@
// ACTION: Convert to anonymous function
// ACTION: Convert to block body
// ACTION: Convert to run { ... }
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Specify explicit lambda signature
// ACTION: Specify explicit lambda signature
@@ -3,8 +3,8 @@
// ACTION: Convert to anonymous function
// ACTION: Convert to block body
// ACTION: Convert to run { ... }
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Specify explicit lambda signature
// ACTION: Specify explicit lambda signature
@@ -4,8 +4,8 @@
// ACTION: Convert to block body
// ACTION: Convert to multi-line lambda
// ACTION: Convert to run { ... }
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Specify explicit lambda signature
// ACTION: Specify explicit lambda signature
@@ -3,8 +3,8 @@
// ACTION: Convert to anonymous function
// ACTION: Convert to block body
// ACTION: Convert to multi-line lambda
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Specify explicit lambda signature
// ACTION: Specify explicit lambda signature
@@ -4,8 +4,8 @@
// ACTION: Convert to anonymous function
// ACTION: Convert to block body
// ACTION: Convert to run { ... }
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Specify explicit lambda signature
// ACTION: Specify explicit lambda signature
@@ -4,8 +4,8 @@
// ACTION: Convert to anonymous function
// ACTION: Convert to block body
// ACTION: Convert to run { ... }
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Specify explicit lambda signature
// ACTION: Specify explicit lambda signature
@@ -5,8 +5,8 @@
// ACTION: Convert to block body
// ACTION: Convert to multi-line lambda
// ACTION: Convert to run { ... }
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Specify explicit lambda signature
// ACTION: Specify explicit lambda signature
@@ -4,8 +4,8 @@
// ACTION: Convert to anonymous function
// ACTION: Convert to block body
// ACTION: Convert to multi-line lambda
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Specify explicit lambda signature
// ACTION: Specify explicit lambda signature
@@ -3,8 +3,8 @@
// ACTION: Convert to anonymous function
// ACTION: Convert to block body
// ACTION: Convert to multi-line lambda
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Specify explicit lambda signature
// ACTION: Specify explicit lambda signature
@@ -4,8 +4,8 @@
// ACTION: Convert to anonymous function
// ACTION: Convert to block body
// ACTION: Convert to multi-line lambda
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Specify explicit lambda signature
// ACTION: Specify explicit lambda signature
@@ -1,7 +1,7 @@
// "Make 'Data' internal" "true"
// ACTION: Convert member to extension
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Make 'Data' internal
// ACTION: Make 'Data' public
// ACTION: Make 'bar' private
@@ -1,7 +1,7 @@
// "Make 'Data' internal" "true"
// ACTION: Convert member to extension
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Make 'Data' internal
// ACTION: Make 'Data' public
// ACTION: Make 'bar' private
@@ -1,7 +1,7 @@
// "Make bar internal" "false"
// ACTION: Add names to call arguments
// ACTION: Convert to lazy property
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Move to constructor
// ERROR: Cannot access 'bar': it is private in 'First'
@@ -1,7 +1,7 @@
// "Make containing function suspend" "false"
// ACTION: Convert to run
// ACTION: Convert to with
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// DISABLE-ERRORS
class A {
suspend fun foo() {}
@@ -1,7 +1,7 @@
// "Make bar suspend" "false"
// ACTION: Convert to lazy property
// ACTION: Convert property initializer to getter
// ACTION: Enable 'Types' inlay hints
// ACTION: Convert to lazy property
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Introduce import alias
// ERROR: Suspend function 'foo' should be called only from a coroutine or another suspend function
@@ -1,11 +1,11 @@
// "Move annotation to receiver type" "false"
// ERROR: This annotation is not applicable to target 'declaration' and use site target '@receiver'
// ACTION: Make internal
// ACTION: Enable 'Types' inlay hints
// ACTION: Add annotation target
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Introduce import alias
// ACTION: Make internal
// ACTION: Make private
// ACTION: Specify type explicitly
// ACTION: Add annotation target
annotation class Ann
@@ -1,7 +1,7 @@
// "Replace with safe (?.) call" "false"
// ERROR: Operator call corresponds to a dot-qualified call 'p1.compareTo(p2)' which is not allowed on a nullable receiver 'p1'.
// ACTION: Add non-null asserted (!!) call
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Expand boolean expression to 'if else'
// ACTION: Flip '>'
// ACTION: Replace overloaded operator with function call
@@ -1,6 +1,6 @@
// "Replace with safe (?.) call" "false"
// ACTION: Add non-null asserted (!!) call
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Expand boolean expression to 'if else'
// ACTION: Flip '>'
// ACTION: Replace '&&' with '||'
@@ -1,6 +1,6 @@
// "Replace with safe (?.) call" "false"
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Replace overloaded operator with function call
// ACTION: Wrap with '?.let { ... }' call
// ERROR: Reference has a nullable type 'String?', use explicit '?.invoke()' to make a function-like call instead
@@ -1,6 +1,6 @@
// "Replace with safe (?.) call" "false"
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Replace overloaded operator with function call
// ACTION: Wrap with '?.let { ... }' call
// ERROR: Reference has a nullable type '(String.() -> Unit)?', use explicit '?.invoke()' to make a function-like call instead
@@ -1,6 +1,6 @@
// "Opt in for 'Library' on 't'" "true"
// ACTION: Add '-opt-in=DoubleExperementalApi2.Library' to module light_idea_test_case compiler arguments
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Opt in for 'Library' in containing file 'doubleExperementalApi2.kts'
// ACTION: Opt in for 'Library' on 'bar'
// ACTION: Opt in for 'Library' on 't'
@@ -1,6 +1,6 @@
// "Opt in for 'Library' on 't'" "true"
// ACTION: Add '-opt-in=DoubleExperementalApi2.Library' to module light_idea_test_case compiler arguments
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Opt in for 'Library' in containing file 'doubleExperementalApi2.kts'
// ACTION: Opt in for 'Library' on 'bar'
// ACTION: Opt in for 'Library' on 't'
@@ -2,8 +2,8 @@
// ACTION: Convert function to property
// ACTION: Convert to block body
// ACTION: Create test
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Specify return type explicitly
fun foo<caret>() = arrayOf(java.lang.String.valueOf(1))
@@ -1,6 +1,6 @@
// "Replace cast with call to 'toInt()'" "false"
// ACTION: Compiler warning 'CAST_NEVER_SUCCEEDS' options
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// WARNING: Cast can never succeed
fun foo() {
@@ -1,8 +1,8 @@
// "Remove single lambda parameter declaration" "false"
// ACTION: Convert to anonymous function
// ACTION: Convert to multi-line lambda
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Function parameter types' for 'Types' inlay hints
// ACTION: Move lambda argument into parentheses
// ACTION: Rename to _
// ACTION: Specify explicit lambda signature
@@ -3,8 +3,8 @@
// ACTION: Convert to anonymous function
// ACTION: Convert to apply
// ACTION: Convert to multi-line lambda
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Remove explicit lambda parameter types (may break code)
// ACTION: Rename to _
fun test() {
@@ -1,7 +1,7 @@
// "Safe delete 'something'" "false"
// ACTION: Convert function to property
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Go To Super Method
// ACTION: Specify return type explicitly
@@ -2,7 +2,7 @@
// ACTION: Convert function to property
// ACTION: Convert member to extension
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Make 'open'
// ACTION: Move to companion object
// ACTION: Specify return type explicitly
@@ -2,7 +2,7 @@
// ACTION: Convert function to property
// ACTION: Convert member to extension
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Make 'open'
// ACTION: Move to companion object
// ACTION: Specify return type explicitly
@@ -2,7 +2,7 @@
// ACTION: Convert function to property
// ACTION: Convert member to extension
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Go To Overridden Methods
// ACTION: Move to companion object
// ACTION: Specify return type explicitly
@@ -2,7 +2,7 @@
// ACTION: Convert function to property
// ACTION: Convert member to extension
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Make 'open'
// ACTION: Move to companion object
// ACTION: Specify return type explicitly
@@ -2,7 +2,7 @@
// ACTION: Convert function to property
// ACTION: Convert member to extension
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Go To Overridden Methods
// ACTION: Move to companion object
// ACTION: Specify return type explicitly
@@ -2,7 +2,7 @@
// ACTION: Convert function to property
// ACTION: Convert to block body
// ACTION: Create test
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Specify return type explicitly
import useMe as used
@@ -1,7 +1,7 @@
// "Remove parameter 'value'" "false"
// ACTION: Compiler warning 'UNUSED_PARAMETER' options
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Function parameter types' for 'Types' inlay hints
// ACTION: Specify type explicitly
class Abacaba {
var foo: String
@@ -1,8 +1,8 @@
// "Remove parameter 'x'" "false"
// ACTION: Add 'block =' to argument
// ACTION: Convert parameter to receiver
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Put parameters on separate lines
// ACTION: Rename to _
// ACTION: Specify return type explicitly
@@ -1,8 +1,8 @@
// "Reorder parameters" "false"
// ACTION: Add '@JvmOverloads' annotation to function 'foo'
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Flip ',' (may change semantics)
// ACTION: Put parameters on one line
// ACTION: Specify return type explicitly
@@ -1,8 +1,8 @@
// "Reorder parameters" "false"
// ACTION: Add '@JvmOverloads' annotation to function 'bar'
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Flip ',' (may change semantics)
// ACTION: Put parameters on one line
// ACTION: Specify return type explicitly
@@ -1,6 +1,6 @@
// "Replace 'if' expression with elvis expression" "false"
// ACTION: Add non-null asserted (!!) call
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Introduce local variable
// DISABLE-ERRORS
class Test {
@@ -2,8 +2,8 @@
// ACTION: Convert to anonymous function
// ACTION: Convert to lazy property
// ACTION: Convert to single-line lambda
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Remove explicit lambda parameter types (may break code)
// ACTION: Rename to _
@@ -1,7 +1,7 @@
// "Surround with null check" "false"
// ACTION: Add non-null asserted (!!) call
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Replace with safe (?.) call
// ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Int?
@@ -1,6 +1,6 @@
// "Surround with null check" "false"
// ACTION: Add non-null asserted (!!) call
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Replace with safe (?.) call
// ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?
@@ -3,7 +3,7 @@
// ACTION: Convert property initializer to getter
// ACTION: Convert property to function
// ACTION: Convert to lazy property
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Introduce backing property
// ACTION: Move to companion object
// ACTION: Specify type explicitly
@@ -3,7 +3,7 @@
// ACTION: Convert property initializer to getter
// ACTION: Convert property to function
// ACTION: Convert to lazy property
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Property types' for 'Types' inlay hints
// ACTION: Introduce backing property
// ACTION: Move to companion object
// ACTION: Specify type explicitly
@@ -7,7 +7,7 @@
// ACTION: Convert property initializer to getter
// ACTION: Convert to lazy property
// ACTION: Do not show hints for current method
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Property types' for 'Types' inlay hints
fun takeUInt(u: UInt) = 0
@@ -1,6 +1,6 @@
// "Remove variable 'one'" "false"
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable a trailing comma by default in the formatter
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// ACTION: Rename to _
// ACTION: Specify all types explicitly in destructuring declaration
// ACTION: Specify type explicitly
@@ -1,5 +1,5 @@
// "Add remaining branches" "false"
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// WITH_STDLIB
// ERROR: 'when' expression must be exhaustive, add necessary 'is B' branch or 'else' branch instead
@@ -1,5 +1,5 @@
// "Add remaining branches" "false"
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Local variable types' for 'Types' inlay hints
// WITH_STDLIB
// ERROR: 'when' expression must be exhaustive, add necessary 'is B' branch or 'else' branch instead
@@ -2,7 +2,7 @@
// WITH_STDLIB
// ACTION: Add non-null asserted (!!) call
// ACTION: Convert to block body
// ACTION: Enable 'Types' inlay hints
// ACTION: Enable option 'Function return types' for 'Types' inlay hints
// ACTION: Introduce local variable
// ACTION: Replace with safe (?.) call
// ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Int?