rust-lang / rust-lang/rust-analyzer

Let "sort variants alphabetically" assist apply to `match` statements

Open
#20,766 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists C-feature
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I have an enum with an increasingly large number of variants that I'd like to sort alphabetically so that they don't get entirely out of hand.

Rust-analyzer already supports doing this for the enum declaration. However, I also have multiple match statements that operate on that enum, and I'd like to sort them in the same order as enum variants.

I can do it with a shell script in simple cases but anything even slightly more complex requires parsing Rust code, so I'd really prefer for rust-analyzer to handle it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating rust-analyzer’s existing assist for sorting enum variants and trace how it identifies their order. Then inspect how match statements and complex patterns are represented; done means the assist can sort match arms consistently with the enum declaration without relying on a separate Rust parser.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.