https://github.com/supabase/postgres_lsp Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Customer Stories + White papers, Ebooks, Webinars + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. {{ message }} supabase / postgres_lsp Public * * Notifications * Fork 7 * Star 785 A Language Server for Postgres supabase.com License MIT license 785 stars 7 forks Activity Star Notifications * Code * Issues 1 * Pull requests 1 * Discussions * Actions * Security * Insights More * Code * Issues * Pull requests * Discussions * Actions * Security * Insights supabase/postgres_lsp This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 9 branches 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/s] Use Git or checkout with SVN using the web URL. [gh repo clone supaba] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @soedirgo soedirgo Merge pull request #16 from supabase/feat/ add-init-vscode-extension ... d4e971e Aug 6, 2023 Merge pull request #16 from supabase/feat/add-init-vscode-extension feat: initial version of vscode extension d4e971e Git stats * 48 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .cargo feat: initial version of vscode extension August 6, 2023 22:28 .github fix: syntax error July 20, 2023 11:53 crates fix: use parser::new instead of parser::default July 20, 2023 10:45 docs/images Adds a banner July 26, 2023 06:46 editors/code feat: initial version of vscode extension August 6, 2023 22:28 example fix: make it work July 9, 2023 17:14 xtask feat: initial version of vscode extension August 6, 2023 22:28 .gitignore chore: update gitignore August 6, 2023 19:29 Cargo.toml feat: initial version of vscode extension August 6, 2023 22:28 LICENSE Initial commit May 17, 2023 21:23 README.md Merge pull request #16 from supabase/feat/add-init-vscode-extension August 6, 2023 22:47 root-file.txt fix: make it work July 9, 2023 17:14 View code [ ] Postgres Language Server Status Features Motivation Roadmap Installation Neovim Building from source Contributors Acknowledgments Footnotes README.md 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 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, 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(tm) 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 + Show migration file lint errors from squawk + Show plpsql lint errors from plpgsql_check 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 * psteinroe (Maintainer) 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 - About A Language Server for Postgres supabase.com Topics postgres language-server-protocol Resources Readme License MIT license Code of conduct Code of conduct Activity Stars 785 stars Watchers 24 watching Forks 7 forks Report repository Releases No releases published Sponsor this project Sponsor Learn more about GitHub Sponsors Packages 0 No packages published Contributors 5 * @psteinroe * @kiwicopple * @brncsk * @shuvroroy * @soedirgo Languages * Rust 96.8% * JavaScript 1.8% * TypeScript 1.4% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time.