jeff-hykin / better-cpp-syntax

💾 The source of VS Code's C++ syntax highlighting
GNU General Public License v3.0
154 stars 29 forks source link

"case" inside #if is not highlighted in C #429

Open joelspadin-garmin opened 4 years ago

joelspadin-garmin commented 4 years ago

Checklist

The code with a problem is:

#define HANDLE_1

void foo(int bar)
{
    switch (bar)
    {
    case 0:
        break;

    #if defined( HANDLE_1 )
    case 1:
        break;
    #endif

    default:
        break;
    }
}

It looks like:

If you use preprocessor conditionals to conditionally compile cases in a switch statement, the "case" text is not highlighted in C. It does get properly highlighted in C++ though.

image

Shown VS Code 1.41.0, C/C++ tools 0.26.2, Dark+ theme.

It should look like:

image

tristan957 commented 1 year ago

I just ran across this issue! Thanks for creating a minimal test case already :).

jeff-hykin commented 1 year ago

Wanted to mention this here, since its probably going to be a bit before the C syntax gets a proper rewrite.

C files can be viewed using the C++ grammar, in settings.json it looks like:

"files.associations": {
        "*.c": "cpp",
}

Definitely a bad hack, but often makes the code look a lot better since almost all C is valid C++, and many of the fixes have not be backported to C