rust/crates
bors[bot] b89fef5220
Merge #7562
7562: add `generate_enum_match` assist r=matklad a=yoshuawuyts

This adds a `generate_enum_match` assist, which generates `is_` variants for enums (e.g. `Option::{is_none,is_some}` in std). This is my first attempt at contributing to Rust-Analyzer, so I'm not sure if I've gotten everything right. Thanks!

## Example

**Input**
```rust
pub(crate) enum Variant {
    Undefined,
    Minor, // cursor here
    Major,
}
```
**Output**
```rust
pub(crate) enum Variant {
    Undefined,
    Minor,
    Major,
}

impl Variant {
    pub(crate) fn is_minor(&self) -> bool {
        matches!(self, Self::Minor)
    }
}
```

## Future Directions

I made this as a stepping stone for some of the more involved refactors (e.g. #5944). I'm not sure yet how to create, use, and test `window.showQuickPick`-based asssists in RA. But once that's possible, it'd probably be nice to be able to generate match methods in bulk through the quickpick UI rather than one-by-one:

```
[x] Select enum members to generate methods for. (3 selected) [ OK ]
---------------------------------------------------------------------------
[x] Undefined
[x] Minor
[x] Major
```

Co-authored-by: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-02-05 14:28:25 +00:00
..
assists Merge #7562 2021-02-05 14:28:25 +00:00
base_db Fix warnings when running cargo doc --document-private-items 2021-01-18 16:44:40 -05:00
cfg
completion Make ModPath's representation private 2021-02-04 20:49:24 +01:00
flycheck Make logger-based debugging more pleasant 2021-01-28 17:07:53 +03:00
hir Prefer ValueNS when resolving hir path for PathExpressions 2021-01-29 15:59:52 +01:00
hir_def Fix merging of segment_index in path resolution 2021-02-05 15:14:33 +01:00
hir_expand add more counts 2021-01-27 12:39:19 +03:00
hir_ty Remove unnecessary allocs in case_conv 2021-02-05 15:02:39 +01:00
ide Show alias underlying type 2021-02-02 17:47:56 +03:00
ide_db Make ModPath's representation private 2021-02-04 20:49:24 +01:00
mbe Make sure normal dependencies always have version 2021-02-03 12:51:07 +00:00
parser Add validation for mutable const items 2021-01-24 02:17:41 +01:00
paths Document paths items 2021-01-22 15:38:33 +01:00
proc_macro_api Reap proc macro server instances 2021-02-01 21:24:09 +02:00
proc_macro_srv Use non-deprecated memmap2 crate 2021-02-02 10:25:17 -05:00
proc_macro_test
profile add more counts 2021-01-27 12:39:19 +03:00
project_model Async Loading outdir and proc-macro 2021-01-29 01:04:14 +08:00
rust-analyzer Make ModPath's representation private 2021-02-04 20:49:24 +01:00
ssr . 2021-01-20 01:56:11 +03:00
stdx Make always-assert crate reusable 2021-01-26 22:13:42 +03:00
syntax Merge #7535 2021-02-05 02:55:56 +00:00
test_utils
text_edit
toolchain
tt
vfs
vfs-notify