Show argument name hints for function type calls only for known names

#KT-19216 Fixed
This commit is contained in:
Dmitry Jemerov
2017-09-08 18:53:46 +02:00
parent af09f5a49f
commit f2a7e7f238
2 changed files with 19 additions and 0 deletions
@@ -17,6 +17,8 @@
package org.jetbrains.kotlin.idea.parameterInfo
import com.intellij.codeInsight.hints.InlayInfo
import org.jetbrains.kotlin.builtins.extractParameterNameFromFunctionTypeArgument
import org.jetbrains.kotlin.builtins.functions.FunctionInvokeDescriptor
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
@@ -53,6 +55,11 @@ fun provideArgumentNameHints(element: KtCallElement): List<InlayInfo> {
private fun getParameterInfoForCallCandidate(resolvedCall: ResolvedCall<out CallableDescriptor>): List<InlayInfo> {
return resolvedCall.valueArguments.mapNotNull { (valueParam: ValueParameterDescriptor, resolvedArg) ->
if (resolvedCall.resultingDescriptor is FunctionInvokeDescriptor &&
valueParam.type.extractParameterNameFromFunctionTypeArgument() == null) {
return@mapNotNull null
}
resolvedArg.arguments.firstOrNull()?.let { arg ->
arg.getArgumentExpression()?.let { argExp ->
if (!arg.isNamed() && !valueParam.name.isSpecial && argExp.isUnclearExpression()) {
@@ -160,4 +160,16 @@ annotation class ManyArgs(val name: String, val surname: String)
@ManyArgs(<hint text="name:"/>"Ilya", <hint text="surname:"/>"Sergey") class AnnotatedMuch
""")
}
fun `test functional type`() {
check("""
fun <T> T.test(block: (T) -> Unit) = block(this)
""")
}
fun `test functional type with parameter name`() {
check("""
fun <T> T.test(block: (receiver: T, Int) -> Unit) = block(<hint text="receiver:"/>this, 0)
""")
}
}