Skip to content
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

Add rust-analyzer.serverEnv to set the environment variables of the server #6099

Closed
wants to merge 1 commit into from

Conversation

emgre
Copy link

@emgre emgre commented Sep 29, 2020

This PR simply adds a rust-analyzer.serverEnv settings in the VSCode extension to set the environment variables used when launching the rust-analyzer server.

I don't know if it is a common use case, but I have a build script that depends on an environment variable to locate a system dependency. If the environment variable changes, the build script is re-run (which takes some time). The environment variables changes frequently, as I jump from version to version. I was setting the environment variable in the terminal of VS Code, but it kept re-running the build script because rust-analyzer was overiding the build script hash value. A quick fix was to launch VS Code from a terminal with the environment variable set, but it seemed like a nice feature to add without much effort needed, so there it is.

@emgre
Copy link
Author

emgre commented Sep 29, 2020

Browsing through the PR, just saw this comment: #5954 (comment)

I guess I did it 😄

Comment on lines +479 to +483
"rust-analyzer.serverEnv": {
"type": "object",
"default": null,
"description": "Environment variables to set for the rust-analyzer executable in form of { \"key\": \"value\"}"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name this server.env. I should have renamed serverPath to server.path long ago...

@wycats
Copy link

wycats commented Nov 5, 2020

This would be great! I just ran into this problem (via #6007) this morning 😄

rib added a commit to rib/cargo that referenced this pull request Nov 7, 2020
Some custom build scripts (especially for -sys packages) expect to
query environment variables to locate build resources (such as
pre-built binaries) but these cause lots of trouble when considering
the numerous different ways in which cargo may be invoked.

For example each editor that invokes cargo as part of providing
development diagnostics needs to offer some way to configure environment
variables or users need to find their own way of controlling the environment
variables of these different tools which is burdensome and can lead
to an inconsistent duplication of state across tools.

This introduces support for reading an (optional) environment.json found
at the root of the current workspace that may contain a map of
environment variable key, value pairs. These variables will be exported
to all build scripts run under the workspace. The removes any need to
configure tools and editors independently.

The configuration is separate from any Config.toml since it's likely
that the state shouldn't be under version control in many situations
(generally locating resources for the project within a specific user's
development environment).

Fixes: rust-lang/issues/4121
Fixes: rust-lang/rls/issues/915
Fixes: rust-lang/vscode-rust/issues/791
Fixes: rust-lang/rust-analyzer/pull/6099
Fixes: intellij-rust/intellij-rust/issues/1569
@matklad
Copy link
Member

matklad commented Jan 5, 2021

superseded by #7091

@matklad matklad closed this Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants