KT-22815: Position deprecated section between definition and description
This commit is contained in:
@@ -20,8 +20,7 @@ import com.google.common.html.HtmlEscapers
|
|||||||
import com.intellij.codeInsight.documentation.DocumentationManagerUtil
|
import com.intellij.codeInsight.documentation.DocumentationManagerUtil
|
||||||
import com.intellij.codeInsight.javadoc.JavaDocInfoGeneratorFactory
|
import com.intellij.codeInsight.javadoc.JavaDocInfoGeneratorFactory
|
||||||
import com.intellij.lang.documentation.AbstractDocumentationProvider
|
import com.intellij.lang.documentation.AbstractDocumentationProvider
|
||||||
import com.intellij.lang.documentation.DocumentationMarkup.DEFINITION_END
|
import com.intellij.lang.documentation.DocumentationMarkup.*
|
||||||
import com.intellij.lang.documentation.DocumentationMarkup.DEFINITION_START
|
|
||||||
import com.intellij.lang.java.JavaDocumentationProvider
|
import com.intellij.lang.java.JavaDocumentationProvider
|
||||||
import com.intellij.openapi.diagnostic.Logger
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
@@ -346,8 +345,10 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
|
|||||||
return KDocTemplate().apply {
|
return KDocTemplate().apply {
|
||||||
definition {
|
definition {
|
||||||
renderDefinition(declarationDescriptor, DESCRIPTOR_RENDERER)
|
renderDefinition(declarationDescriptor, DESCRIPTOR_RENDERER)
|
||||||
renderDeprecationInfo(declarationDescriptor, deprecationProvider)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
insertDeprecationInfo(declarationDescriptor, deprecationProvider)
|
||||||
|
|
||||||
if (!quickNavigation) {
|
if (!quickNavigation) {
|
||||||
description {
|
description {
|
||||||
val comment = declarationDescriptor.findKDoc { DescriptorToSourceUtilsIde.getAnyDeclaration(ktElement.project, it) }
|
val comment = declarationDescriptor.findKDoc { DescriptorToSourceUtilsIde.getAnyDeclaration(ktElement.project, it) }
|
||||||
@@ -420,25 +421,26 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun StringBuilder.renderDeprecationInfo(
|
private fun KDocTemplate.insertDeprecationInfo(
|
||||||
declarationDescriptor: DeclarationDescriptor,
|
declarationDescriptor: DeclarationDescriptor,
|
||||||
deprecationResolver: DeprecationResolver
|
deprecationResolver: DeprecationResolver
|
||||||
) {
|
) {
|
||||||
val deprecation = deprecationResolver.getDeprecations(declarationDescriptor).firstOrNull() ?: return
|
val deprecationInfo = deprecationResolver.getDeprecations(declarationDescriptor).firstOrNull() ?: return
|
||||||
|
|
||||||
|
deprecation {
|
||||||
wrapTag("DL") {
|
deprecationInfo.message?.let { message ->
|
||||||
deprecation.message?.let { message ->
|
append(SECTION_HEADER_START)
|
||||||
wrapTag("DT") { wrapTag("b") { append("Deprecated:") } }
|
append("Deprecated:")
|
||||||
wrapTag("DD") {
|
append(SECTION_SEPARATOR)
|
||||||
append(message.htmlEscape())
|
append(message.htmlEscape())
|
||||||
}
|
append(SECTION_END)
|
||||||
}
|
}
|
||||||
deprecation.deprecatedByAnnotationReplaceWithExpression()?.let { replaceWith ->
|
deprecationInfo.deprecatedByAnnotationReplaceWithExpression()?.let { replaceWith ->
|
||||||
wrapTag("DT") { wrapTag("b") { append("Replace with:") } }
|
append(SECTION_HEADER_START)
|
||||||
wrapTag("DD") {
|
append("Replace with:")
|
||||||
wrapTag("code") { append(replaceWith.htmlEscape()) }
|
append(SECTION_SEPARATOR)
|
||||||
}
|
wrapTag("code") { append(replaceWith.htmlEscape()) }
|
||||||
|
append(SECTION_END)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,19 @@ open class KDocTemplate : Template<StringBuilder> {
|
|||||||
|
|
||||||
val description = Placeholder<StringBuilder>()
|
val description = Placeholder<StringBuilder>()
|
||||||
|
|
||||||
|
val deprecation = Placeholder<StringBuilder>()
|
||||||
|
|
||||||
override fun StringBuilder.apply() {
|
override fun StringBuilder.apply() {
|
||||||
append(DEFINITION_START)
|
append(DEFINITION_START)
|
||||||
insert(definition)
|
insert(definition)
|
||||||
append(DEFINITION_END)
|
append(DEFINITION_END)
|
||||||
|
|
||||||
|
if (!deprecation.isEmpty()) {
|
||||||
|
append(SECTIONS_START)
|
||||||
|
insert(deprecation)
|
||||||
|
append(SECTIONS_END)
|
||||||
|
}
|
||||||
|
|
||||||
insert(description)
|
insert(description)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user