whatisaphone / rustfmt-shim

Workaround for intellij-rust rustfmt issues

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rustfmt-shim

A temporary workaround for a few intellij-rust issues:

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

Usage

  • Clone the source
  • Run cargo run --release -- --install-the-shim
    • This backs up, and then replaces, ~/.cargo/bin/rustfmt
  • 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!

Development

Install prerequisites

Install the pre-commit hook

pre-commit install

This installs a Git hook that runs a quick sanity check before every commit.

Run the app

cargo run

Run the tests

cargo test

About

Workaround for intellij-rust rustfmt issues


Languages

Language:Rust 100.0%