KT-22815: Show documentation for function value/type params
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.kdoc
|
package org.jetbrains.kotlin.idea.kdoc
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
|
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
|
val subjectName = name
|
||||||
if (classKDoc != null && subjectName != null) {
|
if (classKDoc != null && subjectName != null) {
|
||||||
val propertySection =
|
val propertySection =
|
||||||
classKDoc.findSectionByTag(KDocKnownTag.PROPERTY, subjectName)?.takeIf { this.isPropertyParameter() }
|
classKDoc.findSectionByTag(KDocKnownTag.PROPERTY, subjectName)?.takeIf { this is KtParameter && this.isPropertyParameter() }
|
||||||
?: classKDoc.findDescendantOfType<KDocTag> { it.knownTag == KDocKnownTag.PARAM && it.getSubjectName() == subjectName }
|
?: classKDoc.findDescendantOfType<KDocTag> { it.knownTag == KDocKnownTag.PARAM && it.getSubjectName() == subjectName }
|
||||||
if (propertySection != null) {
|
if (propertySection != null) {
|
||||||
return propertySection
|
return propertySection
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* @param f docs for param f
|
||||||
|
*/
|
||||||
fun some(<caret>f: (Int) -> String) : String? = null
|
fun some(<caret>f: (Int) -> String) : String? = null
|
||||||
|
|
||||||
//INFO: <div class='definition'><pre>value-parameter <b>f</b>: (Int) → String</pre></div>
|
//INFO: <div class='definition'><pre>value-parameter <b>f</b>: (Int) → String</pre></div><div class='content'><p>docs for param f</p></div><table class='sections'></table>
|
||||||
|
|||||||
+4
-1
@@ -1,5 +1,8 @@
|
|||||||
interface Base
|
interface Base
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param T this is docs for T
|
||||||
|
*/
|
||||||
class Some<<caret>T: Base>
|
class Some<<caret>T: Base>
|
||||||
|
|
||||||
//INFO: <div class='definition'><pre><a href="psi_element://Some"><code>Some</code></a><br><<b>T</b> : <a href="psi_element://Base">Base</a>></pre></div>
|
//INFO: <div class='definition'><pre><a href="psi_element://Some"><code>Some</code></a><br><<b>T</b> : <a href="psi_element://Base">Base</a>></pre></div><div class='content'><p>this is docs for T</p></div><table class='sections'></table>
|
||||||
|
|||||||
Reference in New Issue
Block a user