Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqlx-lsp

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.

MVP scope

  • Detect query!, query_as!, and query_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, and ORDER BY.
  • Discover PostgreSQL schema data from DATABASE_URL or 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.

Workspace layout

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.

Configure the database

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_app

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

Development

cargo test --workspace
cargo clippy --workspace --all-targets -- -D warnings
cargo install --path crates/sqlx-lsp --debug --force

Then 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-wasip1

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

Intentional first-version limits

  • PostgreSQL only.
  • Literal SQL in query!, query_as!, and query_scalar!; no query_file!.
  • No SQLx compile-time type/nullability reimplementation.
  • No .sqlx metadata for schema discovery.
  • No query execution; database access is limited to schema discovery.
  • The dev adapter uses a configured or PATH binary; release asset download is a publishing/distribution step after the repository URL is finalized.

Never commit .env; it is ignored by this repository.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages