mitranim / sublime-rust-fmt

Sublime Text plugin that formats Rust code with rustfmt
30 stars 3 forks source link

Missing env var: no override and no default toolchain set #14

Closed eugenesvk closed 3 years ago

eugenesvk commented 3 years ago

I have an issue with rustfmt not getting proper env vars and as a result not working, e.g. when I'm doing the following:

This is due to the missing path to the rustup folder

If I manually add the correct env var in your plugin's RustFmt.py file like so:

    proc = sub.Popen(
        args=args,
        ...
        env={"RUSTUP_HOME": os.path.expanduser('~/.dev/rustup')}
    )

everything is working fine (setting CARGO_HOME or adding CARGO_HOME/bin to PATH doesn't help)

Do you know how I could pass the RUSTUP_HOME config to your plugin via a config or something? Don't know how to do that properly in Sublime Text in macOS, there are no global vars or anything and manually setting import os; os.environ['RUSTUP_HOME']=os.path.expanduser('~/.dev/rustup') in a console didn't help Thanks!

macOS 10.15 Sublime Text 3 (but also 4) rustc 1.54.0 (installed via rustup) rustfmt 1.4.37-stable

mitranim commented 3 years ago

Try adding the env variable to your default shell pro-file (~/.profile, ~/.zprofile, ~/.bash_profile, or whatever your have there).

eugenesvk commented 3 years ago

thanks for a prompt response!

  • ST generally mimics your shell environment.

Yeah, it most definitely should! Unless it doesn't :( And as far as I understood in my previous attempts to fix PATH (which Sublime wouldn't pick up) macOS is especially tricky in this regard, so I ended up using https://packagecontrol.io/packages/Fix Mac Path to fix PATH, but that package unfortunately doesn't allow setting other env variables like RUSTUP_HOME

The shell profile files you mentioned only seem to work when bash/zsh are default login shells, but for e.g. fish shell they don't work :(

Will try to find some alternative solution, but any tips are welcome!

mitranim commented 3 years ago

Pushed support for env overrides in plugin settings:

"env": {"RUSTUP_HOME": "..."}

Let me know if this helps.

mitranim commented 3 years ago

The change isn't on Package Control yet. Since you have the plugin setup locally, you can pull to test this.

eugenesvk commented 3 years ago

Thanks for such a quick fix! Can confirm that I can set the env var via settings now and it's working just fine!