Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 5 tasks
alexr00 opened this issue Jan 18, 2021 · 1 comment

Comments

@alexr00
Copy link

alexr00 commented Jan 18, 2021

From @REYNEP in microsoft/vscode#114297

Checklist

  • This problem exists even with the setting "C_Cpp.enhancedColorization": "Disabled"
  • This bug exists for C
  • 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

@per1234
Copy link

per1234 commented Oct 30, 2022

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:

"begin": "^((?:(?:(?:(?>(?:\\s)+)|(\\/\\*)((?:[^\\*]|(?:\\*)++[^\\/])*+((?:\\*)++\\/)))+)|(?:\\b)|(?=\\W)|(?<=\\W)|(?:\\A)|(?:\\Z)))(#)(?:(?:\\s)+)?((?:(?:ifndef|ifdef)|if))",

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants