chore: more work done and planning with AI.
This commit is contained in:
@@ -161,6 +161,83 @@ Legend: ✅ done · 🚧 in progress · ⬜ not started
|
||||
- _Still TODO: Wadler Doc-IR printer for width-aware wrapping of long lines._
|
||||
- _Still TODO: LSP range formatting._
|
||||
|
||||
## ✅ Config expansion — DataGrip settings parity
|
||||
|
||||
Reference: `PostgresCodeStyleSettings` mapping in `docs/plan.md`.
|
||||
|
||||
### ✅ Extended `pkg/config` fields
|
||||
|
||||
Added to `Style` struct, `yamlFile`, and `Load()` in `pkg/config/config.go`:
|
||||
|
||||
- New types: `WrapMode` (`always`|`when_long`|`never`), `Placement` (`same_line`|`new_line`)
|
||||
- **Casing**: `AliasCase`, `BuiltinCase`, `CustomTypeCase` — all default `lower`
|
||||
- **Query layout**: `AlignColumns`, `AlignLineComments`, `SelectAlignAs`, `SetAlignEqual`,
|
||||
`IndentJoin`, `JoinIndentSize`, `WhereWrap`, `WhereAndOrIndent`
|
||||
- **Subqueries**: `SubqueryOpening`, `SubqueryContent`, `SubqueryClosing`, `SubquerySpaceBeforeParen`
|
||||
- **INSERT**: `InsertCollapseValues`
|
||||
- **Routines**: `AlignParamTypes`, `RoutineAsWrap`
|
||||
- **PL/pgSQL**: `PlpgsqlMaxBlankLines`, `PlpgsqlDeclareAlignType`, `PlpgsqlDeclareAlignEq`,
|
||||
`PlpgsqlIfThenNewline`, `PlpgsqlLoopCollapse`
|
||||
- **Expressions**: `BinaryOpAlign`, `SpaceAfterCommaInCalls`, `CaseWhenWrap`, `CaseEnd`,
|
||||
`CaseCollapse`, `RecordSpaceBeforeParen`
|
||||
- `docs/config/default.pgtidy.yaml` updated with all new keys and comments.
|
||||
|
||||
### ✅ Casing engine — alias and built-in classification
|
||||
|
||||
`pkg/format/keywords.go`: added `builtinFunctions` set (COALESCE, MAX, MIN, NOW, …).
|
||||
`pkg/format/format.go`: `caseTextCtx` uses context — `prev` token and `nextIsLParen` flag
|
||||
to route ident tokens through `AliasCase` (after AS) or `BuiltinCase` (before `(`).
|
||||
`inline()` and `dmlInline()` pass context to `caseTextCtx`.
|
||||
|
||||
### ✅ Formatter — query layout settings (`pkg/format/dml.go`)
|
||||
|
||||
- `indent_join` + `join_indent_size`: JOIN clause indented by `JoinIndentSize × Indent`.
|
||||
- `where_wrap` + `where_and_or_indent`: `dmlWhereClause` splits AND/OR conditions; `always`
|
||||
puts each condition on its own line indented under WHERE; `never` keeps inline.
|
||||
- `set_align_equal`: `dmlColListSet` pads LHS of SET items so `=` signs align.
|
||||
- `align_columns` + `select_align_as`: `dmlColListSelect` + `alignSelectItems` pads
|
||||
SELECT expressions so AS keywords and aliases align vertically.
|
||||
- `space_after_comma_in_calls` applied in `dmlInline`.
|
||||
- `binary_op_align` registered in config (enforcement in WHERE/expression context deferred).
|
||||
|
||||
### ⬜ Formatter — subquery formatting
|
||||
|
||||
`subquery_opening/content/closing/space_before_paren` fields are wired in config.
|
||||
Enforcement in `dml.go` is not yet implemented — subqueries use current CTE formatting
|
||||
as a proxy (new_line for content, inline for single-arg subexpressions).
|
||||
|
||||
### ⬜ Formatter — INSERT VALUES collapse
|
||||
|
||||
`insert_collapse_values` field is wired in config. Enforcement in `dml.go` not yet implemented.
|
||||
|
||||
### ✅ Formatter — routine param alignment (`pkg/format/format.go`)
|
||||
|
||||
- `align_param_types`: `alignParamTypes()` pads param names so type columns align; default `true`.
|
||||
- `routine_as_wrap`: when `false`, AS stays on the same line as the last option clause.
|
||||
- Golden file `testdata/corpus/test_a.pgsql` updated to reflect aligned params.
|
||||
|
||||
### ✅ Formatter — PL/pgSQL body settings (`pkg/format/body.go`)
|
||||
|
||||
- `plpgsql_max_blank_lines`: blank-line runs capped at the configured limit; default `1`.
|
||||
- `plpgsql_declare_align_type` + `plpgsql_declare_align_eq`: two-pass declare formatter
|
||||
measures name/type widths then pads for alignment; `writeDeclareAligned` helper.
|
||||
- `plpgsql_if_then_newline`: when `false`, `joinThenToCondition` merges THEN onto the
|
||||
preceding condition line.
|
||||
- `plpgsql_loop_collapse`: `tryCollapseLoop` detects empty FOR/WHILE loop bodies and
|
||||
collapses them to one line.
|
||||
- CRLF normalization in trivia emission (comment text, body trivia before DECLARE).
|
||||
|
||||
### ⬜ Formatter — expression settings (case_when_wrap, case_end, case_collapse, record_space_before_paren)
|
||||
|
||||
Config fields wired. Expression-level CASE/ROW formatting not yet implemented.
|
||||
|
||||
### ⬜ DataGrip XML import/export (optional, V4+)
|
||||
|
||||
`pgtidy config import --datagrip <settings.xml>` / `pgtidy config export --datagrip`
|
||||
not implemented.
|
||||
|
||||
---
|
||||
|
||||
## Open risks
|
||||
- `go-pgquery` tracks PG17 (not PG18) — fine for lint; irrelevant to formatter path.
|
||||
- Leading-comma + one-per-line is a first-class style option, not an afterthought.
|
||||
|
||||
Reference in New Issue
Block a user