@@ -5,22 +5,20 @@ import java.nio.file.Path
55import java.nio.file.Paths
66import java.security.MessageDigest
77import kotlin.contracts.ExperimentalContracts
8- import org.jetbrains.kotlin.KtLightSourceElement
98import org.jetbrains.kotlin.KtSourceElement
109import org.jetbrains.kotlin.KtSourceFile
11- import org.jetbrains.kotlin.com.intellij.lang.LighterASTNode
1210import org.jetbrains.kotlin.com.intellij.lang.java.JavaLanguage
13- import org.jetbrains.kotlin.com.intellij.openapi.util.Ref
14- import org.jetbrains.kotlin.com.intellij.util.diff.FlyweightCapableTreeStructure
1511import org.jetbrains.kotlin.fir.FirElement
16- import org.jetbrains.kotlin.fir.render
12+ import org.jetbrains.kotlin.fir.analysis.getChild
13+ import org.jetbrains.kotlin.fir.renderer.*
1714import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
1815import org.jetbrains.kotlin.fir.symbols.SymbolInternals
1916import org.jetbrains.kotlin.fir.symbols.impl.*
2017import org.jetbrains.kotlin.fir.types.ConeClassLikeType
2118import org.jetbrains.kotlin.idea.KotlinLanguage
2219import org.jetbrains.kotlin.lexer.KtTokens
2320import org.jetbrains.kotlin.psi
21+ import org.jetbrains.kotlin.text
2422
2523@ExperimentalContracts
2624class SemanticdbTextDocumentBuilder (
@@ -84,7 +82,7 @@ class SemanticdbTextDocumentBuilder(
8482 return SymbolInformation {
8583 this .symbol = symbol.toString()
8684 this .displayName = displayName(firBasedSymbol)
87- this .documentation = semanticdbDocumentation(firBasedSymbol.fir, element )
85+ this .documentation = semanticdbDocumentation(firBasedSymbol.fir)
8886 this .addAllOverriddenSymbols(supers)
8987 this .language =
9088 when (element.psi?.language ? : KotlinLanguage .INSTANCE ) {
@@ -127,35 +125,23 @@ class SemanticdbTextDocumentBuilder(
127125 .digest(file.getContentsAsStream().readBytes())
128126 .joinToString(" " ) { " %02X" .format(it) }
129127
130- private fun semanticdbDocumentation (
131- element : FirElement ,
132- source : KtSourceElement
133- ): Semanticdb .Documentation = Documentation {
128+ private fun semanticdbDocumentation (element : FirElement ): Semanticdb .Documentation = Documentation {
134129 format = Semanticdb .Documentation .Format .MARKDOWN
135- val renderOutput = element.render()
136- val kdoc = getKDocFromKtLightSourceElement(source as ? KtLightSourceElement ) ? : " "
137- message = " ```\n $renderOutput \n ```\n ${stripKDocAsterisks(kdoc)} "
138- }
139-
140- private fun getKDocFromKtLightSourceElement (
141- lightSourceElement : KtLightSourceElement ?
142- ): String? {
143- if (lightSourceElement == null ) return null
144- val tree = lightSourceElement.treeStructure // FlyweightCapableTreeStructure<LighterASTNode>
145- val node =
146- lightSourceElement.lighterASTNode // LighterASTNode, the root of the element's structure
147- return findKDoc(tree, node)
148- }
149-
150- // Helper function to find the KDoc node in the AST
151- private fun findKDoc (
152- tree : FlyweightCapableTreeStructure <LighterASTNode >,
153- node : LighterASTNode
154- ): String? {
155- // Recursively traverse the light tree to find a DOC_COMMENT node
156- val kidsRef = Ref <Array <LighterASTNode ?>>()
157- tree.getChildren(node, kidsRef)
158- return kidsRef.get().singleOrNull { it?.tokenType == KtTokens .DOC_COMMENT }?.toString()
130+ // Like FirRenderer().forReadability, but using FirAllModifierRenderer instead of FirPartialModifierRenderer
131+ val renderer = FirRenderer (
132+ typeRenderer = ConeTypeRenderer (),
133+ idRenderer = ConeIdShortRenderer (),
134+ classMemberRenderer = FirNoClassMemberRenderer (),
135+ bodyRenderer = null ,
136+ propertyAccessorRenderer = null ,
137+ callArgumentsRenderer = FirCallNoArgumentsRenderer (),
138+ modifierRenderer = FirAllModifierRenderer (),
139+ valueParameterRenderer = FirValueParameterRendererForReadability (),
140+ declarationRenderer = FirDeclarationRenderer (" local " ),
141+ )
142+ val renderOutput = renderer.renderElementAsString(element)
143+ val kdoc = element.source?.getChild(KtTokens .DOC_COMMENT )?.text?.toString() ? : " "
144+ message = " ```kotlin\n $renderOutput \n ```${stripKDocAsterisks(kdoc)} "
159145 }
160146
161147 // Returns the kdoc string with all leading and trailing "/*" tokens removed. Naive
0 commit comments