KT-22815: Wrap parameters and try new DocumentationMarkup
This commit is contained in:
@@ -20,6 +20,7 @@ import com.google.common.html.HtmlEscapers
|
||||
import com.intellij.codeInsight.documentation.DocumentationManagerUtil
|
||||
import com.intellij.codeInsight.javadoc.JavaDocInfoGeneratorFactory
|
||||
import com.intellij.lang.documentation.AbstractDocumentationProvider
|
||||
import com.intellij.lang.documentation.DocumentationMarkup
|
||||
import com.intellij.lang.java.JavaDocumentationProvider
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.psi.PsiElement
|
||||
@@ -88,6 +89,42 @@ class HtmlClassifierNamePolicy(val base: ClassifierNamePolicy) : ClassifierNameP
|
||||
}
|
||||
}
|
||||
|
||||
class WrapValueParameterHandler(val base: DescriptorRenderer.ValueParametersHandler) : DescriptorRenderer.ValueParametersHandler {
|
||||
|
||||
|
||||
override fun appendBeforeValueParameters(parameterCount: Int, builder: StringBuilder) {
|
||||
base.appendBeforeValueParameters(parameterCount, builder)
|
||||
}
|
||||
|
||||
override fun appendBeforeValueParameter(
|
||||
parameter: ValueParameterDescriptor,
|
||||
parameterIndex: Int,
|
||||
parameterCount: Int,
|
||||
builder: StringBuilder
|
||||
) {
|
||||
builder.append("\n ")
|
||||
base.appendBeforeValueParameter(parameter, parameterIndex, parameterCount, builder)
|
||||
}
|
||||
|
||||
override fun appendAfterValueParameter(
|
||||
parameter: ValueParameterDescriptor,
|
||||
parameterIndex: Int,
|
||||
parameterCount: Int,
|
||||
builder: StringBuilder
|
||||
) {
|
||||
base.appendAfterValueParameter(parameter, parameterIndex, parameterCount, builder)
|
||||
}
|
||||
|
||||
override fun appendAfterValueParameters(parameterCount: Int, builder: StringBuilder) {
|
||||
if (parameterCount > 0) {
|
||||
builder.appendln()
|
||||
}
|
||||
base.appendAfterValueParameters(parameterCount, builder)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
|
||||
|
||||
override fun getQuickNavigateInfo(element: PsiElement?, originalElement: PsiElement?): String? {
|
||||
@@ -123,6 +160,7 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
|
||||
|
||||
private val DESCRIPTOR_RENDERER = DescriptorRenderer.HTML.withOptions {
|
||||
classifierNamePolicy = HtmlClassifierNamePolicy(ClassifierNamePolicy.SHORT)
|
||||
valueParametersHandler = WrapValueParameterHandler(valueParametersHandler)
|
||||
renderCompanionObjectName = true
|
||||
}
|
||||
|
||||
@@ -269,27 +307,32 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
|
||||
}
|
||||
}
|
||||
|
||||
var renderedDecl = DESCRIPTOR_RENDERER.withOptions {
|
||||
var declaration = DESCRIPTOR_RENDERER.withOptions {
|
||||
withDefinedIn = !DescriptorUtils.isLocal(declarationDescriptor)
|
||||
}.render(declarationDescriptor)
|
||||
|
||||
if (!quickNavigation) {
|
||||
renderedDecl = "<pre>$renderedDecl</pre>"
|
||||
}
|
||||
|
||||
var renderedHtml: String
|
||||
|
||||
|
||||
//if (!quickNavigation) {
|
||||
renderedHtml = "${DocumentationMarkup.DEFINITION_START}$declaration${DocumentationMarkup.DEFINITION_END}"
|
||||
//}
|
||||
|
||||
val deprecationProvider = ktElement.getResolutionFacade().frontendService<DeprecationResolver>()
|
||||
renderedDecl += renderDeprecationInfo(declarationDescriptor, deprecationProvider)
|
||||
renderedHtml += renderDeprecationInfo(declarationDescriptor, deprecationProvider)
|
||||
|
||||
if (!quickNavigation) {
|
||||
val comment = declarationDescriptor.findKDoc { DescriptorToSourceUtilsIde.getAnyDeclaration(ktElement.project, it) }
|
||||
if (comment != null) {
|
||||
val renderedComment = KDocRenderer.renderKDoc(comment)
|
||||
if (renderedComment.startsWith("<p>")) {
|
||||
renderedDecl += renderedComment
|
||||
}
|
||||
else {
|
||||
renderedDecl = "$renderedDecl<br/>$renderedComment"
|
||||
}
|
||||
renderedHtml += "${DocumentationMarkup.CONTENT_START}$renderedComment${DocumentationMarkup.CONTENT_END}"
|
||||
// if (renderedComment.startsWith("<p>")) {
|
||||
// renderedHtml += renderedComment
|
||||
// }
|
||||
// else {
|
||||
// renderedHtml = "$renderedHtml<br/>$renderedComment"
|
||||
// }
|
||||
}
|
||||
else {
|
||||
if (declarationDescriptor is CallableDescriptor) { // If we couldn't find KDoc, try to find javadoc in one of super's
|
||||
@@ -299,13 +342,13 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
|
||||
val javaDocInfoGenerator = JavaDocInfoGeneratorFactory.create(psi.project, lightElement)
|
||||
val builder = StringBuilder()
|
||||
if (javaDocInfoGenerator.generateDocInfoCore(builder, false))
|
||||
renderedDecl += builder.toString().substringAfter("</PRE>") // Cut off light method signature
|
||||
renderedHtml += builder.toString().substringAfter("</PRE>") // Cut off light method signature
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return renderedDecl
|
||||
return renderedHtml
|
||||
}
|
||||
|
||||
private fun renderDeprecationInfo(
|
||||
|
||||
Reference in New Issue
Block a user