Skip to content

Commit a4a91a8

Browse files
darthorimarintellij-monorepo-bot
authored andcommitted
[lsp] fix formatting of indented java doc
GitOrigin-RevId: 9a3df4002cb30f1c5ae2b5248bd842c900a3d0b6
1 parent 9cd7bca commit a4a91a8

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
package com.jetbrains.ls.api.features.impl.common.documentaiton
3+
4+
/**
5+
* Formats a given documentation comment string by cleaning up any extra spaces
6+
* and ensuring proper alignment for each line. Java/Kotlin-style comments are
7+
* expected.
8+
*/
9+
fun formatDocComment(docComment: String): String {
10+
val trimmedLines = docComment.trim().lines().map { it.trim() }.filter { it.isNotEmpty() }
11+
return trimmedLines.joinToString(separator = "\n") { if (it.startsWith("/*")) it else " $it" }
12+
}

features-impl/kotlin/src/com/jetbrains/ls/api/features/impl/common/kotlin/hover/LSMarkdownDocProviderKotlinImpl.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package com.jetbrains.ls.api.features.impl.common.kotlin.hover
33

44
import com.intellij.psi.PsiElement
5+
import com.jetbrains.ls.api.features.impl.common.documentaiton.formatDocComment
56
import com.jetbrains.ls.api.features.impl.common.hover.AbstractLSHoverProvider
67
import com.jetbrains.ls.api.features.impl.common.hover.markdownMultilineCode
78
import com.jetbrains.ls.api.features.impl.common.kotlin.language.LSKotlinLanguage
@@ -13,13 +14,8 @@ internal class LSMarkdownDocProviderKotlinImpl : AbstractLSHoverProvider.LSMarkd
1314
val ktElement = element.unwrapped as? KtDeclaration ?: return null
1415
val kdDocText = ktElement.docComment?.text ?: return null
1516
return markdownMultilineCode(
16-
kdDocText.formatKdoc(),
17+
formatDocComment(kdDocText),
1718
language = LSKotlinLanguage.lspName
1819
)
1920
}
20-
21-
private fun String.formatKdoc(): String {
22-
val trimmedLines = trim().lines().map { it.trim() }.filter { it.isNotEmpty() }
23-
return trimmedLines.joinToString(separator = "\n") { if (it.startsWith("/*")) it else " $it" }
24-
}
2521
}

0 commit comments

Comments
 (0)