fix(body): prevent joining continuation lines to comments
CI / Test (push) Failing after 24s
CI / Build (push) Has been skipped

* Ensure comment-only lines are flushed before adding new statements
* Adjust logic to handle col-0 continuation lines correctly
This commit is contained in:
2026-06-30 22:51:25 +02:00
parent c8030247f2
commit f17e87e749
2 changed files with 246 additions and 164 deletions
+24
View File
@@ -471,6 +471,30 @@ func formatBodyStatements(text string, st config.Style) string {
fw := lowerASCII(firstBodyKeyword(stripped))
isColZero := indent == ""
joinToPrev := isColZero && parenDepth == 0 && len(stmt) > 0 && !sqlClauseKw[fw]
// Don't join a col-0 continuation to a comment-only preceding bline:
// the comment has no structural keyword so `continue ;` at col-0 would
// disappear into the comment text and be invisible to the lexer.
if joinToPrev {
if lowerASCII(firstBodyKeyword(stmt[len(stmt)-1].text)) == "" {
joinToPrev = false
}
}
// Pre-flush pending comment-only blines before adding a new non-comment
// non-joined bline. Without this, a comment + `end if;` end up in the
// same stmt, `fw` comes from the comment (empty string), depth is never
// decremented, and the formatter diverges on the second pass.
if !joinToPrev && fw != "" && len(stmt) > 0 {
allComments := true
for _, ll := range stmt {
if lowerASCII(firstBodyKeyword(ll.text)) != "" {
allComments = false
break
}
}
if allComments {
flush()
}
}
if joinToPrev {
last := &stmt[len(stmt)-1]