fmt: preserve ') VALUES (' seams and !=/<> operator spellings - #4597
Open
kyleconroy wants to merge 1 commit into
Open
fmt: preserve ') VALUES (' seams and !=/<> operator spellings#4597kyleconroy wants to merge 1 commit into
kyleconroy wants to merge 1 commit into
Conversation
Two formatting fixes reported from running sqlc fmt on a real project:
The boundary before a bare VALUES list was decided by comparing the
source lines of the neighbouring nodes (the last column and the first
value), which always differ when both paren lists are multi-line — so
an authored ') VALUES (' seam broke apart. The seam now gets its own
group, and AttachComments reads the author's actual choice out of the
source by scanning back from the first value across '(' and the VALUES
keyword.
The parsers normalized inequality spellings: PostgreSQL's grammar turns
!= into <>, and the MySQL converter mapped opcode.NE to != regardless
of what was written. The format parsers now read the author's spelling
back out of the source — PostgreSQL via a new NewFormatParser that
rewrites A_Expr names at the operator's recorded location, MySQL via
the same source-scan approach SQLite already used. The compiler's
parsers keep the canonical names.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T4UpYmwPdxzePtsRXoL1H8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two formatting fixes found by running
sqlc fmton a real project (sqlc-dev/cloud#604).) VALUES (seams broke apartThe boundary before a bare VALUES list was decided by comparing the source lines of the neighbouring nodes — the last column name and the first value. When both paren lists are multi-line those always sit on different lines, so an authored seam was forced apart:
The seam now gets its own layout group in
InsertStmt.Format, andAttachCommentsreads the author's actual choice out of the source: scanning back from the first value across(and theVALUESkeyword, the whitespace in front of the keyword says whether the author broke the line. Glued stays glued;VALUESon its own line stays on its own line. Source that doesn't scan cleanly (an extra paren, a comment against the keyword) falls back to the old heuristic.!=and<>were rewritten to each otherPostgreSQL's grammar normalizes
!=to<>before the AST exists, so fmt printed<>for authors who wrote!=. The MySQL converter mappedopcode.NEto!=unconditionally, rewriting in the other direction. Both format parsers now read the author's spelling back out of the source, the same way the SQLite converter already did:NewFormatParserthat rewritesA_Exprnames at the operator's recorded location (theA_Exprlocation points at the operator token). The compiler keeps usingNewParser, which preserves the canonical<>the catalog knows.Testing
internal/endtoend/testdata/fmt/{postgresql,mysql}with a multi-line) VALUES (INSERT, a broken-seam INSERT, and mixed!=/<>queries; regenerated goldens. The new cases produce no diff hunks — fmt leaves them exactly as written.TestReplay/basecorpus andTestFormatpass.sqlc fmtidempotent on the result.🤖 Generated with Claude Code
https://claude.ai/code/session_01T4UpYmwPdxzePtsRXoL1H8
Generated by Claude Code