A temporary workaround for a few intellij-rust issues:
- rustfmt toolchain
- auto-import woes
The workaround is to replace the default rustfmt
with a shim, which tricks intellij-rust into running it instead of rustfmt.
Here is what the shim does:
- Preprocesses the source to fix imports
- Runs a different toolchain's rustfmt, if one is found in
.pre-commit-config.yaml
- If no override is found, falls back to stable rustfmt
- Clone the source
- Run
cargo run --release -- --install-the-shim
- This backs up, and then replaces,
~/.cargo/bin/rustfmt
- This backs up, and then replaces,
- In IntelliJ, enable "Run rustfmt on Save"
If it doesn't work, check /tmp/rustfmt-shim.log
for hints. If it does work, the target directory and source tree are no longer needed, so you can delete them if you wish.
Note: If the shim is ever clobbered by e.g. rustup, you'll need to install again. Shimfight!
pre-commit install
This installs a Git hook that runs a quick sanity check before every commit.
cargo run
cargo test