@@ -5,22 +5,20 @@ import java.nio.file.Path
5
5
import java.nio.file.Paths
6
6
import java.security.MessageDigest
7
7
import kotlin.contracts.ExperimentalContracts
8
- import org.jetbrains.kotlin.KtLightSourceElement
9
8
import org.jetbrains.kotlin.KtSourceElement
10
9
import org.jetbrains.kotlin.KtSourceFile
11
- import org.jetbrains.kotlin.com.intellij.lang.LighterASTNode
12
10
import 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
15
11
import 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.*
17
14
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
18
15
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
19
16
import org.jetbrains.kotlin.fir.symbols.impl.*
20
17
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
21
18
import org.jetbrains.kotlin.idea.KotlinLanguage
22
19
import org.jetbrains.kotlin.lexer.KtTokens
23
20
import org.jetbrains.kotlin.psi
21
+ import org.jetbrains.kotlin.text
24
22
25
23
@ExperimentalContracts
26
24
class SemanticdbTextDocumentBuilder (
@@ -84,7 +82,7 @@ class SemanticdbTextDocumentBuilder(
84
82
return SymbolInformation {
85
83
this .symbol = symbol.toString()
86
84
this .displayName = displayName(firBasedSymbol)
87
- this .documentation = semanticdbDocumentation(firBasedSymbol.fir, element )
85
+ this .documentation = semanticdbDocumentation(firBasedSymbol.fir)
88
86
this .addAllOverriddenSymbols(supers)
89
87
this .language =
90
88
when (element.psi?.language ? : KotlinLanguage .INSTANCE ) {
@@ -127,35 +125,23 @@ class SemanticdbTextDocumentBuilder(
127
125
.digest(file.getContentsAsStream().readBytes())
128
126
.joinToString(" " ) { " %02X" .format(it) }
129
127
130
- private fun semanticdbDocumentation (
131
- element : FirElement ,
132
- source : KtSourceElement
133
- ): Semanticdb .Documentation = Documentation {
128
+ private fun semanticdbDocumentation (element : FirElement ): Semanticdb .Documentation = Documentation {
134
129
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)} "
159
145
}
160
146
161
147
// Returns the kdoc string with all leading and trailing "/*" tokens removed. Naive
0 commit comments