diff --git a/CLAUDE.md b/CLAUDE.md index 20e5b85..6b676e1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -33,7 +33,7 @@ This is a Cargo workspace with five crates: - **postgres-lsp-parse** — Document model with tree-sitter incremental parsing, parser pool, and PL/pgSQL injection handling. Core types: `Document`, `ParserPool`. - **postgres-lsp-analysis** — Symbol extraction from parse trees, `DashMap`-backed workspace index, name resolution, completion, and hover logic. Core types: `Symbol`, `SymbolKind`, `QualifiedName`, `WorkspaceIndex`. - **postgres-lsp-schema** — Optional live database introspection via `tokio-postgres` against `pg_catalog` (Phase 7). -- **postgres-lsp-format** — SQL formatting powered by [libpgfmt](https://crates.io/crates/libpgfmt). Supports 7 styles (River, Mozilla, Aweber, Dbt, Gitlab, Kickstarter, Mattmc3). Public API: `format_sql(source, options)` and `FormatOptions { style }`. +- **postgres-lsp-format** — SQL formatting powered by [libpgfmt](https://crates.io/crates/libpgfmt). Supports 8 styles (River, Mozilla, Aweber, Dbt, Gitlab, Kickstarter, Mattmc3, PgDump). Public API: `format_sql(source, options)` and `FormatOptions { style }`. - **postgres-lsp** — Binary crate implementing the LSP via `tower-lsp`. Handles document sync, diagnostics, semantic tokens, go-to-definition, find references, completion, hover, document/workspace symbols, folding ranges, and rename. ### Key Design Constraints diff --git a/Cargo.toml b/Cargo.toml index b104b85..97fdab6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,5 +26,5 @@ serde_json = "1" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } thiserror = "2" -libpgfmt = "1" +libpgfmt = "1.2" diff --git a/README.md b/README.md index 4d19231..803a100 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,41 @@ A Language Server Protocol (LSP) implementation for PostgreSQL and PL/pgSQL, bui - **Find References** — Find all usages of a symbol across the workspace - **Hover** — Show definition source on hover - **Completion** — Context-aware completion for keywords, tables, columns, and functions +- **Signature Help** — Parameter hints for function calls - **Folding Ranges** — Collapse multi-line statements - **Rename** — Rename symbols across the workspace +- **Code Actions** — Quick fixes and refactor rewrites +- **Formatting** — Reformat SQL using one of several style guides - **PL/pgSQL Support** — Parses PL/pgSQL function bodies with language injection +## Installation + +### Homebrew (macOS / Linux) + +```bash +brew tap gmr/postgres +brew install postgres-lsp +``` + +> [!NOTE] +> Homebrew 6.0 added [tap trust](https://docs.brew.sh/Tap-Trust), and some +> versions fail to install third-party taps inside the build sandbox (the +> error mentions `build.rb ... exited with 1`). If you hit this, trust the +> formula first: +> +> ```bash +> brew trust --formula gmr/postgres/postgres-lsp +> ``` +> +> or, as a temporary workaround, set `HOMEBREW_NO_REQUIRE_TAP_TRUST=1` for +> the install. + +### From Source (via Cargo) + +```bash +cargo install postgres-lsp +``` + ## Building ```bash @@ -29,10 +60,10 @@ Requires the [tree-sitter-postgres](https://github.com/gmr/tree-sitter-postgres) The server communicates over stdio: ```bash -cargo run -p pg-lsp +cargo run -p postgres-lsp ``` -Configure your editor to use `pg-lsp` as the language server for `.sql` files. +Configure your editor to use `postgres-lsp` as the language server for `.sql` files. ## License diff --git a/crates/postgres-lsp-format/src/formatter.rs b/crates/postgres-lsp-format/src/formatter.rs index 54ded72..af891f0 100644 --- a/crates/postgres-lsp-format/src/formatter.rs +++ b/crates/postgres-lsp-format/src/formatter.rs @@ -90,6 +90,24 @@ mod tests { ); } + #[test] + fn format_with_pg_dump_style() { + let sql = "select a, b from users where active = true"; + let opts = FormatOptions { + style: Style::PgDump, + }; + let result = format_sql(sql, &opts).unwrap(); + assert!( + result.contains("SELECT"), + "expected uppercase SELECT with pg_dump style, got: {result}" + ); + } + + #[test] + fn parse_pg_dump_style() { + assert_eq!("pg_dump".parse::