Show argument name hints for function type calls only for known names
#KT-19216 Fixed
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
package org.jetbrains.kotlin.idea.parameterInfo
|
package org.jetbrains.kotlin.idea.parameterInfo
|
||||||
|
|
||||||
import com.intellij.codeInsight.hints.InlayInfo
|
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.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
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> {
|
private fun getParameterInfoForCallCandidate(resolvedCall: ResolvedCall<out CallableDescriptor>): List<InlayInfo> {
|
||||||
return resolvedCall.valueArguments.mapNotNull { (valueParam: ValueParameterDescriptor, resolvedArg) ->
|
return resolvedCall.valueArguments.mapNotNull { (valueParam: ValueParameterDescriptor, resolvedArg) ->
|
||||||
|
if (resolvedCall.resultingDescriptor is FunctionInvokeDescriptor &&
|
||||||
|
valueParam.type.extractParameterNameFromFunctionTypeArgument() == null) {
|
||||||
|
return@mapNotNull null
|
||||||
|
}
|
||||||
|
|
||||||
resolvedArg.arguments.firstOrNull()?.let { arg ->
|
resolvedArg.arguments.firstOrNull()?.let { arg ->
|
||||||
arg.getArgumentExpression()?.let { argExp ->
|
arg.getArgumentExpression()?.let { argExp ->
|
||||||
if (!arg.isNamed() && !valueParam.name.isSpecial && argExp.isUnclearExpression()) {
|
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
|
@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)
|
||||||
|
""")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user