Skip to content

chore: initial pretty printer #546

Merged
psteinroe merged 12 commits intomainfrom
feat/pretty-print-try-2
Feb 1, 2026
Merged

chore: initial pretty printer #546
psteinroe merged 12 commits intomainfrom
feat/pretty-print-try-2

Conversation

@psteinroe
Copy link
Copy Markdown
Collaborator

@psteinroe psteinroe commented Oct 2, 2025

for the review: if you skip the nodes/ dir as well as the snapshot tests, the size of this pr is manageable. I makes sense to read through the renderer and how layout events work, as well as the integration of it in the language server and the cli.

@psteinroe psteinroe force-pushed the feat/pretty-print-try-2 branch from 4c5072f to c7d27e6 Compare October 30, 2025 19:08
@psteinroe psteinroe mentioned this pull request Dec 9, 2025
@psteinroe psteinroe changed the title chore: pretty-print poc attempt 2 chore: initial pretty printer Dec 31, 2025
@psteinroe psteinroe force-pushed the feat/pretty-print-try-2 branch from 6ede0e1 to 0c40983 Compare January 6, 2026 08:23
@psteinroe psteinroe marked this pull request as ready for review January 6, 2026 09:53
Copy link
Copy Markdown
Collaborator

@juleswritescode juleswritescode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first round of comments in case github dies — will now take a look at the pretty_print modules

Comment thread scripts/pp-status.sh Outdated
Comment thread scripts/pp-hook.sh Outdated
Comment thread justfile Outdated
Comment thread crates/pgls_workspace/src/matcher/mod.rs
Comment thread crates/pgls_statement_splitter/src/splitter/common.rs
Comment thread crates/pgls_splinter/src/lib.rs Outdated
Comment thread crates/pgls_pretty_print/nodes.txt Outdated
Comment thread crates/pgls_pretty_print/src/lib.rs
@@ -0,0 +1,1223 @@
//! AST normalization for semantic comparison.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sehr cool — wie würden wir mitbekommen, wenn sich die interne AST representation bei nem pg_query upgrade ändert? gibt's dafür regression tests oder sowas?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guter Punkt. Werde mir was überlegen. Vllt nen snapshot der Generation oder so

Comment thread crates/pgls_pretty_print/tests/data/multi/comments.sql
psteinroe and others added 11 commits January 26, 2026 17:49
- Add pgls_pretty_print and pgls_pretty_print_codegen crates
- Implement SQL formatting with configurable keyword casing
- Support keyword_case and constant_case settings (default: lowercase)
- Integrate format command into CLI
- Add LSP formatting handler
…rinter

- Use dollar quotes for function/procedure bodies instead of single quotes
- Add DollarQuoteHint enum to select context-appropriate delimiters
  ($function$ for functions, $procedure$ for procedures, $do$ for DO blocks)
- Handle nested dollar quotes by falling back to alternative delimiters
- Use emit_identifier_maybe_quoted for identifiers that don't need quoting
  (lowercase names without special characters or reserved keywords)
- Add tests for dollar quoted functions, nested dollar quotes, and
  lowercase/quoted table identifiers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
CREATE TRIGGER was indenting all its clauses (BEFORE, ON, FOR EACH, EXECUTE)
while similar DDL statements like CREATE FUNCTION and CREATE EVENT TRIGGER
did not indent their clauses. This creates inconsistency in the output.

Remove indent_start/indent_end wrapping to match the style used by other
DDL statements.
The branch was missing the splinter options feature (ignore patterns for
rules) and the pgls_matcher crate that was added in main after the
branch diverged. This restores those files to sync with main.
- Update build.rs to use Rust 2024 inline format strings
- Handle both INT_MAX (2147483647) and LLONG_MAX for FETCH ALL detection
  to support cross-platform consistency
The pg_query parser library handles integer overflow differently on Windows
vs Linux/macOS, causing snapshot mismatches in edge cases like:
- $2147483648 (INT_MAX + 1) becomes $2147483647 on Windows
- FETCH FORWARD ALL using INT_MAX vs LLONG_MAX

These are parser library limitations, not pretty printer bugs.
@psteinroe psteinroe force-pushed the feat/pretty-print-try-2 branch 5 times, most recently from 9b3ad47 to 580a215 Compare January 26, 2026 17:31
- Add test to verify all AST nodes with location fields are handled in normalize.rs
- Document known limitation: comments are removed during formatting
- Clean up unused scripts and files
@psteinroe psteinroe force-pushed the feat/pretty-print-try-2 branch from 580a215 to 3d86b6e Compare January 26, 2026 17:46
@psteinroe psteinroe merged commit 6e2677c into main Feb 1, 2026
9 checks passed
@psteinroe psteinroe deleted the feat/pretty-print-try-2 branch February 1, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants