fix(JavaDoc): Collapsed markdown comments with wrong suffixes

Not perfect at all, it should be able to rely on the commenter API instead.

GitOrigin-RevId: f41d181e9f27905bca1156912b7850f5a96ba943
This commit is contained in:
Mathias Boulay
2024-09-02 16:18:23 +02:00
committed by intellij-monorepo-bot
parent d4e45d6061
commit 286567da08
3 changed files with 86 additions and 1 deletions

View File

@@ -198,7 +198,19 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
final FoldingDescriptor commentDescriptor = CommentFoldingUtil.getCommentDescriptor(comment, document, processedComments,
element -> isCustomRegionElement(element),
isCollapseCommentByDefault(comment));
if (commentDescriptor != null) list.add(commentDescriptor);
if (commentDescriptor != null) {
if (comment instanceof PsiDocComment && ((PsiDocComment)comment).isMarkdownComment()) {
// Hack: Markdown comments aren't documented in the Commenter for the Java language
// To avoid the `/** */` tokens, we remove them
String placeHolderText = commentDescriptor.getPlaceholderText();
if (placeHolderText != null) {
placeHolderText = StringUtil.trimEnd(StringUtil.trimStart(placeHolderText, "/**"), "*/");
commentDescriptor.setPlaceholderText(placeHolderText);
}
}
list.add(commentDescriptor);
}
}
private static void addMethodGenericParametersFolding(@NotNull List<? super FoldingDescriptor> list,

View File

@@ -0,0 +1,71 @@
<fold text='/// outer class javadoc ...'>/// outer class javadoc
/// javadoc body</fold>
class Test {
<fold text='/// method javadoc ...'>/// method javadoc
/// javadoc body
///
/// @param i</fold>
void foo(int i) <fold text='{...}'>{
<fold text='/// method var javadoc ...'>/// method var javadoc
/// javadoc body</fold>
int j = i;
}</fold>
<fold text='/// first line ...'>/// first line
/// second line</fold>
void illFormedJavaDocMultilines() <fold text='{}'>{
}</fold>
<fold text='/// first line ...'>/// first line
///
///</fold>
void javaDocWithTextOnlyOnFirstLine() <fold text='{}'>{
}</fold>
<fold text='/// second line ...'>/// second line
///</fold>
void javaDocWithTextOnlyOnSecondLine() <fold text='{}'>{
}</fold>
<fold text='/// '>/// </fold>
void emptyJavadoc() <fold text='{}'>{
}</fold>
<fold text='/// dangling javadoc ...'>/// dangling javadoc
/// javadoc body</fold>
<fold text='/// inner class javadoc ...'>/// inner class javadoc
/// javadoc body</fold>
class Inner <fold text='{...}'>{
<fold text='/// javadoc for method in inner class ...'>/// javadoc for method in inner class
/// javadoc body</fold>
void foo() <fold text='{...}'>{
<fold text='/// javadoc for class in method ...'>/// javadoc for class in method
/// javadoc body</fold>
class MethodInner <fold text='{...}'>{
<fold text='/// javadoc for method inside class defined in method ...'>/// javadoc for method inside class defined in method
/// javadoc body</fold>
void bar() <fold text='{}'>{
}</fold>
}</fold>
}</fold>
}</fold>
}

View File

@@ -49,6 +49,8 @@ public class JavaFoldingTest extends JavaFoldingTestCase {
public void testJavadocComments() { doTest(); }
public void testJavadocMarkdownComments() { doTest(); }
public void testEditingImports() {
configure("""
import java.util.List;