rust-lang / rust-lang/rust-analyzer

VSCode extension loads before direnv, doesn't notice direnv env vars

Open
#15,852 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-vscode C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: 0.3.1722-standalone

rustc version: rustc 1.73.0 (cc66ad468 2023-10-03)

relevant settings: VSCode extension, direnv extension installed as well

In my project, some of my dependencies can't build until I set some env vars first (things like telling it where to find cc). I use direnv with an .envrc to set the relevant variables. If I open my project, and then open a Rust file, rust-analyzer works fine. But if I already have a Rust file open when I open my project (or reload the window), rust-analyzer seems to load before direnv, and it doesn't notice when direnv sets env vars. This results in rust-analyzer failing to build proc macros. At this point, even if I run "rust-analyzer: Rebuild proc macros and build scripts" or "rust-analyzer: Reload workspace" it still fails. It's acting as though it snapshotted the env vars at the point where the extension loaded and doesn't notice that they've changed.

I think what's happening is it's starting the rust-analyzer server and then never communicating changed env vars to it. If I invoke "rust-analyzer: Stop server" and then "rust-analyzer: Start server" then it works (or if I restart the entire extension host).

So either the VSCode extension needs to tell rust-analyzer that env vars have changed, or if there's not a way to do that then it needs to restart the server if any relevant vars change.

I'd also accept as a stopgap measure a way to simply delay starting the rust-analyzer server until after the direnv extension has done its work, but I'm not sure if there's any way to do that. Somehow the CMake extension is delayed until after direnv, but I don't know if that's just a quirk of activation order.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the VSCode extension activation order with the direnv extension, especially when a Rust file is already open or the window is reloaded. Compare the environment seen by the rust-analyzer server before and after direnv runs, and use the Stop server and Start server commands as a baseline; done means relevant environment changes are recognized without manually restarting the server.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.