Skip to content

Newer versions of rust-analyzer breaks when using multiple databases in SQLX #18533

Closed as not planned
@Laursen79

Description

@Laursen79

So, I have a very specific issue when using newer versions of rust-analyzer in my project.

The project is structured as follows:
It is a monorepo consisting of three crates: a client, a server and some common stuff. The client has a local SQLite database and the server has a PostgreSQL database. Both on the client and on the server we use SQLX to manage our interactions with their respective databases.

SQLX allows you to define a DATABASE_URL in your .env file, and therefore we have a .env file on the server with DATABASE_URL=<postgres_url> and on the client with DATABASE_URL=<sqlite_url>. This works fine when using cargo check, cargo test and cargo run, no issues there.

Using SQLX is nice because it allows compile-time checking of your SQL queries by evaluating them against the database.

Here's the kicker: When we hit save in NeoVim and rust-analyzer runs (on any version newer than 2024-09-16) on the client, the SQLite queries on the client are sent to the PostgreSQL database instead, leading to errors being displayed in the code when the queries inevitably fail. As stated earlier, there is no problem when running the code. There is only a problem when the rust-analyzer lsp checks the code.

rust-analyzer version: newer than 2024-09-16, installed through Mason

rustc version: rustc 1.82.0 (f6e511eec 2024-10-15)

editor or extension: NeoVim

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions