Enable argument name hints for annotations
#KT-19146 Fixed
This commit is contained in:
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
|
|
||||||
fun provideArgumentNameHints(element: KtCallExpression): List<InlayInfo> {
|
fun provideArgumentNameHints(element: KtCallElement): List<InlayInfo> {
|
||||||
if (element.valueArguments.none { it.getArgumentExpression()?.isUnclearExpression() == true }) return emptyList()
|
if (element.valueArguments.none { it.getArgumentExpression()?.isUnclearExpression() == true }) return emptyList()
|
||||||
val ctx = element.analyze(BodyResolveMode.PARTIAL)
|
val ctx = element.analyze(BodyResolveMode.PARTIAL)
|
||||||
val call = element.getCall(ctx) ?: return emptyList()
|
val call = element.getCall(ctx) ?: return emptyList()
|
||||||
|
|||||||
+4
-4
@@ -82,13 +82,13 @@ enum class HintType(desc: String, enabled: Boolean) {
|
|||||||
},
|
},
|
||||||
PARAMETER_HINT("Show argument name hints", true) {
|
PARAMETER_HINT("Show argument name hints", true) {
|
||||||
override fun provideHints(elem: PsiElement): List<InlayInfo> {
|
override fun provideHints(elem: PsiElement): List<InlayInfo> {
|
||||||
(elem as? KtCallExpression)?.let {
|
(elem as? KtCallElement)?.let {
|
||||||
return provideArgumentNameHints(it)
|
return provideArgumentNameHints(it)
|
||||||
}
|
}
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isApplicable(elem: PsiElement): Boolean = elem is KtCallExpression
|
override fun isApplicable(elem: PsiElement): Boolean = elem is KtCallElement
|
||||||
};
|
};
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -122,7 +122,7 @@ class KotlinInlayParameterHintsProvider : InlayParameterHintsProvider {
|
|||||||
override fun getHintInfo(element: PsiElement): HintInfo? {
|
override fun getHintInfo(element: PsiElement): HintInfo? {
|
||||||
val hintType = HintType.resolve(element) ?: return null
|
val hintType = HintType.resolve(element) ?: return null
|
||||||
return when (hintType) {
|
return when (hintType) {
|
||||||
HintType.PARAMETER_HINT -> (element as? KtCallExpression)?.let { getMethodInfo(it) }
|
HintType.PARAMETER_HINT -> (element as? KtCallElement)?.let { getMethodInfo(it) }
|
||||||
else -> HintInfo.OptionInfo(hintType.option)
|
else -> HintInfo.OptionInfo(hintType.option)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ class KotlinInlayParameterHintsProvider : InlayParameterHintsProvider {
|
|||||||
super.getInlayPresentation(inlayText)
|
super.getInlayPresentation(inlayText)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getMethodInfo(elem: KtCallExpression): HintInfo.MethodInfo? {
|
private fun getMethodInfo(elem: KtCallElement): HintInfo.MethodInfo? {
|
||||||
val ctx = elem.analyze(BodyResolveMode.PARTIAL)
|
val ctx = elem.analyze(BodyResolveMode.PARTIAL)
|
||||||
val resolvedCall = elem.getResolvedCall(ctx)
|
val resolvedCall = elem.getResolvedCall(ctx)
|
||||||
val resolvedCallee = resolvedCall?.candidateDescriptor
|
val resolvedCallee = resolvedCall?.candidateDescriptor
|
||||||
|
|||||||
@@ -151,6 +151,13 @@ class X {
|
|||||||
class X {
|
class X {
|
||||||
operator fun invoke(a: Int, bI: Int) {}
|
operator fun invoke(a: Int, bI: Int) {}
|
||||||
}
|
}
|
||||||
|
""")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `test annotation`() {
|
||||||
|
check("""
|
||||||
|
annotation class ManyArgs(val name: String, val surname: String)
|
||||||
|
@ManyArgs(<hint text="name:"/>"Ilya", <hint text="surname:"/>"Sergey") class AnnotatedMuch
|
||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user