Conversation
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.
What
A new
layoutoption:layout"fit""fit","expanded"fit- today's behaviour: a clause breaks only when the line would exceedlineWidth.expanded-SELECTtarget lists, joins andINSERTcolumn lists always break, whatever the line width.Joins each get their own line:
INSERTwith a CTE:Why
With
fit, whether a query is one line or ten depends on how long its identifiers happen to be.Two queries with the same shape can be formatted differently, and adding a column can reflow an entire statement.
expandedmakes the printed shape a function of the query structure alone, which keeps diffs minimal and reviewable - the property people want from a formatter in a versioned SQL repository.Implementation
A
clause_break(e)helper innodes/mod.rsemits a hard break underexpandedand a soft one underfit.select_stmt.rs,join_expr.rsandinsert_stmt.rscall it where they previously emitted a soft line.No new renderer state.
Wiring:
pgls_configuration(--layout),pgls_workspacesettings,docs/features/formatting.md,docs/schema.json.Tests
Three new fixtures snapshotted at widths 80 and 100 - identical at both widths, which is exactly the property
expandedpromises.The two preparatory commits
The first two commits of this PR are shared, byte for byte, with the three other formatter-option PRs open alongside it:
commaStyle/logicalOperatorPlacementclauseBodyStyle/isolateSemicoloncastStyleThe shared commits are:
test(pretty-print): allow per-fixture format configurationrefactor(pretty-print): thread the format config into the emitterThey are carried in each PR so every option remains independently reviewable and mergeable.
Whichever PR lands first, I will rebase the other three to remove the duplicate commits.
Merge them in whatever order suits you; nothing here depends on the others.