Skip to content

Commit

Permalink
Update error message to be more actionable when a comment was deleted…
Browse files Browse the repository at this point in the history
… by the formatter.

PiperOrigin-RevId: 708426663
  • Loading branch information
dplassgit authored and copybara-github committed Dec 20, 2024
1 parent 7316917 commit 1554191
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions xls/dslx/fmt/ast_fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3009,10 +3009,14 @@ absl::StatusOr<DocRef> 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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion xls/dslx/fmt/ast_fmt_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3056,7 +3056,7 @@ proc A {
let _my_grand_finale_here = true;
}
})",
"was deleted");
"would be deleted");
}

TEST_F(ModuleFmtTest, BinopWithCommentBeforeOpNoNewline) {
Expand Down

0 comments on commit 1554191

Please sign in to comment.