How supabase-community/postgres-language-server works
And define the main components
• Client Interfaces: Represent the different “front-ends” that interact with your toolchain. This includes:
– LSP Clients (editors such as VSCode, Neovim, etc.)
– CLI (command line interface)
– (Potentially) Other interfaces like HTTP APIs or WebAssembly modules, as hinted by the transport-agnostic design.
• Server / Core Service: This layer is responsible for processing and handing off requests from the client interfaces. It will include:
– The LSP server implementation (see the pgt_lsp crate)
– The CLI backend (pgt_cli crate)
– libpg_query integration (libpg_query module)
– pgt_analyse and pgt_analyser (for analysis and linting)
– pgt_diagnostics, pgt_diagnostics_categories, and pgt_diagnostics_macros (for diagnostics and error reporting)
– pgt_configuration (reading and managing configurations)
– pgt_lexer and pgt_lexer_codegen (parsing and syntax processing)
– pgt_schema_cache, pgt_statement_splitter, pgt_type_resolver, pgt_typecheck (for SQL statement handling and type checking)
– pgt_fs and pgt_workspace (for file, workspace, and environment management)
• Additional Tools: There are also helper modules for generating completions (pgt_completions), markup (pgt_console, pgt_markup), treesitter queries, text editing, text sizing, etc. These provide supporting functionality and can be grouped as “Utility Libraries.”
Out relationships and data flow
• Within the server component, show a breakdown where requests are passed into a “Processing Pipeline” that leverages the core libraries:
– A “Parser” submodule (using libpg_query, pgt_lexer, etc.) to transform SQL input into ASTs.
– A “Linter/Analyser” submodule (using pgt_analyse/pgt_analyser and diagnostics modules) to check for syntax, lint, and type issues.
– A “Configuration and Workspace” submodule (pgt_configuration, pgt_workspace, pgt_fs) to manage settings and context.
– A “Response Generation” submodule (pgt_console, pgt_completions, etc.) that formats and sends results back to the client.
– From “LSP Client” → “LSP Server” → “Parsing Module” → “Linter/Diagnostic Module” → “Response Formatter” → back to “LSP Client.”
– Similarly for the CLI route.
Architectural patterns and design principles
• Separation of concerns: distinct crates handling parsing, diagnostics, configuration, and client communication.
• Modularity provided by the Cargo workspace, with each crate (located in the “crates” directory) responsible for a specific part of the functionality.
Technical stack and technologies
• Integration with libpg_query and other core dependencies.