Skip to content

Add SQL query formatter/prettifier (Ctrl+Shift+F)#41

Open
muk2 wants to merge 2 commits intomainfrom
feature/issue-33-sql-formatter
Open

Add SQL query formatter/prettifier (Ctrl+Shift+F)#41
muk2 wants to merge 2 commits intomainfrom
feature/issue-33-sql-formatter

Conversation

@muk2
Copy link
Owner

@muk2 muk2 commented Feb 19, 2026

Summary

Implements #33 — adds a built-in SQL query formatter that auto-formats messy or one-line SQL into well-indented, readable SQL directly in the editor.

  • New ast::formatter module with format_sql() function that pretty-prints Query AST nodes
  • Shortcut: Ctrl+Shift+F in the editor formats the entire buffer
  • Multi-line formatting: Each major SQL clause on its own line (SELECT, FROM, WHERE, JOIN, GROUP BY, HAVING, ORDER BY, LIMIT, OFFSET)
  • Indented projections: Multi-column SELECT lists get one column per line with proper indentation
  • JOIN formatting: JOIN conditions indented under their JOIN clause
  • All query types: SELECT, INSERT, UPDATE, DELETE, CTEs, UNION/INTERSECT/EXCEPT
  • Non-destructive: Shows toast error if SQL can't be parsed; buffer unchanged
  • Single undo step: Ctrl+Z reverts the entire format operation
  • 16 new unit tests including round-trip reparse verification ensuring formatted SQL is always valid

Example

Before (single line):

SELECT u.id, u.name, o.total FROM users u JOIN orders o ON u.id = o.user_id WHERE o.total > 100 ORDER BY o.total DESC LIMIT 10

After (Ctrl+Shift+F):

SELECT
    u.id,
    u.name,
    o.total
FROM users AS u
JOIN orders AS o
    ON u.id = o.user_id
WHERE o.total > 100
ORDER BY o.total DESC
LIMIT 10

Test plan

  • cargo build compiles without warnings
  • cargo test — all 232 tests pass (16 new formatter tests)
  • Formatter produces valid SQL (round-trip reparse test)
  • Multi-column SELECT indentation
  • JOIN/WHERE/GROUP BY/ORDER BY each on own line
  • CTE formatting
  • INSERT/UPDATE/DELETE formatting
  • Help overlay shows new shortcut

Closes #33

🤖 Generated with Claude Code

muk2 and others added 2 commits February 19, 2026 22:36
Adds a built-in SQL pretty-printer that formats messy queries into
well-indented, readable SQL using the existing AST parse→compile
pipeline. Triggered via Ctrl+Shift+F in the editor.

- New `ast::formatter` module with `format_sql()` function
- Multi-line output: each SQL clause (SELECT, FROM, WHERE, JOIN,
  GROUP BY, ORDER BY, LIMIT, OFFSET) on its own line
- Indented column lists for multi-column SELECT
- JOIN conditions indented under their JOIN clause
- Supports all query types: SELECT, INSERT, UPDATE, DELETE, CTEs
- Non-destructive: shows toast error on parse failure
- Single undo step to revert formatting
- 16 unit tests including round-trip reparse verification
- Help overlay updated with new shortcut

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolve merge conflicts in app.rs and components.rs by keeping both
the SQL formatter feature and autocomplete additions from main.
Run cargo fmt for consistent formatting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Feature: SQL Query Formatter / Prettifier

1 participant