KT-22815: Show documentation for function value/type params

This commit is contained in:
Simon Ogorodnik
2018-07-12 17:08:33 +03:00
parent e4d76382b8
commit 9ec0ce6ec8
3 changed files with 16 additions and 6 deletions
@@ -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<KDoc>()
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<KDoc>()
val subjectName = name
if (classKDoc != null && subjectName != null) {
val propertySection =
classKDoc.findSectionByTag(KDocKnownTag.PROPERTY, subjectName)?.takeIf { this.isPropertyParameter() }
?: classKDoc.findDescendantOfType<KDocTag> { it.knownTag == KDocKnownTag.PARAM && it.getSubjectName() == subjectName }
classKDoc.findSectionByTag(KDocKnownTag.PROPERTY, subjectName)?.takeIf { this is KtParameter && this.isPropertyParameter() }
?: classKDoc.findDescendantOfType<KDocTag> { it.knownTag == KDocKnownTag.PARAM && it.getSubjectName() == subjectName }
if (propertySection != null) {
return propertySection
}