-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zed doesn't detect environment variables from its launch environment #9788
Comments
Hey! Actually, Zed does detect environment variables from its launch environment, but things are a bit tricky. Let me explain: Current Status
So far, so good. You can see in the logs above that (2) happened for you:
But here's gotcha nr. 1:
As part of #7902 I tried to improve on the situation and created #8188, which adds the following:
5.-7. are only implemented for Go and Zig right now and for Zig we even had a slight regression that we fixed yesterday, where we would not remember the env in which we found So that's gotcha nr. 2:
OptionsI think, the ideal case would look something like this:
That's a lot of work that's tricky to get right, since there's a lot of global state being kept around and edge cases to handle (what if you have two worktrees in a single project/window? do we already correctly attach language servers per worktree?). It also has to be said, that there's no real "best practices" here, since all the language servers do something slightly different (some read their env, some read only config files), all editors do something different, editor plugins also mix their own behavior in, etc. etc. A short-term solution could be that we modify the Rust and the C++ adapters just like the Go and Zig adapters to also make use of the current environment. A workaround would be to only have a single Zed process running and launching it from the CLI. That should pick up the environment variables. cc @maxdeviant and @maxbrunsfeld who worked on the extensions and whom I also talked to about this before. I'd love to hear your thoughts on this, now that we're moving to extensions. |
I think we're ok here, because language servers are always spawned for one particular worktree. In a multi-root project, we'll spawn a separate language server for each root. We already expose a I also think it would be a good idea to store, on each Project (which may have multiple roots) the shell env of the |
Option 1 sounds reasonable to me, and VS Code's
Just want to point out a slight complication here with Nix. If you're not aware, when you enter a development shell with Nix via |
Yeah, I do think that there's only so much we can do (apart from having a Nix-aware extension that populates the environment variables for you, of course). We already make sure to trigger direnv or other things that populate the env on In this case, the interesting bit here is that I think the environment inherit by
Now Zed should have all the correct environment variables, but if we were then to spawn a shell in So, to answer your question, @maxbrunsfeld
I think it should work roughly like this:
So no merging, but deciding either or. |
Just wanted to say that this issue makes Zed unusable with For example, on Rust projects - Zed will refuse to recognize the The above is reproducible with https://github.com/srid/rust-nix-template |
@mrnugget I noticed something, it is mostly an issue with the CLI not Zed, because here what I have tested, and I find it very interesting:
I find it very strange because the editor itself is able to load the shell environment correctly, but looks like the CLI just throws it away before it starts the Zed binary.
|
@zmitchell, off topic, but are you able to share your flake.nix? |
https://github.com/flox/flox That's a particularly gnarly |
Would it be possible to override project-specific envs in local settings ( |
I am also having this issue, is there any way to fix this as of now? |
I like the idea of override project-specific envs in local settings (.zed/settings.json). |
Setting the environment manually in |
There's still no fix, I plan on working on this in the near future, but am currently busy with the Linux port. Sorry! |
I noticed something that might fit here rather than a new bug report. I'm using an on-exit event script in fish, like this:
When zed runs a shell to get environment vars, this "Exiting fish." is randomly present in one of them (at least I couldn't see a pattern which variable it affects, but might be wrong). This can be confirmed in a zed terminal panel by using When this affects I'm using the |
Yes! Forgot to update this issue. See: #17075 |
Thanks everyone! I’ll take a look once the next release goes out. |
Check for existing issues
Describe the bug / provide steps to reproduce it
It's common to set environment variables in your shell and then launch your editor in that shell so that the editor picks up those environment variables. This is very common in the Nix world especially, where you would enter a development shell and launch the editor from the shell.
Basic case:
Nix case:
This matters a lot when you have compile-time environment variables in a Rust project.
In a Nix project you might use this to hard-code the Nix store path of a binary that you want to call from your Rust project, but you could imagine a variety of other use cases I'm sure.
On the codebase I'm working on I'm also not getting any other "red squiggles" when I'm in my development shell. I can't tell if that's related or not. The codebase is flox, which contains Rust and C++.
Environment
Zed: v0.127.4 (Zed)
OS: macOS 14.2.0
Memory: 32 GiB
Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
No response
If applicable, attach your
~/Library/Logs/Zed/Zed.log
file to this issue.The text was updated successfully, but these errors were encountered: