Simple VS Code extension for formatting Rust code using rustfmt.
You need rustfmt installed. Install it via:
rustup component add rustfmtVerify installation:
rustfmt --version
rustc --version
rustup --versionWorks on Linux, Windows, and macOS. If your project uses rust-toolchain files, rustup is required so the extension can pick the correct toolchain.
For faster workspace formatting, cargo must be available (usually installed with Rust/rustup).
Add to your settings.json and set rust-fmt as the default formatter for Rust:
"[rust]": {
"editor.defaultFormatter": "vremyavnikuda.rust-fmt",
"editor.formatOnSave": true
}rustfmt.path: Path to rustfmt executable (default: "rustfmt")rustfmt.extraArgs: Additional arguments for rustfmt (default: [])
Automatic: Save any .rs file (if formatOnSave is enabled).
Manual:
- Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) -> "Format Document with rustfmt" (current file) - Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) -> "Format Workspace with rustfmt" (all Rust files; usescargo fmtwhen all files are saved) - Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) -> "Use rust-fmt as Default Formatter" (prompts for Global or Workspace, then enables format on save) - Shortcut:
Shift+Alt+F(Windows/Linux) orShift+Option+F(Mac) formats the entire workspace when a Rust file is active - Status bar: "rust-fmt: active" appears for Rust files; click to format workspace
The extension runs rustfmt --emit stdout on your code and applies the formatted result.
It also:
- Sets the working directory to the nearest
Cargo.toml(crate root). - Reads
editionfromCargo.tomland passes--edition. - Finds
rustfmt.toml/.rustfmt.tomland passes--config-path. - If
rust-toolchain(.toml)is present, setsRUSTUP_TOOLCHAINautomatically. - Skips files larger than 2 MB.
- Uses
cargo fmtper crate when formatting the workspace and all Rust files are saved; otherwise it falls back to per-file formatting and skips dirty files.
rustfmtnot found: install it viarustup component add rustfmtor setrustfmt.pathto the executable.
