sqlx-lsp adds PostgreSQL-aware SQL editing to SQLx macros in Rust source files.
The language server is editor-independent; the Zed extension in editors/zed
is intentionally only an adapter that starts and configures it.
- Detect
query!,query_as!, andquery_scalar!invocations. - Support ordinary and raw Rust string literals.
- Highlight the embedded PostgreSQL SQL with LSP semantic tokens.
- Complete schemas, tables, columns, aliases, SQL keywords, and functions.
- Understand
SELECT,FROM,JOIN,WHERE,GROUP BY, andORDER BY. - Discover PostgreSQL schema data from
DATABASE_URLor a project.env. - Refresh the in-memory catalog without restarting the editor.
The MVP deliberately does not use .sqlx metadata for schema discovery and
does not reproduce SQLx compile-time type or nullability analysis.
crates/sqlx-lsp-core/ Editor-independent analysis and PostgreSQL integration
crates/sqlx-lsp/ LSP protocol adapter and stdio binary
editors/zed/ Thin Zed WASM extension
docs/ Architecture and development notes
See docs/architecture.md for the data flow and design decisions, and docs/development.md for a guided tour of the request lifecycle and local Zed workflow.
Prefer a project-local .env so Zed launched from the desktop does not depend
on shell environment inheritance:
DATABASE_URL=postgres://postgres:postgres@localhost:5432/my_appResolution order is an explicit LSP databaseUrl setting, the server process's
DATABASE_URL, then .env in the workspace root. An explicit setting is useful
for testing but stores the URL in editor settings, so environment-based options
are safer for credentials.
cargo test --workspace
cargo clippy --workspace --all-targets -- -D warnings
cargo install --path crates/sqlx-lsp --debug --forceThen run zed: install dev extension and select the editors/zed directory.
The adapter first honors an explicit lsp.sqlx-lsp.binary.path setting, then
looks for sqlx-lsp on the project environment's PATH. Zed requires a
rustup-installed toolchain and the wasm32-wasip1 target when building a Rust
dev extension:
rustup target add wasm32-wasip1Example Zed settings:
{
"semantic_tokens": "combined",
"languages": {
"Rust": {
"language_servers": ["rust-analyzer", "sqlx-lsp", "..."]
}
}
}semantic_tokens matters because Zed disables them by default. combined
keeps Rust's Tree-sitter highlighting and overlays SQL tokens from sqlx-lsp.
See Zed's semantic-token documentation
and language-server configuration.
Inside a Rust buffer, open code actions (cmd-. on macOS or ctrl-. on
Linux/Windows) to refresh the PostgreSQL catalog. Query execution is not exposed
by the language server or Zed extension.
For adapter changes, rebuild the dev extension from Zed. For language-server
changes, rerun the cargo install command or temporarily point
lsp.sqlx-lsp.binary.path at this workspace's target/debug/sqlx-lsp.
- PostgreSQL only.
- Literal SQL in
query!,query_as!, andquery_scalar!; noquery_file!. - No SQLx compile-time type/nullability reimplementation.
- No
.sqlxmetadata for schema discovery. - No query execution; database access is limited to schema discovery.
- The dev adapter uses a configured or
PATHbinary; release asset download is a publishing/distribution step after the repository URL is finalized.
Never commit .env; it is ignored by this repository.