From 9ec0ce6ec8ede71dfb489bfce515160d6651897f Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 12 Jul 2018 17:08:33 +0300 Subject: [PATCH] KT-22815: Show documentation for function value/type params --- .../src/org/jetbrains/kotlin/idea/kdoc/findKDoc.kt | 12 ++++++++---- idea/testData/editor/quickDoc/AtFunctionParameter.kt | 5 ++++- idea/testData/editor/quickDoc/AtTypeParameter.kt | 5 ++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/kdoc/findKDoc.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/kdoc/findKDoc.kt index 47ecc2b465e..cdc992f42f2 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/kdoc/findKDoc.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/kdoc/findKDoc.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.idea.kdoc import com.intellij.psi.PsiElement +import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource @@ -62,13 +63,16 @@ fun KtElement.findKDoc(descriptorToPsi: (DeclarationDescriptorWithSource) -> Psi } - if (this is KtParameter) { - val classKDoc = containingClassOrObject?.getChildOfType() + + if (this is KtParameter || this is KtTypeParameter) { + val containingDeclaration = + PsiTreeUtil.getParentOfType(this, KtDeclarationWithBody::class.java, KtClassOrObject::class.java, KtScript::class.java) + val classKDoc = containingDeclaration?.getChildOfType() val subjectName = name if (classKDoc != null && subjectName != null) { val propertySection = - classKDoc.findSectionByTag(KDocKnownTag.PROPERTY, subjectName)?.takeIf { this.isPropertyParameter() } - ?: classKDoc.findDescendantOfType { it.knownTag == KDocKnownTag.PARAM && it.getSubjectName() == subjectName } + classKDoc.findSectionByTag(KDocKnownTag.PROPERTY, subjectName)?.takeIf { this is KtParameter && this.isPropertyParameter() } + ?: classKDoc.findDescendantOfType { it.knownTag == KDocKnownTag.PARAM && it.getSubjectName() == subjectName } if (propertySection != null) { return propertySection } diff --git a/idea/testData/editor/quickDoc/AtFunctionParameter.kt b/idea/testData/editor/quickDoc/AtFunctionParameter.kt index 17508ebbb5b..5062ba217c2 100644 --- a/idea/testData/editor/quickDoc/AtFunctionParameter.kt +++ b/idea/testData/editor/quickDoc/AtFunctionParameter.kt @@ -1,3 +1,6 @@ +/** + * @param f docs for param f + */ fun some(f: (Int) -> String) : String? = null -//INFO:
value-parameter f: (Int) → String
+//INFO:
value-parameter f: (Int) → String

docs for param f

diff --git a/idea/testData/editor/quickDoc/AtTypeParameter.kt b/idea/testData/editor/quickDoc/AtTypeParameter.kt index d61f28f4890..933b90acc26 100644 --- a/idea/testData/editor/quickDoc/AtTypeParameter.kt +++ b/idea/testData/editor/quickDoc/AtTypeParameter.kt @@ -1,5 +1,8 @@ interface Base +/** + * @param T this is docs for T + */ class Some<T: Base> -//INFO:
Some
<T : Base>
+//INFO:
Some
<T : Base>

this is docs for T