Skip to content

fix(pretty_print): close a lone compact select item under select - #960

Open
psteinroe wants to merge 2 commits into
fix/pretty-print-cast-indentfrom
fix/pretty-print-compact-select-item
Open

psteinroe wants to merge 2 commits into
fix/pretty-print-cast-indentfrom
fix/pretty-print-compact-select-item

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

Stacked on #959.

With clauseBodyStyle: compact, a lone select item stays on the select line inside an indent kept for its continuation lines. #938 listed this as not covered. When the item only breaks inside its own parentheses, a function call for instance, it has no continuation lines, and the indent pushed its arguments two levels in and its ) one level in, under nothing. This is the same pattern #938 fixed for WHERE and ON:

-- clauseBodyStyle: compact
-- before
select json_build_object(
    'identifier', users.id,
    'display_name', users.name
  )
from users;
-- after
select json_build_object(
  'identifier', users.id,
  'display_name', users.name
)
from users;

What changed

The compact select list leaves out the indent for a lone item without an alias that is one of these:

Anything else keeps the indent, because it can continue on lines of its own: an alias (... as total can wrap), a FILTER clause, an operator chain such as a + b +\n c.

The FILTER layout

The other item, filter (where keeping where on the filter ( line with ) attached to the condition, was already fixed later in the stack:

count_star_stays_together_when_the_filter_breaks in function_call_layout.rs asserts it, so there is no separate change here.

Snapshot changes

All reviewed; one category: a lone call or subquery in a compact select list moves its arguments one level left and closes ) under select (compact_select_list*, scalar_subquery_expanded).

New test a_lone_compact_select_item_closes_under_select in subquery_layout.rs, covering a call and an operator chain that keeps its indent. The option matrix passes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant