A new Language Server Protocol (LSP) implementation for PostgreSQL is now available: postgres-lsp. Built on top of tree-sitter-postgres, it offers deep, grammar-aware support for SQL and PL/pgSQL, replacing heuristic-based tools with precise analysis. Developers can integrate it into editors like VS Code, Neovim, or Emacs to get rich features for .sql files.
Key features include:
- Diagnostics — Parse errors from tree-sitter reported as LSP diagnostics.
- Semantic Tokens — Syntax highlighting via semantic token classification.
- Document Symbols — Outline of DDL statements (tables, functions, views, and more).
- Workspace Symbols — Search across all open files for symbols.
- Go to Definition — Navigate to definitions of tables, functions, types, and columns.
- Find References — Find all usages of a symbol in the workspace.
- Hover — Show the 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 styles from
libpgfmt:river,mozilla,aweber,dbt,gitlab,kickstarter,mattmc3,pg_dump. - PL/pgSQL Support — Parses PL/pgSQL functions.
For developers, this means significantly improved editing experience for PostgreSQL code. The use of a real grammar reduces false positives and enables accurate refactoring and navigation. Formatting options align with popular style guides, making it easier to maintain consistent codebases. This project is a major step forward for PostgreSQL tooling, bringing it closer to the quality of language servers in other ecosystems.
Source: https://www.postgresql.org/about/news/new-postgres-language-server-postgres-lsp-3322/