|
2 | 2 |
|
3 | 3 | # Postgres Language Server
|
4 | 4 |
|
5 |
| -A Language Server for Postgres. Not SQL with flavors, just Postgres. |
| 5 | +A collection of language tools and a Language Server Protocol (LSP) implementation for Postgres, focusing on developer experience and reliable SQL tooling. |
6 | 6 |
|
7 |
| -> [!WARNING] |
8 |
| -> This is in active development and is only ready for collaborators. But we are getting there! You can find the current roadmap and opportunities to contribute in https://github.com/supabase-community/postgres_lsp/issues/136. |
| 7 | +## Overview |
9 | 8 |
|
10 |
| -## Features |
| 9 | +This project provides a toolchain for Postgres development, built on Postgres' own parser `libpg_query` to ensure 100% syntax compatibility. It is built on a Server-Client architecture with a transport-agnostic design. This means all features can be accessed not only through the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/), but also through other interfaces like a CLI, HTTP APIs, or a WebAssembly module. The goal is to make all the great Postgres tooling out there as accessible as possible, and to build anything that is missing ourselves. |
11 | 10 |
|
12 |
| -The [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) is an open protocol between code editors and servers to provide code intelligence tools such as code completion and syntax highlighting. This project implements such a language server for Postgres, significantly enhancing the developer experience within your favorite editor by adding: |
| 11 | +Currently, the following features are implemented: |
| 12 | +- Autocompletion |
| 13 | +- Syntax Error Highlighting |
| 14 | +- Type-checking (via `EXPLAIN` error insights) |
| 15 | +- Linter, inspired by [Squawk](https://squawkhq.com) |
13 | 16 |
|
14 |
| -- Lint |
15 |
| -- Hover |
16 |
| -- Typechecking |
17 |
| -- Syntax Error Diagnostics |
18 |
| -- Inlay Hints |
19 |
| -- Auto-Completion |
20 |
| -- Code actions such as `Execute the statement under the cursor`, or `Execute the current file` |
21 |
| -- Formatter |
22 |
| -- ... and many more |
23 |
| - |
24 |
| -We plan to support all of the above for SQL and PL/pgSQL function bodies too! |
25 |
| - |
26 |
| -## Motivation |
27 |
| - |
28 |
| -Despite the rising popularity of Postgres, support for the PL/pgSQL in IDEs and editors is limited. While there are some _generic_ SQL Language Servers[^1] offering the Postgres syntax as a "flavor" within the parser, they usually fall short due to the ever-evolving and complex syntax of PostgreSQL. There are a few proprietary IDEs[^2] that work well, but the features are only available within the respective IDE. |
29 |
| - |
30 |
| -This Language Server is designed to support Postgres, and only Postgres. The server uses [libpg_query](https://github.com/pganalyze/libpg_query), both as a git submodule for access to its protobuf file and as the [pg_query](https://crates.io/crates/pg_query/5.0.0) rust crate, therefore leveraging the PostgreSQL source to parse the SQL code reliably. Using Postgres within a Language Server might seem unconventional, but it's the only reliable way of parsing all valid PostgreSQL queries. You can find a longer rationale on why This is the Way™ [here](https://pganalyze.com/blog/parse-postgresql-queries-in-ruby). While libpg_query was built to execute SQL, and not to build a language server, any shortcomings have been successfully mitigated in the `parser` crate. You can read the [commented source code](./crates/parser/src/lib.rs) for more details on the inner workings of the parser. |
31 |
| - |
32 |
| -Once the parser is stable, and a robust and scalable data model is implemented, the language server will not only provide basic features such as semantic highlighting, code completion and syntax error diagnostics, but also serve as the user interface for all the great tooling of the Postgres ecosystem. |
33 |
| - |
34 |
| -## Installation |
35 |
| - |
36 |
| -> [!WARNING] |
37 |
| -> This is not ready for production use. Only install this if you want to help with development. |
38 |
| -
|
39 |
| -> [!NOTE] |
40 |
| -> Interested in setting up a release process and client extensions for Neovim and VS Code? Please check out https://github.com/supabase-community/postgres_lsp/issues/136! |
41 |
| -
|
42 |
| -### Neovim |
43 |
| - |
44 |
| -Add the postgres_lsp executable to your path, and add the following to your config to use it. |
45 |
| - |
46 |
| -```lua |
47 |
| -local util = require 'lspconfig.util' |
48 |
| -local lspconfig = require 'lspconfig' |
49 |
| - |
50 |
| -require('lspconfig.configs').postgres_lsp = { |
51 |
| - default_config = { |
52 |
| - name = 'postgres_lsp', |
53 |
| - cmd = { 'postgres_lsp' }, |
54 |
| - filetypes = { 'sql' }, |
55 |
| - single_file_support = true, |
56 |
| - root_dir = util.root_pattern 'root-file.txt', |
57 |
| - }, |
58 |
| -} |
59 |
| - |
60 |
| -lspconfig.postgres_lsp.setup { force_setup = true } |
61 |
| -``` |
62 |
| - |
63 |
| -### Building from source |
64 |
| - |
65 |
| -You'll need _nightly_ Cargo, Node, and npm installed. |
66 |
| - |
67 |
| -Install the `libpg_query` submodule by running: |
68 |
| - |
69 |
| -```sh |
70 |
| -git submodule update --init --recursive |
71 |
| -``` |
72 |
| - |
73 |
| -If you are using VS Code, you can install both the server and the client extension by running: |
74 |
| - |
75 |
| -```sh |
76 |
| -cargo xtask install |
77 |
| -``` |
78 |
| - |
79 |
| -If you're not using VS Code, you can install the server by running: |
80 |
| - |
81 |
| -```sh |
82 |
| -cargo xtask install --server |
83 |
| -``` |
84 |
| - |
85 |
| -The server binary will be installed in `.cargo/bin`. Make sure that `.cargo/bin` is in `$PATH`. |
86 |
| - |
87 |
| -### Github CodeSpaces |
88 |
| - |
89 |
| -You can setup your development environment on [CodeSpaces](https://github.com/features/codespaces). |
90 |
| - |
91 |
| -After your codespace boots up, run the following command in the shell to install Rust: |
92 |
| - |
93 |
| -```shell |
94 |
| -curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh |
95 |
| -``` |
96 |
| - |
97 |
| -Proceed with the rest of the installation as usual. |
| 17 | +Our current focus is on refining and enhancing these core features while building a robust and easily accessible infrastructure. For future plans and opportunities to contribute, please check out the issues and discussions. Any contributions are welcome! |
98 | 18 |
|
99 | 19 | ## Contributors
|
100 | 20 |
|
101 |
| -- [psteinroe](https://github.com/psteinroe) (Maintainer) |
| 21 | +- [psteinroe](https://github.com/psteinroe) |
| 22 | +- [juleswritescode](https://github.com/juleswritescode) |
| 23 | + |
| 24 | +## Acknowledgements |
102 | 25 |
|
103 |
| -## Footnotes |
| 26 | +A big thanks to the following projects, without which this project wouldn't have been possible: |
104 | 27 |
|
105 |
| -[^1]: Generic SQL Solutions: [sql-language-server](https://github.com/joe-re/sql-language-server), [pgFormatter](https://github.com/darold/pgFormatter/tree/master), [sql-parser-cst](https://github.com/nene/sql-parser-cst) |
106 |
| -[^2]: Proprietary IDEs: [DataGrip](https://www.jetbrains.com/datagrip/) |
| 28 | +- [libpg_query](https://github.com/pganalyze/libpg_query): For extracting the Postgres' parser |
| 29 | +- [Biome](https://github.com/biomejs/biome): For implementing a toolchain infrastructure we could copy from |
| 30 | +- [Squawk](https://github.com/sbdchd/squawk): For the linter inspiration |
0 commit comments