-
Notifications
You must be signed in to change notification settings - Fork 102
chore: update the readme #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Add directories or file patterns to ignore during indexing (e.g. foo/ or *.csv) | ||
libpg_query/ | ||
lib/tree_sitter_sql/tree-sitter-sql/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,105 +2,29 @@ | |
|
||
# Postgres Language Server | ||
|
||
A Language Server for Postgres. Not SQL with flavors, just Postgres. | ||
A collection of language tools and a Language Server Protocol (LSP) implementation for Postgres, focusing on developer experience and reliable SQL tooling. | ||
|
||
> [!WARNING] | ||
> 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. | ||
## Overview | ||
|
||
## Features | ||
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. | ||
|
||
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: | ||
Currently, the following features are implemented: | ||
- Autocompletion | ||
- Syntax Error Highlighting | ||
- Type-checking (via `EXPLAIN` error insights) | ||
- Linter, inspired by [Squawk](https://squawkhq.com) | ||
|
||
- Lint | ||
- Hover | ||
- Typechecking | ||
- Syntax Error Diagnostics | ||
- Inlay Hints | ||
- Auto-Completion | ||
- Code actions such as `Execute the statement under the cursor`, or `Execute the current file` | ||
- Formatter | ||
- ... and many more | ||
|
||
We plan to support all of the above for SQL and PL/pgSQL function bodies too! | ||
|
||
## Motivation | ||
|
||
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. | ||
|
||
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. | ||
|
||
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. | ||
|
||
## Installation | ||
|
||
> [!WARNING] | ||
> This is not ready for production use. Only install this if you want to help with development. | ||
|
||
> [!NOTE] | ||
> 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! | ||
|
||
### Neovim | ||
|
||
Add the postgres_lsp executable to your path, and add the following to your config to use it. | ||
|
||
```lua | ||
local util = require 'lspconfig.util' | ||
local lspconfig = require 'lspconfig' | ||
|
||
require('lspconfig.configs').postgres_lsp = { | ||
default_config = { | ||
name = 'postgres_lsp', | ||
cmd = { 'postgres_lsp' }, | ||
filetypes = { 'sql' }, | ||
single_file_support = true, | ||
root_dir = util.root_pattern 'root-file.txt', | ||
}, | ||
} | ||
|
||
lspconfig.postgres_lsp.setup { force_setup = true } | ||
``` | ||
|
||
### Building from source | ||
|
||
You'll need _nightly_ Cargo, Node, and npm installed. | ||
|
||
Install the `libpg_query` submodule by running: | ||
|
||
```sh | ||
git submodule update --init --recursive | ||
``` | ||
|
||
If you are using VS Code, you can install both the server and the client extension by running: | ||
|
||
```sh | ||
cargo xtask install | ||
``` | ||
|
||
If you're not using VS Code, you can install the server by running: | ||
|
||
```sh | ||
cargo xtask install --server | ||
``` | ||
|
||
The server binary will be installed in `.cargo/bin`. Make sure that `.cargo/bin` is in `$PATH`. | ||
|
||
### Github CodeSpaces | ||
|
||
You can setup your development environment on [CodeSpaces](https://github.com/features/codespaces). | ||
|
||
After your codespace boots up, run the following command in the shell to install Rust: | ||
|
||
```shell | ||
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh | ||
``` | ||
|
||
Proceed with the rest of the installation as usual. | ||
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! | ||
|
||
## Contributors | ||
|
||
- [psteinroe](https://github.com/psteinroe) (Maintainer) | ||
- [psteinroe](https://github.com/psteinroe) | ||
- [juleswritescode](https://github.com/juleswritescode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
## Acknowledgements | ||
|
||
## Footnotes | ||
A big thanks to the following projects, without which this project wouldn't have been possible: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great addition!!! |
||
|
||
[^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) | ||
[^2]: Proprietary IDEs: [DataGrip](https://www.jetbrains.com/datagrip/) | ||
- [libpg_query](https://github.com/pganalyze/libpg_query): For extracting the Postgres' parser | ||
- [Biome](https://github.com/biomejs/biome): For implementing a toolchain infrastructure we could copy from | ||
- [Squawk](https://github.com/sbdchd/squawk): For the linter inspiration |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took the opportunity to play with cursor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.