mitranim / sublime-rust-fmt

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

Respect project rust-toolchain version #7

Closed dbeckwith closed 6 years ago

dbeckwith commented 6 years ago

I use project-specific toolchains for all of my projects using the rust-toolchain file. It would be great if I could get this plugin to use the toolchain specified in that file. Right now in my terminal when I'm in the project directory, cargo fmt will use that toolchain because it sees the file in the project root. But when I set this plugin's config executable to ["cargo", "fmt"], it uses my default toolchain instead. I think this could be fixed by running the executable with CWD set to the project root, so cargo can pick up any project-specific overrides as specified here.

The reason I want this is so that the version of rustfmt can be pinned by the rust-toolchain file. Right now when I update my nightly toolchain, the rustfmt version updates as well (I use "executable": ["rustup", "run", "nightly", "rustfmt"]) and my rustfmt.toml file in my projects can get out of date and break. If I could get this plugin to use the project toolchain version, the rustfmt version would be pinned as well and my rustfmt config would be more stable.

mitranim commented 6 years ago

Hello there! Apologies for the long delay.

Just pushed an update with CWD detection. Should work out of the box. Let me know if this solves your problem.

dbeckwith commented 6 years ago

Thanks for the update! This is partially working for me. I think it's now using the rustfmt from my rust-toolchain version, but because the version is old enough, it requires legacy_write_mode_option: true. Is there some way to set this option automatically based on the rustfmt version? Like have it on only when the rustfmt version is less than the version where they changed that write mode option? That might be nice to have in general anyway if it really is just dependent on the version, why make the user decide if they need to set that or not?

I think the commit that changed that option was released in 0.8.0.