Is it possible to have rust-analyzer's expr.match magic completion do exhaustive variant match arms?

At some point I thought that it was possible for rust-analyzer to do this on user-defined enums, but the latest version does not seem to have this feature.

rust-analyzer will do this on stdlib enums, for example if you type a.match and ask it to do the magic completion you'll get a match expression with Ok and Err

fn foo(a: Result) -> {
    match a {
        Ok(_) => {},
        Err(_) => {},

However, when I try it with an enum I define, I do not get all the variants, just a single wildcard arm

enum Simple {

fn foo(a: Simple) -> {
    match a {
        _ => {},

I'll admit the last time I tried this was December 2020. Was this feature removed for user-defined enums, or am I totally misremembering this?

I'm using neovim with lspconfig, nvim-cmp for completion integration and nvim-vsnip to interpret the snippet stuff, but I've tested this on a fresh vanilla VSCode install and I'm getting the same behavior.


We currently only do this special casing for Option and Result, you can hover invoke the Add missing match arms assist on the completed match to fill in the rest of the arms afterwards. I think the reason for why we do not do this eagerly on completion is that sometimes you don't wanna match on all variants which would mean you would have to remove all the uninteresting arms after the completion which is unnecessary work by the user. This doesn't really apply to the two std enums though as they only add 2 arms and not more(though we could special case this two all 2-variant enums).

1 Like

Ah -- that's perfect and right what I was looking for. Thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.