From 300fb84a9ff019091d1b59c96f2ee284676530c2 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 20 Jun 2023 15:16:25 -0700 Subject: [PATCH] Fix single-line comments. --- core/src/main/java/org/lflang/ast/FormattingUtil.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/lflang/ast/FormattingUtil.java b/core/src/main/java/org/lflang/ast/FormattingUtil.java index 0f28a8dca4..cb20df533f 100644 --- a/core/src/main/java/org/lflang/ast/FormattingUtil.java +++ b/core/src/main/java/org/lflang/ast/FormattingUtil.java @@ -127,12 +127,13 @@ static String lineWrapComments(List comments, int width, String singleLi } /** Wrap lines. Do not merge lines that start with weird characters. */ private static String lineWrapComment(String comment, int width, String singleLineCommentPrefix) { - if (!MULTILINE_COMMENT.matcher(comment).matches()) return comment; + comment = + comment + .strip() + .replaceAll("^/?((\\*|//|#)\\s*)+", ""); + if (!MULTILINE_COMMENT.matcher(comment).matches()) return comment.isBlank() ? "" : singleLineCommentPrefix + " " + comment; width = Math.max(width, MINIMUM_COMMENT_WIDTH_IN_COLUMNS); - var stripped = - comment - .strip() - .replaceAll("^/?((\\*|//|#)\\s*)+", "") + var stripped = comment .replaceAll("\\s*\\*/$", "") .replaceAll("(?<=(\\r\\n|\\r|\\n))\\h*(\\*|//|#)\\h?(\\h*)", "$3"); var preformatted = false;