rust-derive-order
Keep your Rust #[derive(...)] lists tidy and predictable. This extension warns when derives you care about are out of order and offers a quick fix to rewrite them. It’s lightweight, configurable, and stays out of your way while you type.
Features
- Warns when derives listed in your preferred order appear out of sequence.
- Quick fix that reorders derives while preserving whitespace and multi-line formatting.
- Respects traits you haven’t listed (they’re ignored, not shuffled).
- Debounced analysis after typing stops (configurable).
How it behaves
- The extension scans Rust files for
#[derive(...)] attributes.
- Only traits included in your preferred list are considered for ordering.
- If the order is wrong, you’ll see a warning on the derive group.
- The quick fix updates only the trait order inside the
derive(...) list.
Quick fix examples
Example 1: Simple reorder
Preferred order:
Clone, Copy
Before:
#[derive(Copy, Clone)]
Quick fix result:
#[derive(Clone, Copy)]
Preferred order:
Clone, Copy, Debug
Before:
#[derive(Debug, serde::Serialize, Copy, Clone)]
Quick fix result:
#[derive(Clone, serde::Serialize, Copy, Debug)]
Only the traits in your list are re-ordered; serde::Serialize stays where it is.
Example 3: Multi-line derives
Preferred order:
Debug, Clone, Copy
Before:
#[derive(
Copy,
Debug,
Clone,
)]
Quick fix result:
#[derive(
Debug,
Clone,
Copy,
)]
Extension settings
rust-derive-order.preferredOrder: Comma-separated list that defines your desired ordering. Default: Clone, Copy.
rust-derive-order.debounceTime: Debounce time in milliseconds before analyzing after typing stops. Default: 1000.
Known issues
If you spot a false positive or an edge case, please open an issue with a small repro. It helps a lot.
Release notes
0.0.1
Initial release.