better-cpp-syntax icon indicating copy to clipboard operation
better-cpp-syntax copied to clipboard

Shouldn't c++ preprocessor #elif's textmate scope be keyword.control.directive.conditional.elif?

Open alexr00 opened this issue 4 years ago • 1 comments

From @REYNEP in https://github.com/microsoft/vscode/issues/114297

Checklist

  • [ ] This problem exists even with the setting "C_Cpp.enhancedColorization": "Disabled"
  • [ ] This bug exists for C
  • [x] This bug exists for C++
  • [ ] This bug exists for Objective-C
  • [ ] This bug exists for Objective-C++

The code with a problem is:

#elif

It looks like:

#if

It should look like:

WHY?:-

  1. all conditional Preprocessor Commands, #if, #else, #endif, #ifdef, #ifndef are inside keyword.control.directive.conditional (eg. keyword.control.directive.conditional.ifdef)
  2. But #elif is inside keyword.control.directive, (like this: keyword.control.directive.elif)
  3. Shouldn't #elif's textmate scope be under keyword.control.directive.conditional too like the others?

I have fixed this by modifying cpp.tmLanguage.json At Line 12683 if you add elif beside the other #if #ifdef #ifndef preprocessor commands, this gets fixed

alexr00 avatar Jan 18 '21 10:01 alexr00

I believe I am experiencing this bug, but found the report to be insufficient. I'll add the missing information:

The code with a problem is:

#if FOO  // Coloration of expression is as expected
#elif BAZ  // Coloration of expression is NOT as expected
#endif

It looks like:

Using "Dark+" theme:

image

It should look like:

image


I believe the incorrect code is now located here:

https://github.com/jeff-hykin/better-cpp-syntax/blob/8d51203e1a95a3e8bcb122ca8bc984eceec675b1/syntaxes/cpp.tmLanguage.json#L12806

I applied the suggested patch there and found it resulted in the expected highlighting.

per1234 avatar Oct 30 '22 03:10 per1234