• Stars
    star
    3,188
  • Rank 14,085 (Top 0.3 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 1 year ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Language Server for Postgres

Postgres Language Server

Postgres Language Server

A Language Server for Postgres. Not SQL with flavors, just Postgres.

Status

๐Ÿšง This is in active development and is only ready for collaborators. The majority of work is still ahead, but we've verified that the approach works. We're making this public so that we can develop it in the open with input from the community.

Features

The 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:

  • Semantic Highlighting
  • Syntax Error Diagnostics
  • Show SQL comments on hover
  • Auto-Completion
  • Code actions such as Execute the statement under the cursor, or Execute the current file
  • Configurable Code Formatting
  • ... and many more

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 Servers1 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 IDEs2 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, 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. 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 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.

Roadmap

This is a proof of concept for building both a concrete syntax tree and an abstract syntax tree from a potentially malformed PostgreSQL source code. The postgres_lsp crate was created to prove that it works end-to-end, and is just a very basic language server with semantic highlighting and error diagnostics. Before further feature development, we have to complete a bit of groundwork:

  1. Finish the parser
    • The parser works, but the enum values for all the different syntax elements and internal conversations are manually written or copied, and, in some places, only cover a few elements required for a simple select statement. To have full coverage without possibilities for a copy and paste error, they should be generated from pg_query.rs source code. (#4)
    • There are a few cases such as nested and named dollar quoted strings that cause the parser to fail due to limitations of the regex-based lexer. Nothing that is impossible to fix, or requires any fundamental change in the parser though.
  2. Implement a robust and scalable data model
    • This is still in a research phase
    • A great rationale on the importance of the data model in a language server can be found here
    • rust-analyzers base-db crate will serve as a role model
    • The salsa crate will most likely be the underlying data structure
  3. Setup the language server properly
    • This is still in a research phase
    • Once again rust-analyzer will serve as a role model, and we will most likely implement the same queueing and cancellation approach
  4. Implement basic language server features
    • Semantic Highlighting
    • Syntax Error Diagnostics
    • Show SQL comments on hover
    • Auto-Completion
    • Code Actions, such as Execute the statement under the cursor, or Execute the current file
    • ... anything you can think of really
  5. Integrate all the existing open source tooling
  6. Build missing pieces
    • An optionated code formatter (think prettier for PostgreSQL)
  7. (Maybe) Support advanced features with declarative schema management
    • Jump to definition
    • ... anything you can think of really

Installation

Warning
This is not ready for production use. Only install this if you want to help with development.

Neovim

Add the postgres_lsp executable to your path, and add the following to your config to use it.

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'
  }
}

lsp.configure("postgres_lsp", {force_setup = true})

Building from source

You'll need Cargo, Node, and npm installed.

If you are using VS Code, you can install both the server and the client extension by running:

cargo xtask install

If you're not using VS Code, you can install the server by running:

cargo xtask install --server

The server binary will be installed in .cargo/bin. Make sure that .cargo/bin is in $PATH.

Contributors

Acknowledgments

  • rust-analyzer for implementing such a robust, well documented, and feature-rich language server. Great place to learn from.
  • squawk and pganalyze for inspiring the use of libpg_query.

Footnotes

Footnotes

  1. Generic SQL Solutions: sql-language-server, pgFormatter, sql-parser-cst โ†ฉ

  2. Proprietary IDEs: DataGrip โ†ฉ

More Repositories

1

postgres-new

In-browser Postgres sandbox with AI assistance
TypeScript
2,212
star
2

nextjs-openai-doc-search

Template for building your own custom ChatGPT style doc search powered by Next.js, OpenAI, and Supabase.
TypeScript
1,249
star
3

copycat

Generate deterministic fake values: The same input will always generate the same fake-output.
TypeScript
755
star
4

supabase-csharp

A C# Client library for Supabase
C#
491
star
5

supabase-on-aws

Self-hosted Supabase on AWS
TypeScript
382
star
6

supabase-kt

A Kotlin Multiplatform Client for Supabase.
Kotlin
364
star
7

sql-examples

Curated list of SQL to help you find useful script easily ๐Ÿš€
Vue
358
star
8

chatgpt-your-files

Production-ready MVP for securely chatting with your documents using pgvector
TypeScript
330
star
9

postgrest-rs

Rust client for PostgREST
Rust
328
star
10

supabase-custom-claims

How to implement custom claims with Supabase
JavaScript
254
star
11

supabase-graphql-example

A HackerNews-like clone built with Supabase and pg_graphql
PLpgSQL
214
star
12

snapshot

Capture a snapshot (or subset) of your Postgres database whilst transforming the data.
TypeScript
211
star
13

supabase-kubernetes

Helm 3 charts to deploy a Supabase on Kubernetes
Smarty
206
star
14

svelte-kanban

PLpgSQL
203
star
15

godot-engine.supabase

A lightweight addon which integrates Supabase APIs for Godot Engine out of the box.
GDScript
172
star
16

nuxt-supabase

A supa simple wrapper around Supabase.js to enable usage within Nuxt.
TypeScript
167
star
17

postgrest-go

Isomorphic Go client for PostgREST. (Now Updating)
Go
125
star
18

supabase-ui-svelte

Supabase authentication UI for Svelte
Svelte
120
star
19

postgrest-csharp

A C# Client library for Postgrest
C#
117
star
20

firebase-to-supabase

Firebase to Supabase Migration Guide
JavaScript
100
star
21

vue-supabase

A supa simple wrapper around Supabase.js to enable usage within Vue.
TypeScript
87
star
22

expo-stripe-payments-with-supabase-functions

Bring the Func(๐Ÿ•บ)
TypeScript
86
star
23

realtime-csharp

A C# client library for supabase/realtime.
C#
71
star
24

svelte-supabase

JavaScript
71
star
25

partner-gallery-example

Supabase Partner Gallery Example
TypeScript
67
star
26

supabase-sveltekit-example

Svelte
65
star
27

supabase-flutter-quickstart

Flutter implementation of the Quickstart Supabase User Management app.
C++
61
star
28

deno-fresh-openai-doc-search

Template for building your own custom ChatGPT style doc search powered by Fresh, Deno, OpenAI, and Supabase.
TypeScript
60
star
29

supabase-traefik

Python
57
star
30

flutter-stripe-payments-with-supabase-functions

Dart
55
star
31

supabase-terraform

HCL
53
star
32

postgrest-kt

Postgrest Kotlin Client
Kotlin
52
star
33

supabase-vscode-extension

Supabase Extension for VS Code and GitHub Copilot.
TypeScript
50
star
34

flutter-auth-ui

Supabase Auth UI library for Flutter
Dart
49
star
35

supabase-rb

An isomorphic Ruby client for Supabase.
Ruby
46
star
36

realtime-swift

A Swift client for Supabase Realtime server.
Swift
45
star
37

supabase-by-example

TypeScript
44
star
38

flutter-chat

Simple chat application built with Flutter and Supabase.
Dart
44
star
39

postgrest-swift

Swift client for PostgREST
Swift
43
star
40

gotrue-csharp

C# implementation of Supabase's GoTrue
C#
39
star
41

postgrest-rb

Isomorphic Ruby client for PostgREST.
Ruby
32
star
42

gotrue-swift

A Swift client library for GoTrue.
Swift
32
star
43

storage-go

Storage util client for Supabase in Go
Go
31
star
44

vec2pg

Migrate vector workloads to Postgres
Python
29
star
45

chatgpt-plugin-template-deno

Template for building ChatGPT Plugins in TypeScript that run on Supabase's custom Deno Edge Runtime.
TypeScript
27
star
46

storage-swift

Swift client library to interact with Supabase Storage
Swift
25
star
47

base64url-js

Pure TypeScript implementation of Base64-URL encoding for JavaScript strings.
TypeScript
22
star
48

gotrue-kt

Kotlin Client for GoTrue API
Kotlin
21
star
49

storage-csharp

A C# implementation of Supabase's Object Storage API
C#
19
star
50

sql-to-rest

SQL to PostgREST translator
TypeScript
19
star
51

postgrest-ex

Elixir Client library for PostgREST
Elixir
18
star
52

gotrue-ex

An Elixir client for the GoTrue authentication service
Elixir
16
star
53

heroku-to-supabase

Heroku to Supabase Migration Guide
16
star
54

sveltekit-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with SvelteKit.
TypeScript
13
star
55

nuxt3-quickstarter

CSS
13
star
56

gotrue-go

Typed Golang cilent for the Supabase fork of GoTrue
Go
12
star
57

supabase-php

PHP
11
star
58

pg_headerkit

A set of functions for adding special features to your application that uses PostgREST API calls to your PostgreSQL database.
PLpgSQL
11
star
59

functions-csharp

C# client for interacting with Supabase Functions
C#
11
star
60

auth-go

Go
10
star
61

gotrue-java

A Java client library for the GoTrue API.
Java
10
star
62

onesignal

Next.js app showcasing how you can implement push notification using OneSignal and Supabase
TypeScript
10
star
63

postgres-wasm-fdw

A WebAssembly foreign data wrapper example project
Rust
9
star
64

functions-swift

Swift Client library to interact with Supabase Functions.
Swift
8
star
65

supabase-adminpack

A Trusted Language Extension containing a variety of useful databse admin queries.
8
star
66

functions-go

Golang client library to interact with Supabase Functions.
Go
7
star
67

unboring.sg

A website and browser extensions to discover things to eat, do, and learn.
TypeScript
7
star
68

supabase-community-bot

TypeScript
5
star
69

ai-writer

An AI writing assistant powered by OpenAI, Supabase, and Next.js
TypeScript
5
star
70

storage-java

A Java client library for the Supabase Storage API
Java
4
star
71

supabase-management-js

Convenience wrapper for the Supabase Management API: https://supabase.com/docs/reference/api/introduction
TypeScript
4
star
72

supabase-go

Go
4
star
73

deno-supabase-js

Using supabase-js in Deno.
4
star
74

launchweek.dev

Tracking launch weeks across the industry, for product discovery and inspiration.
JavaScript
3
star
75

.github

Supabase Community
3
star
76

core-swift

Shared interfaces and helpers for Swift libraries
Swift
2
star
77

supa-jam

TypeScript
2
star
78

nftree-garden

Mint an NFT, plant a Tree!
JavaScript
1
star
79

realtime-go

1
star
80

functions-rs

Rust
1
star
81

squad

1
star
82

gotrue-php

PHP
1
star
83

storage-php

PHP
1
star
84

postgrest-php

PHP
1
star
85

deno-storage-js

Repo to overwrite https://deno.land/x/storagee listing.
1
star
86

supabase-fastify-api

TypeScript
1
star
87

gotrue-fsharp

F# client for interacting with Supabase GoTrue
F#
1
star
88

realtime-php

1
star
89

core-py

Shared interfaces and helpers for the supabase-py libs
Python
1
star
90

hacktoberfest-hackathon-template

Template for the Supabase Hacktoberfest Hackathon that follows https://hacktoberfest.digitalocean.com/resources/maintainers
1
star
91

postgrest-java

1
star