|
| 1 | + |
| 2 | + |
| 3 | +# Postgres Language Server |
| 4 | + |
| 5 | +A collection of language tools and a Language Server Protocol (LSP) implementation for Postgres, focusing on developer experience and reliable SQL tooling. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +**Source Code**: <a href="https://github.com/supabase-community/postgres_lsp" target="_blank">https://github.com/supabase-community/postgres_lsp</a> |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +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. |
| 16 | + |
| 17 | +Currently, the following features are implemented: |
| 18 | +- Autocompletion |
| 19 | +- Syntax Error Highlighting |
| 20 | +- Type-checking (via `EXPLAIN` error insights) |
| 21 | +- Linter, inspired by [Squawk](https://squawkhq.com) |
| 22 | + |
| 23 | +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! |
| 24 | + |
| 25 | +## Installation |
| 26 | + |
| 27 | +> [!NOTE] |
| 28 | +> We will update this section once we have published the binaries. |
| 29 | +
|
| 30 | +## Configuration |
| 31 | + |
| 32 | +We recommend that you create a `pglt.toml` configuration file for each project. This eliminates the need to repeat the CLI options each time you run a command, and ensures that we use the same configuration in your editor. Some options are also only available from a configuration file. If you are happy with the defaults, you don’t need to create a configuration file. To create the `pglt.toml` file, run the `init` command in the root folder of your project: |
| 33 | + |
| 34 | +```sh |
| 35 | +pglt init |
| 36 | +``` |
| 37 | + |
| 38 | +After running the `init` command, you’ll have a new `pglt.toml` file in your directory: |
| 39 | + |
| 40 | +```toml |
| 41 | +[vcs] |
| 42 | +enabled = false |
| 43 | +client_kind = "git" |
| 44 | +use_ignore_file = false |
| 45 | + |
| 46 | +[files] |
| 47 | +ignore = [] |
| 48 | + |
| 49 | +[linter] |
| 50 | +enabled = true |
| 51 | + |
| 52 | +[linter.rules] |
| 53 | +recommended = true |
| 54 | + |
| 55 | +[db] |
| 56 | +host = "127.0.0.1" |
| 57 | +port = 5432 |
| 58 | +username = "postgres" |
| 59 | +password = "postgres" |
| 60 | +database = "postgres" |
| 61 | +conn_timeout_secs = 10 |
| 62 | +``` |
| 63 | + |
| 64 | +Make sure to point the database connection settings at your local development database. To see what else can be configured, run `--help`. |
| 65 | + |
| 66 | +## Usage |
| 67 | + |
| 68 | +You can check SQL files using the `check` command: |
| 69 | + |
| 70 | +```sh |
| 71 | +pglt check myfile.sql |
| 72 | +``` |
| 73 | + |
| 74 | +Make sure to check out the other options. We will provide guides for specific use cases like linting migration files soon. |
| 75 | + |
| 76 | +## Install an Editor Plugin |
| 77 | + |
| 78 | +We recommend installing an editor plugin to get the most out of Postgres Language Tools. |
| 79 | + |
| 80 | +> [!NOTE] |
| 81 | +> We will update this section once we have published the binaries. |
| 82 | +
|
| 83 | + |
| 84 | +## CI Setup |
| 85 | + |
| 86 | +> [!NOTE] |
| 87 | +> We will update this section once we have published the binaries. |
| 88 | +
|
0 commit comments