Skip to content

Commit 557e0da

Browse files
Merge branch 'main' into test/analyser-suite
2 parents e511bdf + 7cda2b3 commit 557e0da

File tree

57 files changed

+303
-369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+303
-369
lines changed

.cursorignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Add directories or file patterns to ignore during indexing (e.g. foo/ or *.csv)
2+
libpg_query/
3+
lib/tree_sitter_sql/tree-sitter-sql/

.github/workflows/release.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release PG_CLI
1+
name: Release Binary
22

33
on:
44
workflow_dispatch:
@@ -61,28 +61,28 @@ jobs:
6161
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
6262

6363
- name: 🛠️ Run Build
64-
run: cargo build -p pg_cli --release --target ${{ matrix.config.target }}
64+
run: cargo build -p pglt_cli --release --target ${{ matrix.config.target }}
6565

6666
# windows is a special snowflake to, it saves binaries as .exe
6767
- name: 👦 Name the Binary
6868
if: matrix.config.os == 'windows-latest'
6969
run: |
7070
mkdir dist
71-
cp target/${{ matrix.config.target }}/release/pg_cli.exe ./dist/pgcli_${{ matrix.config.target }}
71+
cp target/${{ matrix.config.target }}/release/pglt.exe ./dist/pglt_${{ matrix.config.target }}
7272
- name: 👦 Name the Binary
7373
if: matrix.config.os != 'windows-latest'
7474
run: |
7575
mkdir dist
76-
cp target/${{ matrix.config.target }}/release/pg_cli ./dist/pgcli_${{ matrix.config.target }}
76+
cp target/${{ matrix.config.target }}/release/pglt ./dist/pglt_${{ matrix.config.target }}
7777
7878
# It is not possible to return the artifacts from the matrix jobs individually: Matrix outputs overwrite each other.
7979
# A common workaround is to upload and download the resulting artifacts.
8080
- name: 👆 Upload Artifacts
8181
id: upload-artifacts
8282
uses: actions/upload-artifact@v4
8383
with:
84-
name: pgcli_${{ matrix.config.target }}
85-
path: ./dist/pgcli_*
84+
name: pglt_${{ matrix.config.target }}
85+
path: ./dist/pglt_*
8686
# The default compression level is 6; this took the binary down from 350 to 330MB.
8787
# It is recommended to use a lower level for binaries, since the compressed result is not much smaller,
8888
# and the higher levels of compression take much longer.
@@ -113,7 +113,7 @@ jobs:
113113
id: download
114114
with:
115115
merge-multiple: true
116-
pattern: pgcli_*
116+
pattern: pglt_*
117117

118118
- name: 📂 Create Release
119119
uses: softprops/action-gh-release@v2
@@ -124,7 +124,7 @@ jobs:
124124
token: ${{ secrets.GITHUB_TOKEN }}
125125
body: ${{ steps.create_changelog.outputs.content }}
126126
tag_name: ${{ steps.create_changelog.outputs.version }}
127-
files: pgcli_*
127+
files: pglt_*
128128
fail_on_unmatched_files: true
129129
draft: true
130130

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 17 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -2,105 +2,29 @@
22

33
# Postgres Language Server
44

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.
66

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
98

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.
1110

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)
1316

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!
9818

9919
## Contributors
10020

101-
- [psteinroe](https://github.com/psteinroe) (Maintainer)
21+
- [psteinroe](https://github.com/psteinroe)
22+
- [juleswritescode](https://github.com/juleswritescode)
23+
24+
## Acknowledgements
10225

103-
## Footnotes
26+
A big thanks to the following projects, without which this project wouldn't have been possible:
10427

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

crates/pglt_analyse/src/categories.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,38 +74,34 @@ impl ActionCategory {
7474
match self {
7575
ActionCategory::QuickFix(tag) => {
7676
if tag.is_empty() {
77-
Cow::Borrowed("quickfix.pglsp")
77+
Cow::Borrowed("quickfix.pglt")
7878
} else {
79-
Cow::Owned(format!("quickfix.pglsp.{tag}"))
79+
Cow::Owned(format!("quickfix.pglt.{tag}"))
8080
}
8181
}
8282

83-
ActionCategory::Refactor(RefactorKind::None) => Cow::Borrowed("refactor.pglsp"),
83+
ActionCategory::Refactor(RefactorKind::None) => Cow::Borrowed("refactor.pglt"),
8484
ActionCategory::Refactor(RefactorKind::Extract) => {
85-
Cow::Borrowed("refactor.extract.pglsp")
86-
}
87-
ActionCategory::Refactor(RefactorKind::Inline) => {
88-
Cow::Borrowed("refactor.inline.pglsp")
85+
Cow::Borrowed("refactor.extract.pglt")
8986
}
87+
ActionCategory::Refactor(RefactorKind::Inline) => Cow::Borrowed("refactor.inline.pglt"),
9088
ActionCategory::Refactor(RefactorKind::Rewrite) => {
91-
Cow::Borrowed("refactor.rewrite.pglsp")
89+
Cow::Borrowed("refactor.rewrite.pglt")
9290
}
9391
ActionCategory::Refactor(RefactorKind::Other(tag)) => {
94-
Cow::Owned(format!("refactor.{tag}.pglsp"))
92+
Cow::Owned(format!("refactor.{tag}.pglt"))
9593
}
9694

97-
ActionCategory::Source(SourceActionKind::None) => Cow::Borrowed("source.pglsp"),
98-
ActionCategory::Source(SourceActionKind::FixAll) => {
99-
Cow::Borrowed("source.fixAll.pglsp")
100-
}
95+
ActionCategory::Source(SourceActionKind::None) => Cow::Borrowed("source.pglt"),
96+
ActionCategory::Source(SourceActionKind::FixAll) => Cow::Borrowed("source.fixAll.pglt"),
10197
ActionCategory::Source(SourceActionKind::OrganizeImports) => {
102-
Cow::Borrowed("source.organizeImports.pglsp")
98+
Cow::Borrowed("source.organizeImports.pglt")
10399
}
104100
ActionCategory::Source(SourceActionKind::Other(tag)) => {
105-
Cow::Owned(format!("source.{tag}.pglsp"))
101+
Cow::Owned(format!("source.{tag}.pglt"))
106102
}
107103

108-
ActionCategory::Other(tag) => Cow::Owned(format!("{tag}.pglsp")),
104+
ActionCategory::Other(tag) => Cow::Owned(format!("{tag}.pglt")),
109105
}
110106
}
111107
}

crates/pglt_analyse/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl AnalyserRules {
4545
/// A set of information useful to the analyser infrastructure
4646
#[derive(Debug, Default)]
4747
pub struct AnalyserOptions {
48-
/// A data structured derived from the [`pglsp.toml`] file
48+
/// A data structured derived from the [`pglt.toml`] file
4949
pub rules: AnalyserRules,
5050
}
5151

crates/pglt_analyser/CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Let's assume that the rule we implement support the following options:
7979
- `threshold`: an integer between 0 and 255;
8080
- `behaviorExceptions`: an array of strings.
8181

82-
We would like to set the options in the `pglsp.toml` configuration file:
82+
We would like to set the options in the `pglt.toml` configuration file:
8383

8484
```toml
8585
[linter.rules.safety.myRule]
@@ -132,9 +132,9 @@ We currently require implementing _serde_'s traits `Deserialize`/`Serialize`.
132132

133133
Also, we use other `serde` macros to adjust the JSON configuration:
134134

135-
- `rename_all = "snake_case"`: it renames all fields in camel-case, so they are in line with the naming style of the `pglsp.toml`.
135+
- `rename_all = "snake_case"`: it renames all fields in camel-case, so they are in line with the naming style of the `pglt.toml`.
136136
- `deny_unknown_fields`: it raises an error if the configuration contains extraneous fields.
137-
- `default`: it uses the `Default` value when the field is missing from `pglsp.toml`. This macro makes the field optional.
137+
- `default`: it uses the `Default` value when the field is missing from `pglt.toml`. This macro makes the field optional.
138138

139139
You can simply use a derive macros:
140140

crates/pglt_analyser/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ pglt_analyse = { workspace = true }
1616
pglt_console = { workspace = true }
1717
pglt_query_ext = { workspace = true }
1818
serde = { workspace = true }
19+
20+
[dev-dependencies]
21+
pglt_diagnostics = { workspace = true }
22+
termcolor = { workspace = true }

crates/pglt_analyser/src/lint/safety/ban_drop_column.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ declare_lint_rule! {
1212
///
1313
/// ### Invalid
1414
///
15-
/// ```sql,ignore
15+
/// ```sql,expect_diagnostic
1616
/// alter table test drop column id;
1717
/// ```
1818
///

crates/pglt_analyser/src/lint/safety/ban_drop_not_null.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ declare_lint_rule! {
1212
///
1313
/// ### Invalid
1414
///
15-
/// ```sql,ignore
15+
/// ```sql,expect_diagnostic
1616
/// alter table users alter column email drop not null;
1717
/// ```
1818
pub BanDropNotNull {

0 commit comments

Comments
 (0)