diff --git a/xls/dslx/fmt/ast_fmt.cc b/xls/dslx/fmt/ast_fmt.cc index fc6d834220..9a4cf9d3d0 100644 --- a/xls/dslx/fmt/ast_fmt.cc +++ b/xls/dslx/fmt/ast_fmt.cc @@ -3009,10 +3009,14 @@ absl::StatusOr Formatter::Format(const Module& n) { } for (const CommentData* comment : comments_.GetComments(span)) { if (!comments_.WasPlaced(comment)) { + const std::string& comment_text = + std::string{absl::StripTrailingAsciiWhitespace(comment->text)}; return absl::InternalError(absl::StrFormat( - "Comment at %s was deleted by the formatter: //%sThis is " - "probably due to a bug.", - comment->span.ToString(arena_.file_table()), comment->text)); + "Formatting was skipped because a comment at %s would be " + "deleted by the formatter: //%s\nThis is probably due to a bug " + "(which may not have been reported yet). To complete formatting, " + "try moving the comment to a different line.", + comment->span.ToString(arena_.file_table()), comment_text)); } } } diff --git a/xls/dslx/fmt/ast_fmt_test.cc b/xls/dslx/fmt/ast_fmt_test.cc index 853281568c..c405c4e32e 100644 --- a/xls/dslx/fmt/ast_fmt_test.cc +++ b/xls/dslx/fmt/ast_fmt_test.cc @@ -3056,7 +3056,7 @@ proc A { let _my_grand_finale_here = true; } })", - "was deleted"); + "would be deleted"); } TEST_F(ModuleFmtTest, BinopWithCommentBeforeOpNoNewline) {