KT-4519 Show first line with content of block comment when collapsed (#928)
This commit is contained in:
committed by
Dmitry Jemerov
parent
4669fb3ca7
commit
7d35316d95
@@ -97,12 +97,28 @@ class KotlinFoldingBuilder : CustomFoldingBuilder(), DumbAware {
|
||||
}
|
||||
|
||||
override fun getLanguagePlaceholderText(node: ASTNode, range: TextRange): String = when {
|
||||
node.elementType == KtTokens.BLOCK_COMMENT -> "/.../"
|
||||
node.elementType == KDocTokens.KDOC -> "/**...*/"
|
||||
node.elementType == KtTokens.BLOCK_COMMENT -> "/${getFirstLineOfComment(node)}.../"
|
||||
node.elementType == KDocTokens.KDOC -> "/**${getFirstLineOfComment(node)}...*/"
|
||||
node.psi is KtImportList -> "..."
|
||||
else -> "{...}"
|
||||
}
|
||||
|
||||
private fun getFirstLineOfComment(node: ASTNode): String {
|
||||
val targetCommentLine = node.text.split("\n").firstOrNull {
|
||||
getCommentContents(it).isNotEmpty()
|
||||
} ?: return ""
|
||||
return " ${getCommentContents(targetCommentLine)} "
|
||||
}
|
||||
|
||||
private fun getCommentContents(line: String): String {
|
||||
return line.trim()
|
||||
.replace("/**", "")
|
||||
.replace("/*", "")
|
||||
.replace("*/", "")
|
||||
.replace("*", "")
|
||||
.trim()
|
||||
}
|
||||
|
||||
override fun isRegionCollapsedByDefault(node: ASTNode): Boolean {
|
||||
val settings = JavaCodeFoldingSettings.getInstance()
|
||||
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
<fold text='/**...*/' expand='~false~'>/**
|
||||
<fold text='/** Some header kdoc ...*/' expand='~false~'>/**
|
||||
* Some header kdoc
|
||||
*/</fold>
|
||||
package some
|
||||
|
||||
<fold text='/**...*/' expand='true'>/**
|
||||
<fold text='/** Other ...*/' expand='true'>/**
|
||||
* Other
|
||||
*/</fold>
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<fold text='/.../' expand='~false~'>/*
|
||||
<fold text='/ Some header .../' expand='~false~'>/*
|
||||
* Some header
|
||||
*/</fold>
|
||||
|
||||
val a = 12
|
||||
|
||||
<fold text='/.../' expand='true'>/*
|
||||
<fold text='/ Other .../' expand='true'>/*
|
||||
* Other
|
||||
*/</fold>
|
||||
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
<fold text='/**...*/'>/**
|
||||
<fold text='/** Kdoc licence ...*/'>/**
|
||||
* Kdoc licence
|
||||
*/</fold>
|
||||
package some
|
||||
|
||||
<fold text='/**...*/'>/**
|
||||
<fold text='/** Some Kdoc comment ...*/'>/**
|
||||
* Some Kdoc comment
|
||||
*/</fold>
|
||||
class A
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
<fold text='/.../'>/*
|
||||
<fold text='/ Some multiline comment .../'>/*
|
||||
* Some multiline comment
|
||||
* And more comment
|
||||
*/</fold>
|
||||
class A
|
||||
Reference in New Issue
Block a user