Skip to content

feat: Autocomplete Cargo-defined env vars in env! and option_env! (#12448) #13358

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

Merged
merged 16 commits into from
Oct 11, 2022

Conversation

btwotwo
Copy link
Contributor

@btwotwo btwotwo commented Oct 6, 2022

Closes #12448

Important to know:

  • Variables are taken from https://doc.rust-lang.org/cargo/reference/environment-variables.html and hardcoded as a const array.
  • For the sake of simplicity I didn't include the autocompletion of CARGO_BIN_EXE_<name> and OUT_DIR since it would require information about build.rs and binary name. If somebody knows an easy way of obtaining them I can add those vars as well :)

Comment on lines 45 to 47
if !matches!(name.text().as_str(), "env" | "option_env") {
return None;
}
Copy link
Member

Choose a reason for hiding this comment

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

A possible follow up is to check that the macro is build-in, to guard against shadowing. Something like #13356

Copy link
Contributor Author

@btwotwo btwotwo Oct 6, 2022

Choose a reason for hiding this comment

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

Good point, thanks! Will add that check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@Veykril
Copy link
Member

Veykril commented Oct 10, 2022

For the sake of simplicity I didn't include the autocompletion of CARGO_BIN_EXE_ and OUT_DIR since it would require information about build.rs and binary name. If somebody knows an easy way of obtaining them I can add those vars as well :)

OUT_DIR should be feasible in theory, we already store it when evaluating build scripts. But we aren't exposing it yet, though I am unsure how we would want to make it accessible. Probably through the DefMap would need to think about that a bit.

@Veykril
Copy link
Member

Veykril commented Oct 11, 2022

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Oct 11, 2022

📌 Commit 2b2b9f8 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Oct 11, 2022

⌛ Testing commit 2b2b9f8 with merge a0ab61f...

@bors
Copy link
Contributor

bors commented Oct 11, 2022

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing a0ab61f to master...

@bors bors merged commit a0ab61f into rust-lang:master Oct 11, 2022
@btwotwo btwotwo deleted the feature/env-vars-autocompletion branch October 12, 2022 08:14
@lnicola
Copy link
Member

lnicola commented Oct 17, 2022

env-completions.mp4

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.

Complete env var strings in env!/option_env! macro calls for env vars cargo will set
5 participants