nvim-treesitter-cpp-tools icon indicating copy to clipboard operation
nvim-treesitter-cpp-tools copied to clipboard

Generate Switch from Enum (Feature Request)

Open naums opened this issue 1 year ago • 1 comments

Hello,

I've just found this plugin, which looks very interesting.

A thing I have to do sometimes is create switch statements for enum-types, mapping out every single element. So I'd propose a feature request, to generate switch statements from enum definitions.

For example from

enum Seasons {
    SPRING, SUMMER, FALL, WINTER
};

Generate:

Seasons s = // ...
switch ( s ) {
  case SPRING:
    break;
  case SUMMER:
    break;
  case FALL:
    break;
  case WINTER:
    break;
}

While we're at it, a separate function to generate a code to convert the enum from String and to String would be swell as well. E.g.

std::string txt = // ...
if ( txt == "WINTER" ) {
    return WINTER;
} else if ( ...

and

Seasons s = // ...
switch ( s ) {
  case SPRING:
    return "SPRING";
  case ...

This is just a feature request. Thank you for your work, even if you don't find this feature interesting enough the implement.

Kind Regards, snaums

naums avatar Feb 11 '24 14:02 naums

Hi, that sounds like a useful feature to have. Thanks for the suggestion.

Badhi avatar Feb 20 '24 17:02 Badhi