Rust-analyzer: When completing enum patterns, complete unqualifed enum names as well

Created on 17 Apr 2020  路  3Comments  路  Source: rust-analyzer/rust-analyzer

Given the following code:

enum Animal {
    Walrus,
    MantisShrimp
}

fn feed(animal: &mut Animal) {
    match animal {
        Wa /*cursor*/
    }
}

we should suggest Animial::Walrus completion. The relevant completion handler is here. ctx.sema.type_of_pat(..) method can be used to get the type of the pattern.

E-has-instructions E-medium

Most helpful comment

We should do the same in expressions as well, actually! And to extend these type-based completions even further, we could e.g. suggest X::new() if the expected type is X (or any other static method on X returning X).

All 3 comments

We should do the same in expressions as well, actually! And to extend these type-based completions even further, we could e.g. suggest X::new() if the expected type is X (or any other static method on X returning X).

In this context, would also be cool if the name resolution issue for importing the variants actually got fixed (see #3988).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matklad picture matklad  路  3Comments

mehmooda picture mehmooda  路  3Comments

r-darwish picture r-darwish  路  3Comments

matklad picture matklad  路  3Comments

csmoe picture csmoe  路  4Comments