Open Laursen79 opened 3 days ago
I'm having a similar issue as well In my case, i have mutiple bin crates with cargo workspace setup,
services
|-- service_1
|-- service_2
|-- service_n
each crate has its own .env
file
Rust analyzer keeps yelling errors (like "relation does not exist...") while rustc doesn't I did inspect and found that the rust analyzer was complaining because queries didn't go to the correct database as expected (for example, rust analyzer thought service_1 was querying to service_2's database and so on), but the truth is these .env files are all having correct connection setup
Edit:
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= and on the client with DATABASE_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